Пример #1
0
        private void Basics()
        {
            // Create menu
            menu = new CMenu();

            // Let's specify a custom prompt so we later clearly know we're in the tutorial menu.
            menu.PromptCharacter = "tutorial>";

            // Add simple Hello World command
            menu.Add("hello", s => Console.WriteLine("Hello world!"));

            /*
             * If the command happens to be more complex, you can just put it in a separate method.
             */
            menu.Add("len", s => PrintLen(s));

            /*
             * It is also possible to return an exit code to signal that processing should be stopped.
             * By default, the command "quit" exists for this purpose. Let's add an alternative way to stop processing input.
             */
            menu.Add("exit", s => menu.Quit());

            /*
             * To create a command with help text, simply add it during definition.
             */
            menu.Add("time",
                     s => Console.WriteLine(DateTime.UtcNow),
                     "Help for \"time\": Writes the current time");

            /*
             * You can also access individual commands to edit them later, though this is rarely required.
             */
            menu["time"].HelpText += " (UTC).";

            // Run menu. The menu will run until quit by the user.
            Console.WriteLine("Enter \"help\" for help.");
            Console.WriteLine("Enter \"quit\" to quit (in this case, the next step of this demo will be started).");
            menu.Run();

            Console.WriteLine("(First menu example completed, starting the next one...)");
        }
Пример #2
0
 public override void Execute(string arg)
 {
     _Menu.Quit();
 }