public void RegisterKeyPress(ConsoleKeyInfo key) { Context.Reset(); Context.KeyPressed = key; Context.CharacterToWrite = new ConsoleCharacter(Context.KeyPressed.KeyChar); IKeyHandler handler = null; if (KeyHandlers.TryGetValue(Context.KeyPressed.Key, out handler) == false && RichTextCommandLineReader.IsWriteable(Context.KeyPressed)) { WriteCharacterForPressedKey(Context.KeyPressed); DoSyntaxHighlighting(Context); } else if (handler != null) { handler.Handle(Context); if (Context.Intercept == false && RichTextCommandLineReader.IsWriteable(Context.KeyPressed)) { WriteCharacterForPressedKey(Context.KeyPressed); } DoSyntaxHighlighting(Context); } FireValueChanged(); }
private void OnKeyInputReceived(ConsoleKeyInfo info) { if (info.Key == ConsoleKey.UpArrow) { Up(); } else if (info.Key == ConsoleKey.DownArrow) { Down(); } else if (info.Key == ConsoleKey.LeftArrow) { Left(); } else if (info.Key == ConsoleKey.RightArrow) { Right(); } else if (info.Key == ConsoleKey.PageDown) { PageDown(); } else if (info.Key == ConsoleKey.PageUp) { PageUp(); } else if (info.Key == ConsoleKey.Home) { Home(); } else if (info.Key == ConsoleKey.End) { End(); } else if (info.Key == ConsoleKey.Enter) { Activate(); } else if (FilteringEnabled && RichTextCommandLineReader.IsWriteable(info) && FilterTextBox != null) { FilterTextBox.Value = info.KeyChar.ToString().ToConsoleString(); Application.FocusManager.TrySetFocus(FilterTextBox); } }
private async Task OnHandleHey(ConsoleKeyInfo keyInfo) { if (keyInfo.Key == ConsoleKey.Enter) { ConsoleString output = ConsoleString.Empty; try { var args = Args.Convert(tb.Value.ToString()); AddHistory(tb.Value.ToString()); var action = Args.ParseAction(def, args); (tb.Parent as ConsolePanel).Controls.Remove(tb); output = await Run(action); } catch (Exception ex) { var inner = ex; if (ex is AggregateException && (ex as AggregateException).InnerExceptions.Count == 1) { inner = ex.InnerException; } if (ex is ArgException == false) { throw; } output = inner.Message.ToRed(); } finally { if (IsExpired == false) { HardRefresh(output); } } } else if (keyInfo.Key == ConsoleKey.Tab) { ConsoleCharacter?prototype = tb.Value.Length == 0 ? (ConsoleCharacter?)null : tb.Value[tb.Value.Length - 1]; tb.RichTextEditor.RegisterKeyPress(keyInfo, prototype); } else if (keyInfo.Key == ConsoleKey.UpArrow) { if (HasHistory()) { tb.Value = GetHistoryPrevious(); outputLabel.Text = UpdateAssistiveText(); } } else if (keyInfo.Key == ConsoleKey.DownArrow) { if (HasHistory()) { tb.Value = GetHistoryNext(); outputLabel.Text = UpdateAssistiveText(); } } else if (RichTextCommandLineReader.IsWriteable(keyInfo)) { outputLabel.Text = UpdateAssistiveText(); } }
private async Task OnHandleHey(ConsoleKeyInfo keyInfo) { if (InputBox.IsInputBlocked) { return; } if (keyInfo.Key == ConsoleKey.Enter) { ConsoleString output = ConsoleString.Empty; try { var args = Args.Convert(InputBox.Value.ToString()); AddHistory(InputBox.Value.ToString()); if (def.ExceptionBehavior?.Policy == ArgExceptionPolicy.StandardExceptionHandling) { def.ExceptionBehavior = new ArgExceptionBehavior(ArgExceptionPolicy.DontHandleExceptions); } ArgAction action; ConsoleOutInterceptor.Instance.Attach(); try { action = Args.ParseAction(def, args); } finally { ConsoleOutInterceptor.Instance.Detatch(); } InputBox.Dispose(); output = new ConsoleString(ConsoleOutInterceptor.Instance.ReadAndClear()); if (action.Cancelled == false) { await Run(action); } } catch (Exception ex) { var inner = ex; if (ex is AggregateException && (ex as AggregateException).InnerExceptions.Count == 1) { inner = ex.InnerException; } if (ex is ArgException == false) { throw; } output = inner.Message.ToRed(); } finally { if (IsExpired == false) { HardRefresh(output); } } } else if (keyInfo.Key == ConsoleKey.Tab) { ConsoleCharacter?prototype = InputBox.Value.Length == 0 ? (ConsoleCharacter?)null : InputBox.Value[InputBox.Value.Length - 1]; InputBox.RichTextEditor.RegisterKeyPress(keyInfo, prototype); } else if (keyInfo.Key == ConsoleKey.UpArrow) { if (HasHistory()) { InputBox.Value = GetHistoryPrevious(); outputLabel.Text = UpdateAssistiveText(); } } else if (keyInfo.Key == ConsoleKey.DownArrow) { if (HasHistory()) { InputBox.Value = GetHistoryNext(); outputLabel.Text = UpdateAssistiveText(); } } else if (RichTextCommandLineReader.IsWriteable(keyInfo)) { outputLabel.Text = UpdateAssistiveText(); } }