From 0e32eed5dd0821b8d3218a026c44cc4b19456a16 Mon Sep 17 00:00:00 2001 From: rhysd Date: Sat, 3 Aug 2024 07:58:11 +0900 Subject: [PATCH] support shift/ctrl/alt + arrow keys combinations added at termion v4 fix #68 termion added the support at this commit: https://github.com/redox-os/termion/commit/3b52dc9bfb22da591a7b86a76a2e7234c45db08f --- src/input/termion.rs | 54 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/input/termion.rs b/src/input/termion.rs index 545c4b3..bf1ad66 100644 --- a/src/input/termion.rs +++ b/src/input/termion.rs @@ -17,6 +17,7 @@ impl From for Input { fn from(key: KeyEvent) -> Self { let mut ctrl = false; let mut alt = false; + let mut shift = false; let key = match key { KeyEvent::Char('\n' | '\r') => Key::Enter, KeyEvent::Char(c) => Key::Char(c), @@ -30,9 +31,57 @@ impl From for Input { } KeyEvent::Backspace => Key::Backspace, KeyEvent::Left => Key::Left, + KeyEvent::ShiftLeft => { + shift = true; + Key::Left + } + KeyEvent::AltLeft => { + alt = true; + Key::Left + } + KeyEvent::CtrlLeft => { + ctrl = true; + Key::Left + } KeyEvent::Right => Key::Right, + KeyEvent::ShiftRight => { + shift = true; + Key::Right + } + KeyEvent::AltRight => { + alt = true; + Key::Right + } + KeyEvent::CtrlRight => { + ctrl = true; + Key::Right + } KeyEvent::Up => Key::Up, + KeyEvent::ShiftUp => { + shift = true; + Key::Up + } + KeyEvent::AltUp => { + alt = true; + Key::Up + } + KeyEvent::CtrlUp => { + ctrl = true; + Key::Up + } KeyEvent::Down => Key::Down, + KeyEvent::ShiftDown => { + shift = true; + Key::Down + } + KeyEvent::AltDown => { + alt = true; + Key::Down + } + KeyEvent::CtrlDown => { + ctrl = true; + Key::Down + } KeyEvent::Home => Key::Home, KeyEvent::End => Key::End, KeyEvent::PageUp => Key::PageUp, @@ -48,7 +97,7 @@ impl From for Input { key, ctrl, alt, - shift: false, + shift, } } } @@ -106,6 +155,9 @@ mod tests { (KeyEvent::F(1), input(Key::F(1), false, false, false)), (KeyEvent::BackTab, input(Key::Tab, false, false, false)), (KeyEvent::Null, input(Key::Null, false, false, false)), + (KeyEvent::ShiftDown, input(Key::Down, false, false, true)), + (KeyEvent::AltUp, input(Key::Up, false, true, false)), + (KeyEvent::CtrlLeft, input(Key::Left, true, false, false)), ] { assert_eq!(Input::from(from), to, "{:?} -> {:?}", from, to); }