Ejemplo n.º 1
0
        private async Task <bool> OnSearchHistoryAsync(ConsoleImproved prompt, ConsoleKeyEx key)
        {
            int oldPos = implementation.CursorTop;

            implementation.CursorLeft = 0;
            implementation.CursorTop  = implementation.WindowHeight - 2;

            // create fake shell object with a custom prompt
            var fakeShell = new Dotnet.Shell.API.Shell();

            fakeShell.History.AddRange(shell.History);
            fakeShell.Prompt = () =>
            {
                RenderSearchChanges();

                // Search) user search text
                // [1/3]: matched entry
                return("Search) ");
            };

            ci = new ConsoleImproved(implementation, fakeShell);

            ci.KeyOverrides.Where(x => x.Key.Key == ConsoleKey.UpArrow).ToList().ForEach(x => ci.KeyOverrides.Remove(x));
            ci.KeyOverrides.Where(x => x.Key.Key == ConsoleKey.DownArrow).ToList().ForEach(x => ci.KeyOverrides.Remove(x));

            ci.AddKeyOverride(ConsoleKeyEx.Any, OnSearchTextEnteredAsync);
            ci.AddKeyOverride(new ConsoleKeyEx(ConsoleKey.UpArrow), OnChangeSearchEntryAsync);
            ci.AddKeyOverride(new ConsoleKeyEx(ConsoleKey.DownArrow), OnChangeSearchEntryAsync);
            ci.AddKeyOverride(new ConsoleKeyEx(ConsoleKey.Enter), OnSelectSearchEntryAsync);

            ci.DisplayPrompt();

            // When the prompt returns, instead of executing the command we just set that
            // as what to show on screen
            var command = await ci.GetCommandAsync();

            implementation.CursorTop = implementation.WindowHeight - 2;
            implementation.Write(new string(' ', implementation.WindowWidth));
            implementation.CursorTop = implementation.WindowHeight - 1;
            implementation.Write(new string(' ', implementation.WindowWidth));

            implementation.CursorTop = oldPos;
            implementation.Write(new string(' ', implementation.WindowWidth));

            prompt.DisplayPrompt(command);

            return(false);
        }
Ejemplo n.º 2
0
 public HistorySearch(IConsole console, Dotnet.Shell.API.Shell shell)
 {
     this.implementation = console;
     this.shell          = shell;
 }
Ejemplo n.º 3
0
        public static Func <ConsoleImproved, ConsoleKeyEx, Task <bool> > OnSearchHistory(IConsole console, Dotnet.Shell.API.Shell shell)
        {
            var search = new HistorySearch(console, shell);

            return(search.OnSearchHistoryAsync);
        }