/// <summary>
        /// Initializes a new instance of the <see cref="MenuDisplay{T}"/> class.
        /// </summary>
        /// <param name="point">The point where the menu should be displayed.</param>
        /// <param name="displayedLines">
        /// The maximum number of console lines the menu display should use.
        /// The menu can display more options than this value.
        /// Values greater than the height of the console can result in odd effects.</param>
        public MenuDisplay(IConsole console, ConsolePoint point, int displayedLines)
        {
            _console      = console ?? throw new ArgumentNullException(nameof(console));
            _windowOrigin = _console.GetWindowPosition();
            _origin       = point;
            _options      = new MenuOptionCollection <TOption>();
            _options.CollectionChanged += OptionsCollectionChanged;
            _displayed = new List <ConsoleString>();
            for (int i = 0; i < displayedLines; i++)
            {
                _displayed.Add("");
            }
            _displayOffset = 0;

            _index    = -1;
            _prompt   = "> ";
            _noPrompt = "  ";

            _prefixTop    = new PrefixKeyCollection();
            _prefixBottom = new PrefixKeyCollection();
            _hasPrefix    = false;

            _prefixTop.PrefixSetChanged    += UpdateAllOptions;
            _prefixBottom.PrefixSetChanged += UpdateAllOptions;
        }
Beispiel #2
0
        private static void ApplyCleanup(ConsoleString prompt, IConsole console, ConsolePoint start, ConsoleReader reader, ReadlineCleanup cleanup)
        {
            switch (cleanup)
            {
            case ReadlineCleanup.None:
                console.WriteLine();
                break;

            case ReadlineCleanup.RemovePrompt:
                var text = reader.Text;
                reader.Text = string.Empty;
                console.SetCursorPosition(start);
                console.Write(new string(' ', prompt.Length));
                console.SetCursorPosition(start);
                console.WriteLine(text);
                break;

            case ReadlineCleanup.RemoveAll:
                reader.Text = string.Empty;
                console.SetCursorPosition(start);
                console.Write(new string(' ', prompt.Length));
                console.SetCursorPosition(start);
                break;
            }
        }
        public ConsoleString(ConsolePoint position, IEnumerable <ConsoleSegment> segments)
        {
            Position = position;
            Segments = segments.ToImmutableList();

            _outputString = new CommandLineParsing.Output.ConsoleString(Segments.Select(Map));
        }
Beispiel #4
0
        public void SetWindowPosition(int left, int top)
        {
            if (left + WindowWidth > BufferWidth)
            {
                throw new ArgumentOutOfRangeException(nameof(left));
            }

            if (top + WindowHeight > BufferHeight)
            {
                throw new ArgumentOutOfRangeException(nameof(top));
            }

            _windowPosition = new ConsolePoint(left, top);
        }
Beispiel #5
0
        public TestingConsole()
        {
            _bufferSize     = new ConsoleSize(80, 300);
            _cursorPosition = new ConsolePoint(0, 0);

            _windowSize     = new ConsoleSize(_bufferSize.Width, 20);
            _windowPosition = new ConsolePoint(0, 0);

            CursorVisible = true;
            ResetColor();

            _content    = new List <char[]>();
            _foreground = new List <ConsoleColor[]>();
            _background = new List <ConsoleColor[]>();

            _input = new InputCollection();
        }
Beispiel #6
0
        public void SetCursorPosition(int left, int top)
        {
            _cursorPosition = new ConsolePoint(left, top);

            if (top < WindowTop)
            {
                WindowTop = top;
            }
            else if (top >= WindowTop + WindowHeight)
            {
                WindowTop = top - WindowHeight + 1;
            }

            if (left < WindowLeft)
            {
                WindowLeft = left;
            }
            else if (left >= WindowLeft + WindowWidth)
            {
                WindowLeft = left - WindowWidth + 1;
            }
        }