| 1 |
use crossterm::event::{Event, KeyCode}; |
| 2 |
use ratatui::crossterm::{self, event::KeyModifiers}; |
| 3 |
|
| 4 |
use super::Input; |
| 5 |
|
| 6 |
impl From<&Event> for Input { |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
fn from(value: &Event) -> Self { |
| 11 |
if let Event::Key(key) = value |
| 12 |
&& matches!( |
| 13 |
key.kind, |
| 14 |
crossterm::event::KeyEventKind::Press | crossterm::event::KeyEventKind::Repeat |
| 15 |
) |
| 16 |
{ |
| 17 |
let input = match key.code { |
| 18 |
KeyCode::Char('j') | KeyCode::Down => Input::Down, |
| 19 |
KeyCode::Char('k') | KeyCode::Up => Input::Up, |
| 20 |
KeyCode::Left | KeyCode::Backspace => Input::Left, |
| 21 |
KeyCode::Char('h') => { |
| 22 |
if key.modifiers.contains(KeyModifiers::CONTROL) { |
| 23 |
Input::ToggleShowHidden |
| 24 |
} else { |
| 25 |
Input::Left |
| 26 |
} |
| 27 |
} |
| 28 |
KeyCode::Char('l') | KeyCode::Right | KeyCode::Enter => Input::Right, |
| 29 |
KeyCode::Home => Input::Home, |
| 30 |
KeyCode::End => Input::End, |
| 31 |
KeyCode::PageUp => Input::PageUp, |
| 32 |
KeyCode::PageDown => Input::PageDown, |
| 33 |
_ => Input::None, |
| 34 |
}; |
| 35 |
|
| 36 |
return input; |
| 37 |
} |
| 38 |
|
| 39 |
Input::None |
| 40 |
} |
| 41 |
} |