public void Reentry_Submenu()
        {
            var console = new TestConsole();

            console.AddUserInput(ConsoleKey.D1);
            console.AddUserInputWithActionBefore(ConsoleKey.D1, () =>
            {
                AssertHelper.Equal(@"Pick an option:
   [0] One
>> [1] Close
", console.ToString());
            });

            // open submenu once again
            console.AddUserInputWithActionBefore(ConsoleKey.D1, () =>
            {
                AssertHelper.Equal(@"Pick an option:
   [0] Sub_One
>> [1] Sub_Close
", console.ToString());
            });
            console.AddUserInputWithActionBefore(ConsoleKey.D1, () =>
            {
                AssertHelper.Equal(@"Pick an option:
   [0] One
>> [1] Close
", console.ToString());
            });
            var submenu = new ConsoleMenu()
            {
                Console = console
            }
            .Add("Sub_One", () => { })
            .Add("Sub_Close", ConsoleMenu.Close)
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
            });

            var menu = new ConsoleMenu()
            {
                Console = console
            }
            .Add("One", submenu.Show)
            .Add("Close", ConsoleMenu.Close)
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
            });

            menu.Show();

            AssertHelper.Equal(@"Pick an option:
   [0] One
>> [1] Close

", console.ToString());
        }
        public void SimpleScenario()
        {
            const string input   = @"2
";
            var          console = new TestConsole(input);

            var menu = new ConsoleMenu()
            {
                console = console
            }
            .Add("One", () => { })
            .Add("Two", () => { })
            .Add("Close", ConsoleMenu.Close)
            .Add("Exit", () => Environment.Exit(0))
            .Configure(m =>
            {
                m.SelectedItemBackgroundColor = console.ForegroundColor;
                m.SelectedItemForegroundColor = console.BackgroundColor;
                m.ItemBackgroundColor         = console.BackgroundColor;
                m.ItemForegroundColor         = console.ForegroundColor;
                m.WriteHeaderAction           = () => console.WriteLine("Pick an option:");
                m.WriteItemAction             = item => console.Write("[{0}] {1}", item.Index, item.Name);
            });

            menu.Show();

            Assert.Equal(@"Pick an option:
   [0] One
   [1] Two
>> [2] Close
   [3] Exit

", console.ToString());
        }
        public void PreSelected_SubmenuItem()
        {
            var console = new TestConsole();

            var submenu = new ConsoleMenu(args: new[] { "--menu-select=0.1" }, level: 1)
            {
                Console = console
            }
            .Add("One", () => { })
            .Add("Two", () => console.Write("Expected action"))
            .Add("Close", ConsoleMenu.Close)
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
            });

            var menu = new ConsoleMenu(args: new[] { "--menu-select=0.1" }, level: 0)
            {
                Console = console
            }
            .Add("One", submenu.Show)
            .Add("Close", ConsoleMenu.Close)
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
            });

            menu.Show();

            Assert.Equal("Expected action", console.ToString(), ignoreLineEndingDifferences: true);
        }
        public void SimpleScenario_Colors()
        {
            var console = new TestConsole {
                Details = true
            };

            console.AddUserInput("2");

            var menu = new ConsoleMenu()
            {
                Console = console
            }
            .Add("One", () => { })
            .Add("Two", () => { })
            .Add("Close", ConsoleMenu.Close)
            .Add("Exit", () => Environment.Exit(0))
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
            });

            menu.Show();

            Assert.Equal(@"Pick an option:<fc: White, bc: Black>
   <fc: White, bc: Black>[0] One<fc: White, bc: Black>
   <fc: White, bc: Black>[1] Two<fc: White, bc: Black>
>> <fc: Black, bc: White>[2] Close<fc: Black, bc: White>
   <fc: White, bc: Black>[3] Exit<fc: White, bc: Black>

", console.ToString(), ignoreLineEndingDifferences: true);
        }
        public void SimpleScenario()
        {
            var console = new TestConsole();

            console.AddUserInput("2");

            var menu = new ConsoleMenu()
            {
                Console = console
            }
            .Add("One", () => { })
            .Add("Two", () => { })
            .Add("Close", ConsoleMenu.Close)
            .Add("Exit", () => Environment.Exit(0))
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
            });

            menu.Show();

            Assert.Equal(@"Pick an option:
   [0] One
   [1] Two
>> [2] Close
   [3] Exit

", console.ToString(), ignoreLineEndingDifferences: true);
        }
        public void PreSelected_OpenSubmenu()
        {
            var console = new TestConsole();

            var submenu = new ConsoleMenu(args: new[] { "--menu-select=0" }, level: 1)
            {
                Console = console
            }
            .Add("One1", () => console.Write("Should not be chosen"))
            .Add("Close1", ConsoleMenu.Close)
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
            });

            var menu = new ConsoleMenu(args: new[] { "--menu-select=0" }, level: 0)
            {
                Console = console
            }
            .Add("One0", submenu.Show)
            .Add("Close0", ConsoleMenu.Close)
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
            });

            console.AddUserInputWithActionBefore("2", () =>
            {
                Assert.Equal(@"Pick an option:
>> [0] One1
   [1] Close1
", console.ToString(), ignoreLineEndingDifferences: true);
            });

            console.AddUserInputWithActionBefore(ConsoleKey.Enter, () =>
            {
                submenu.CloseMenu();
                menu.CloseMenu();
            });

            menu.Show();
        }
        public void Breadcrumbs()
        {
            var console = new TestConsole();

            console.AddUserInputWithActionBefore("1", () => AssertHelper.Equal(@"First menu
Pick an option:
>> [0] One
   [1] Two
   [2] Close
   [3] Exit
", console.ToString()));

            console.AddUserInputWithActionBefore("0", () => AssertHelper.Equal(@"First menu > Second menu
Pick an option:
>> [0] Close
", console.ToString()));

            console.AddUserInputWithActionBefore("2", () => AssertHelper.Equal(@"First menu
Pick an option:
   [0] One
>> [1] Two
   [2] Close
   [3] Exit
", console.ToString()));

            var submenu = new ConsoleMenu {
                Console = console
            }
            .Add("Close", ConsoleMenu.Close)
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
                m.EnableBreadcrumb      = true;
                m.WriteBreadcrumbAction = titles => console.WriteLine(string.Join(" > ", titles));
                m.Title = "Second menu";
            });

            var menu = new ConsoleMenu()
            {
                Console = console
            }
            .Add("One", () => { })
            .Add("Two", submenu.Show)
            .Add("Close", ConsoleMenu.Close)
            .Add("Exit", () => Environment.Exit(0))
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
                m.EnableBreadcrumb      = true;
                m.WriteBreadcrumbAction = titles => console.WriteLine(string.Join(" > ", titles));
                m.Title = "First menu";
            });

            menu.Show();

            AssertHelper.Equal(@"First menu
Pick an option:
   [0] One
   [1] Two
>> [2] Close
   [3] Exit

", console.ToString());
        }
Example #8
0
        public void Filtering_Navigation()
        {
            var console = new TestConsole();

            console.AddUserInputWithActionBefore("e", () => AssertHelper.Equal(@"Pick an option:
>> [0] One
   [1] Two
   [2] Close
   [3] Exit
Filter: ", console.ToString()));

            console.AddUserInputWithActionBefore(ConsoleKey.DownArrow, () => AssertHelper.Equal(@"Pick an option:
>> [0] One
   [2] Close
   [3] Exit
Filter: e", console.ToString()));

            console.AddUserInputWithActionBefore(ConsoleKey.UpArrow, () => AssertHelper.Equal(@"Pick an option:
   [0] One
>> [2] Close
   [3] Exit
Filter: e", console.ToString()));

            console.AddUserInputWithActionBefore(ConsoleKey.UpArrow, () => AssertHelper.Equal(@"Pick an option:
>> [0] One
   [2] Close
   [3] Exit
Filter: e", console.ToString()));

            console.AddUserInputWithActionBefore(ConsoleKey.UpArrow, () => AssertHelper.Equal(@"Pick an option:
   [0] One
   [2] Close
>> [3] Exit
Filter: e", console.ToString()));

            console.AddUserInputWithActionBefore(ConsoleKey.Enter, () => AssertHelper.Equal(@"Pick an option:
   [0] One
>> [2] Close
   [3] Exit
Filter: e", console.ToString()));

            var submenu = new ConsoleMenu {
                Console = console
            }
            .Add("Close", ConsoleMenu.Close)
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
                m.EnableFilter = true;
            });

            var menu = new ConsoleMenu()
            {
                Console = console
            }
            .Add("One", () => { })
            .Add("Two", submenu.Show)
            .Add("Close", ConsoleMenu.Close)
            .Add("Exit", () => Environment.Exit(0))
            .Configure(m =>
            {
                ConfigHelper.BaseTestConfiguration(m, console);
                m.EnableFilter = true;
            });

            menu.Show();

            AssertHelper.Equal(@"Pick an option:
   [0] One
>> [2] Close
   [3] Exit
Filter: e
", console.ToString());
        }