Debian Codegraph @

src/input/termwiz.rs

raw symbols SCIP
1 use ratatui::termwiz::{input::InputEvent, input::KeyCode, input::Modifiers};
2
3 use super::Input;
4
5 impl From<&InputEvent> for Input {
6 /// Convert termwiz [`InputEvent`](https://docs.rs/termwiz/latest/termwiz/input/enum.InputEvent.html) to [`Input`].
7 ///
8 /// **Note:** This implementation is only available when the `termwiz` feature is enabled.
9 fn from(value: &InputEvent) -> Self {
10 match value {
11 InputEvent::Key(key) => match key.key {
12 KeyCode::Char('j') | KeyCode::DownArrow => Input::Down,
13 KeyCode::Char('k') | KeyCode::UpArrow => Input::Up,
14 KeyCode::LeftArrow | KeyCode::Backspace => Input::Left,
15 KeyCode::Char('h') => {
16 if key.modifiers.contains(Modifiers::CTRL) {
17 Input::ToggleShowHidden
18 } else {
19 Input::Left
20 }
21 }
22
23 KeyCode::Char('l') | KeyCode::RightArrow | KeyCode::Enter => Input::Right,
24 KeyCode::Home => Input::Home,
25 KeyCode::End => Input::End,
26 KeyCode::PageUp => Input::PageUp,
27 KeyCode::PageDown => Input::PageDown,
28 _ => Input::None,
29 },
30 _ => Input::None,
31 }
32 }
33 }