Beispiel #1
0
        private static void TestPromptMenu()
        {
            var prompt = "Select an item:";

            string[] items = { "Item 1", "Item 2", "Item 3" };

            var menu = ConsoleMio.CreatePromptMenu(prompt, items);

            Console.WriteLine("Some text before menu");
            menu.Show(Red, Blue);
            Console.WriteLine("Some text after");
        }
        private static void Prompt()
        {
            const string triangle = "Create a Triangle";
            const string rect     = "Create a Rectangle";
            const string square   = "Create a Square";
            const string quit     = "Quit";

            var menu = ConsoleMio.CreatePromptMenu <string>(
                "What would you like to do?",
                new[] { triangle, rect, square, quit });

            var choice = menu.Show(Black, Warning);

            ConsoleMio.WriteLine();

            double[] args;
            switch (choice)
            {
            case triangle:
                args = ReadInput("Enter hypotenuse and side lengths: ", 2);
                CreateTriangle(args[0], args[1]);
                break;

            case rect:
                args = ReadInput("Enter A and B sides: ", 2);
                CreateRectangle(args[0], args[1]);
                break;

            case square:
                args = ReadInput("Enter the square side: ", 1);
                CreateSquare(args[0]);
                break;

            case quit:
                ConsoleMio.WriteLine("Byem bye...", DarkRed);
                Thread.Sleep(1000);
                Environment.Exit(0);
                break;

            default:
                throw new ApplicationException("Invalid menu choice");
            }
        }
        private static void Loop()
        {
            while (true)
            {
                string[] actions =
                {
                    "Register a customer",
                    "Review existing customers",
                    "Quit"
                };

                var menu = ConsoleMio.CreatePromptMenu(
                    "What would you like to do?", actions);

                var choice = menu.Show(Black, Warning);

                if (choice == actions[0])
                {
                    commandInterface.RegisterCustomer();
                }
                else if (choice == actions[1])
                {
                    commandInterface.ReviewCustomers();
                }
                else if (choice == actions[2])
                {
                    OnQuit();
                }
                else
                {
                    throw new NotImplementedException("This action isn't implemented yet");
                }

                ConsoleMio.WriteLine();
            }
        }