Esempio n. 1
0
        static void PromptlessMode()
        {
            var m = new CMenu();

            m.Add("promptless", s => {
                m.CQ.PromptUserForInput = false;
                Console.WriteLine("Promptless mode selected. Input will be ignored.");
                Console.WriteLine("A timer will be set which will input 'active' in 5 seconds.");
                new Thread(() => {
                    for (int i = 5; i >= 0; i--)
                    {
                        Console.WriteLine(i + "...");
                        Thread.Sleep(1000);
                    }
                    Console.WriteLine("Sending input 'active' to the command queue.");
                    m.CQ.ImmediateInput("active");
                }).Start();
            });
            m.Add("active", s => {
                m.CQ.PromptUserForInput = true;
                Console.WriteLine("Prompting mode selected again.");
            });

            Console.WriteLine("IO is currently in active mode - you will be prompted for input.");
            Console.WriteLine("The 'promptless' command will turn on promptless mode, which disables interactive input.");
            Console.WriteLine("The 'active' command will turn active mode back on.");
            Console.WriteLine("Please enter 'promptless' (or 'p').");

            m.Run();
        }
Esempio n. 2
0
        static void DisabledCommands()
        {
            var m = new CMenu();

            /*
             * In this example, a global flag is used to determine the visibility of disabled commands.
             * It is initially cleared, the 'enable' command sets it.
             */
            Enabled = false;
            m.Add("enable", s => Enabled = true);

            /*
             * Create a new inline command, then set its enabledness function so it returns the above flag.
             */
            var mi = m.Add("inline", s => Console.WriteLine("Disabled inline command was enabled!"));

            mi.SetEnablednessCondition(() => Enabled);

            /*
             * Command abbreviations do not change when hidden items become visible, i.e. it is made sure they are already long
             * enough. This avoids confusion about abbreviations suddenly changing.
             */
            m.Add("incollision", s => Console.WriteLine("The abbreviation of 'incollision' is longer to account for the hidden 'inline' command."));

            /*
             * It is also possible to override the visibility by subclassing.
             */
            m.Add(new DisabledItem());
            m.Run();
        }
Esempio n. 3
0
        static void ImmediateMode()
        {
            var m = new CMenu();

            m.ImmediateMenuMode = true;
            m.Add("foo", s => Console.WriteLine("foo"));
            m.Add("bar", s => Console.WriteLine("bar"));
            m.Run();
        }
Esempio n. 4
0
        public void Run()
        {
            var menu = new CMenu();

            menu.Add("view", (name) => RenderSystem(name));
            menu.Run();

            Console.WriteLine(">>>> DONE");
        }
Esempio n. 5
0
        private void CaseSensitivity()
        {
            /*
             * Commands are case *in*sensitive by default. This can be changed using the `StringComparison` property.
             */
            menu.StringComparison = StringComparison.InvariantCulture;
            menu.Add("Hello", s => Console.WriteLine("Hi!"));

            Console.WriteLine("The menu is now case sensitive.");
            menu.Run();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Simple CMenu demonstration");

            var mainmenu = new CMenu();

            mainmenu.PromptCharacter = "main>";
            mainmenu.Add("tutorial", s => new Tutorial().Run());
            mainmenu.Add("tree-init", s => TreeInitialization());
            mainmenu.Add("disabled", s => DisabledCommands());
            mainmenu.Add("passive", s => PassiveMode());
            mainmenu.Add("immediate", s => ImmediateMode());
            mainmenu.Add(new ExamplesMenu());

            mainmenu.CQ.ImmediateInput("help");
            mainmenu.Run();
        }
Esempio n. 7
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...)");
        }
Esempio n. 8
0
        static void TreeInitialization()
        {
            /*
             * It may be useful to create complex menu trees using collection initializers
             */
            var m = new CMenu()
            {
                new CMenuItem("1")
                {
                    new CMenuItem("1", s => Console.WriteLine("1-1")),
                    new CMenuItem("2", s => Console.WriteLine("1-2")),
                },
                new CMenuItem("2")
                {
                    new CMenuItem("1", s => Console.WriteLine("2-1")),
                    new CMenuItem("2", s => Console.WriteLine("2-2")),
                },
            };

            m.PromptCharacter = "tree>";
            m.Run();

            /*
             * You can also combine object and collection initializers
             */
            m = new CMenu()
            {
                PromptCharacter = "combined>",
                MenuItem        =
                {
                    new CMenuItem("1", s => Console.WriteLine("1")),
                    new CMenuItem("2", s => Console.WriteLine("2")),
                }
            };
            m.Run();
        }
 public static void ExecuteSubMenu(CMenu menu)
 {
     menu.Run();
 }
Esempio n. 10
0
 public void Run()
 {
     menu.Run();
 }