示例#1
0
        public void Run()
        {
            _commands = LoadConsoleCommands();

            Vt100.SwitchToAlternateBuffer();
            Vt100.HideCursor();

            InitializeScreen();

            using (_repository)
            {
                while (!_done)
                {
                    var width  = Console.WindowWidth;
                    var height = Console.WindowHeight;

                    var key     = Console.ReadKey(true);
                    var command = _commands.FirstOrDefault(c => c.MatchesKey(key));
                    command?.Execute();

                    if (width != Console.WindowWidth || height != Console.WindowHeight)
                    {
                        InitializeScreen();
                    }
                }

                Vt100.ResetScrollMargins();
                Vt100.SwitchToMainBuffer();
                Vt100.ShowCursor();
            }
        }
示例#2
0
        private void Search()
        {
            var sb = new StringBuilder();

            while (true)
            {
                Vt100.HideCursor();
                Vt100.SetCursorPosition(0, Console.WindowHeight - 1);
                Vt100.SetForegroundColor(ConsoleColor.Blue);
                Vt100.SetBackgroundColor(ConsoleColor.Gray);
                Console.Write("/");
                Vt100.EraseRestOfCurrentLine();
                Console.Write(sb);
                Vt100.ShowCursor();

                var k = Console.ReadKey(intercept: true);

                if (k.Key == ConsoleKey.Enter)
                {
                    break;
                }
                else if (k.Key == ConsoleKey.Escape)
                {
                    sb.Clear();
                    break;
                }
                else if (k.Key == ConsoleKey.Backspace)
                {
                    if (sb.Length > 0)
                    {
                        sb.Length--;
                    }
                }
                else if (k.KeyChar >= 32)
                {
                    sb.Append(k.KeyChar);
                    if (sb.Length == Console.WindowWidth - 1)
                    {
                        break;
                    }
                }
            }

            Vt100.HideCursor();
            UpdateFooter();

            if (sb.Length == 0)
            {
                return;
            }

            var searchResults = new SearchResults(_view.Document, sb.ToString());

            if (searchResults.Hits.Count == 0)
            {
                Vt100.HideCursor();
                Vt100.SetCursorPosition(0, Console.WindowHeight - 1);
                Vt100.SetForegroundColor(ConsoleColor.Blue);
                Vt100.SetBackgroundColor(ConsoleColor.Gray);
                Vt100.EraseRestOfCurrentLine();
                Console.Write("<< NO RESULTS FOUND >>");
                Console.ReadKey();
                UpdateFooter();
                return;
            }

            _view.SearchResults = searchResults;
            _view.SelectedLine  = searchResults.Hits.First().LineIndex;
        }