public void ChangeToShorterPrompt()
        {
            var dis = new MenuDisplay <MenuOption <string> >(Console, 3);

            dis.Options.Add(new MenuOption <string>("first", "first"));
            dis.Options.Add(new MenuOption <string>("second", "second"));
            dis.Options.Add(new MenuOption <string>("third", "third"));

            dis.HandleKey(new ConsoleKeyInfo('\0', ConsoleKey.DownArrow, false, false, false));

            AssertConsole.BufferAndWindowLines
            (
                "> first",
                "  second",
                "  third"
            );

            dis.Prompt = ">";

            AssertConsole.BufferAndWindowLines
            (
                ">first",
                " second",
                " third"
            );
        }
        public void TopBottomPrefixRemoving()
        {
            var display = new MenuDisplay <MenuOption <string> >(Console, 10);

            display.PrefixesTop.SetKeys(new char[] { '0', '1' });
            display.PrefixesBottom.SetKeys(new char[] { 'a', 'b' });

            display.Options.Add(new MenuOption <string>("first", "first"));
            display.Options.Add(new MenuOption <string>("second", "second"));
            display.Options.Add(new MenuOption <string>("third", "third"));
            display.Options.Add(new MenuOption <string>("fourth", "fourth"));
            display.Options.Add(new MenuOption <string>("fifth", "fifth"));

            AssertConsole.BufferAndWindowLines
            (
                "  0: first",
                "  1: second",
                "     third",
                "  b: fourth",
                "  a: fifth"
            );

            display.Options.RemoveAt(4);
            AssertConsole.BufferAndWindowLines
            (
                "  0: first",
                "  1: second",
                "  b: third",
                "  a: fourth"
            );

            display.Options.RemoveAt(3);
            AssertConsole.BufferAndWindowLines
            (
                "  0: first",
                "  b: second",
                "  a: third"
            );

            display.Options.RemoveAt(2);
            AssertConsole.BufferAndWindowLines
            (
                "  b: first",
                "  a: second"
            );

            display.Options.RemoveAt(1);
            AssertConsole.BufferAndWindowLines
            (
                "  a: first"
            );

            display.Options.RemoveAt(0);
            AssertConsole.BufferAndWindowLines();
        }
Beispiel #3
0
        public void FullCleanup()
        {
            Console.Input.Enqueue("12");
            Console.Input.Enqueue(ConsoleKey.Enter);

            var value = ReadlineConfiguration.Create <int>()
                        .WithPrompt("My prompt: ")
                        .WithCleanup(cleanup: ReadlineCleanup.RemoveAll)
                        .Read(Console);

            Assert.AreEqual(12, value);
            Assert.AreEqual(new ConsolePoint(0, 0), Console.GetCursorPosition());

            AssertConsole.BufferAndWindowLines();
        }
Beispiel #4
0
        public void BarelyOverflow()
        {
            var width = Console.WindowWidth;
            var word  = "abcde";
            var line  = string.Join("", System.Linq.Enumerable.Repeat(word, width / word.Length + 1)).Substring(0, width);

            Console.Input.Enqueue(line);
            Console.Input.Enqueue(ConsoleKey.Enter);

            var value = ReadlineConfiguration.Create <string>()
                        .Read(Console);

            AssertConsole.BufferAndWindowLines
            (
                line
            );
        }
        public void ScrollbackCleanUp()
        {
            Console.WindowHeight = 5;

            Console.WriteLine("Line 1");
            Console.WriteLine("Line 2");

            var display = new MenuDisplay <MenuOption <string> >(Console, 5);

            display.Cleanup = InputCleanup.Clean;
            display.Options.Add(new MenuOption <string>("first", "first"));
            display.Options.Add(new MenuOption <string>("second", "second"));
            display.Options.Add(new MenuOption <string>("third", "third"));
            display.Options.Add(new MenuOption <string>("fourth", "fourth"));
            display.Options.Add(new MenuOption <string>("fifth", "fifth"));
            display.Dispose();

            AssertConsole.BufferAndWindowLines
            (
                "Line 1",
                "Line 2"
            );
        }
        public void ReducedDisplayLines()
        {
            var dis = new MenuDisplay <MenuOption <string> >(Console, 2);

            dis.Options.Add(new MenuOption <string>("first", "first"));
            dis.Options.Add(new MenuOption <string>("second", "second"));
            dis.Options.Add(new MenuOption <string>("third", "third"));

            AssertConsole.BufferAndWindowLines
            (
                "  first",
                "  second"
            );

            dis.HandleKey(new ConsoleKeyInfo('\0', ConsoleKey.UpArrow, false, false, false));

            AssertConsole.BufferAndWindowLines
            (
                "  second",
                "> third"
            );

            dis.Options.RemoveAt(0);

            AssertConsole.BufferAndWindowLines
            (
                "  second",
                "> third"
            );

            dis.Options.RemoveAt(0);

            AssertConsole.BufferAndWindowLines
            (
                "> third"
            );
        }