From af339f7cfeabab611a96108cd5970ace43d7fb54 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 8 Apr 2020 19:11:15 -0700 Subject: [PATCH] termwiz: line editor: allow application cursor keys On Windows, if you run `wsl.exe` from the terminal and start zsh (maybe bash also?) and it enables application cursor key mode, exiting zsh doesn't clear application cursor key mode and when we return to the shell and are using virtual terminal input rather than the native windows console input, we'll continue to receive application cursor key sequences instead of regular cursor key input sequences. This commit recognizes both flavors as arrow movement in the line editor to make this feel less broken. --- termwiz/src/lineedit/mod.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/termwiz/src/lineedit/mod.rs b/termwiz/src/lineedit/mod.rs index b89bfe5be..c1df5e8e8 100644 --- a/termwiz/src/lineedit/mod.rs +++ b/termwiz/src/lineedit/mod.rs @@ -291,6 +291,10 @@ impl LineEditor { | InputEvent::Key(KeyEvent { key: KeyCode::UpArrow, modifiers: Modifiers::NONE, + }) + | InputEvent::Key(KeyEvent { + key: KeyCode::ApplicationUpArrow, + modifiers: Modifiers::NONE, }) => Some(Action::HistoryPrevious), InputEvent::Key(KeyEvent { @@ -300,12 +304,20 @@ impl LineEditor { | InputEvent::Key(KeyEvent { key: KeyCode::DownArrow, modifiers: Modifiers::NONE, + }) + | InputEvent::Key(KeyEvent { + key: KeyCode::ApplicationDownArrow, + modifiers: Modifiers::NONE, }) => Some(Action::HistoryNext), InputEvent::Key(KeyEvent { key: KeyCode::Char('B'), modifiers: Modifiers::CTRL, }) + | InputEvent::Key(KeyEvent { + key: KeyCode::ApplicationLeftArrow, + modifiers: Modifiers::NONE, + }) | InputEvent::Key(KeyEvent { key: KeyCode::LeftArrow, modifiers: Modifiers::NONE, @@ -323,6 +335,10 @@ impl LineEditor { | InputEvent::Key(KeyEvent { key: KeyCode::LeftArrow, modifiers: Modifiers::ALT, + }) + | InputEvent::Key(KeyEvent { + key: KeyCode::ApplicationLeftArrow, + modifiers: Modifiers::ALT, }) => Some(Action::Move(Movement::BackwardWord(1))), InputEvent::Key(KeyEvent { @@ -332,6 +348,10 @@ impl LineEditor { | InputEvent::Key(KeyEvent { key: KeyCode::RightArrow, modifiers: Modifiers::ALT, + }) + | InputEvent::Key(KeyEvent { + key: KeyCode::ApplicationRightArrow, + modifiers: Modifiers::ALT, }) => Some(Action::Move(Movement::ForwardWord(1))), InputEvent::Key(KeyEvent { @@ -357,6 +377,10 @@ impl LineEditor { | InputEvent::Key(KeyEvent { key: KeyCode::RightArrow, modifiers: Modifiers::NONE, + }) + | InputEvent::Key(KeyEvent { + key: KeyCode::ApplicationRightArrow, + modifiers: Modifiers::NONE, }) => Some(Action::Move(Movement::ForwardChar(1))), InputEvent::Key(KeyEvent { key: KeyCode::Char(c),