Пример #1
0
        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);
            }
        }
Пример #2
0
 public void Reset(InlineTextBlock label)
 {
     label.Text = label.Text.TrimEnd() + " ";
     Label      = label;
     DoneText   = new InlineTextBlock("[Done]", ConsoleColor.DarkGreen);
     Display();
 }
Пример #3
0
 public CustomSpinner(InlineTextBlock label, InlineTextBlock doneText)
 {
     label.Text = label.Text.TrimEnd() + " ";
     Label      = label;
     DoneText   = doneText;
     Display();
 }
Пример #4
0
        private void DisplayQuestion()
        {
            InlineTextBlock labelControl = new InlineTextBlock
            {
                PaddingRight    = 1,
                ForegroundColor = QuestionForegroundColor ?? ForegroundColor,
                BackgroundColor = QuestionBackgroundColor ?? BackgroundColor,
                Text            = QuestionText
            };

            labelControl.Display();
        }
Пример #5
0
        private void DisplaySpaceAfterQuestion()
        {
            string space = new string(' ', SpaceAfterQuestion);

            InlineTextBlock inlineTextBlock = new InlineTextBlock
            {
                Text            = space,
                ForegroundColor = ForegroundColor,
                BackgroundColor = BackgroundColor
            };

            inlineTextBlock.Display();
        }
Пример #6
0
        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);
        }
Пример #7
0
        /// <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();
        }
Пример #8
0
 public CustomSpinner()
 {
     DoneText = new InlineTextBlock("[Done]", ConsoleColor.DarkGreen);
     Display();
 }