示例#1
0
        private void UpdateOption(int index)
        {
            if (!_updateOptions)
            {
                return;
            }

            var displayedIndex = index - _displayOffset;

            if (displayedIndex < 0 || displayedIndex >= _displayed.Count)
            {
                return;
            }

            var text = _options.Count > index ? _options[index].Text : ConsoleString.Empty;

            text = GetPrefix(index) + text;

            if (text == _displayed[displayedIndex])
            {
                return;
            }

            var offset = new ConsoleSize(_prompt.Length, displayedIndex);
            int oldLen = _displayed[displayedIndex].Length;

            _console.TemporaryShift(_origin + offset, c =>
            {
                c.Render(new string(' ', oldLen) + new string('\b', oldLen));
                c.Write(text);
            });

            _displayed[displayedIndex] = text;
        }
示例#2
0
        public void SetWindowSize(int width, int height)
        {
            if (width + WindowLeft > BufferWidth)
            {
                throw new ArgumentOutOfRangeException(nameof(width));
            }

            if (height + WindowTop > BufferHeight)
            {
                throw new ArgumentOutOfRangeException(nameof(height));
            }

            _windowSize = new ConsoleSize(width, height);
        }
示例#3
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();
        }
示例#4
0
 static void InitUi(int x, int y)
 {
     Console.CursorVisible = false;
     ConsoleSize.SetWindowSize(x + 2, y + 7);
     Console.SetCursorPosition(0, 0);
     ConsoleWrite.WriteRowOf('#');
     for (int i = 0; i < y; i++)
     {
         Console.Write("#");
         for (int j = 0; j < x; j++)
         {
             Console.Write(" ");
         }
         Console.Write("#");
     }
     ConsoleWrite.WriteRowOf('#');
     ConsoleWrite.WriteCentered("Snake");
     ShowScore(y, 0);
 }
示例#5
0
        public void SetBufferSize(int width, int height)
        {
            if (width == _bufferSize.Width && height == _bufferSize.Height)
            {
                return;
            }

            if (height < _content.Count)
            {
                _content.RemoveRange(height, _content.Count - height);
                _foreground.RemoveRange(height, _foreground.Count - height);
                _background.RemoveRange(height, _background.Count - height);
            }

            for (int r = 0; r < _content.Count; r++)
            {
                var c  = _content[r];
                var fg = _foreground[r];
                var bg = _background[r];

                Array.Resize(ref c, width);
                Array.Resize(ref fg, width);
                Array.Resize(ref bg, width);

                for (int i = _bufferSize.Width; i < width; i++)
                {
                    c[i]  = ' ';
                    fg[i] = ConsoleColor.DarkGray;
                    bg[i] = ConsoleColor.Black;
                }

                _content[r]    = c;
                _foreground[r] = fg;
                _background[r] = bg;
            }

            _bufferSize = new ConsoleSize(width, height);
        }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MenuDisplay{T}"/> class.
 /// </summary>
 /// <param name="offset">The offset from the current cursor position where to 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, ConsoleSize offset, int displayedLines)
     : this(console, console.GetCursorPosition() + offset, displayedLines)
 {
 }
 public virtual void SetUnit(ConsoleSize unit)
 {
     Unit = unit;
 }