public static void Run(InlineTextBlock label, Action action) { if (action == null) { throw new ArgumentNullException(nameof(action)); } var spinner = new CustomSpinner(label); spinner.Display(); try { action(); spinner.Close(); } catch (Exception e) { spinner.DoneText = null; string error = e.Message; if (error.StartsWith("Error:")) { error = error.Substring(7); } Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write("[ERROR]"); Console.ResetColor(); Console.Write($" {error}"); spinner.Close(); Environment.Exit(1); } }
public void Reset(InlineTextBlock label) { label.Text = label.Text.TrimEnd() + " "; Label = label; DoneText = new InlineTextBlock("[Done]", ConsoleColor.DarkGreen); Display(); }
public CustomSpinner(InlineTextBlock label, InlineTextBlock doneText) { label.Text = label.Text.TrimEnd() + " "; Label = label; DoneText = doneText; Display(); }
private void DisplayQuestion() { InlineTextBlock labelControl = new InlineTextBlock { PaddingRight = 1, ForegroundColor = QuestionForegroundColor ?? ForegroundColor, BackgroundColor = QuestionBackgroundColor ?? BackgroundColor, Text = QuestionText }; labelControl.Display(); }
private void DisplaySpaceAfterQuestion() { string space = new string(' ', SpaceAfterQuestion); InlineTextBlock inlineTextBlock = new InlineTextBlock { Text = space, ForegroundColor = ForegroundColor, BackgroundColor = BackgroundColor }; inlineTextBlock.Display(); }
public MainMenu(DemoApplication demoApplication) { if (demoApplication == null) { throw new ArgumentNullException(nameof(demoApplication)); } Margin = "0 1"; QuestionText = new InlineTextBlock { Text = "Make your choice:", MarginRight = 1 }; IEnumerable <TextMenuItem> menuItems = CreateMenuItems(demoApplication); AddItems(menuItems); }
/// <summary> /// Displays to the console the list of possible answers. /// </summary> protected virtual void DisplayPossibleAnswersList() { StringBuilder sb = new StringBuilder(); sb.Append("["); string yesText = CapitalizeDefaultAnswer && DefaultAnswer == YesNoAnswer.Yes ? YesText.ToUpper() : YesText; sb.Append(yesText); sb.Append("/"); string noText = CapitalizeDefaultAnswer && DefaultAnswer == YesNoAnswer.No ? NoText.ToUpper() : NoText; sb.Append(noText); if (AcceptCancel) { sb.Append("/"); string cancelText = CapitalizeDefaultAnswer && DefaultAnswer == YesNoAnswer.Cancel ? CancelText.ToUpper() : CancelText; sb.Append(cancelText); } sb.Append("]"); InlineTextBlock inlineTextBlock = new InlineTextBlock { Text = sb.ToString(), ForegroundColor = ForegroundColor, BackgroundColor = BackgroundColor }; inlineTextBlock.Display(); }
public CustomSpinner() { DoneText = new InlineTextBlock("[Done]", ConsoleColor.DarkGreen); Display(); }