2025-06-13 18:38:31 -04:00
|
|
|
//! Keyboard handling
|
|
|
|
|
|
2025-06-13 18:48:22 -04:00
|
|
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
2025-06-13 18:38:31 -04:00
|
|
|
|
|
|
|
|
use super::state::{Mode, State};
|
|
|
|
|
|
|
|
|
|
/// Event handling
|
|
|
|
|
pub async fn handle_key(state: &mut State, key_event: KeyEvent) {
|
|
|
|
|
match state.mode {
|
|
|
|
|
Mode::List => match key_event.code {
|
|
|
|
|
KeyCode::Char('e') => state.mode = Mode::Edit,
|
|
|
|
|
KeyCode::Home => state.selected_place.select_first(),
|
|
|
|
|
KeyCode::End => state.selected_place.select_last(),
|
|
|
|
|
KeyCode::PageUp => state.prev_page(),
|
|
|
|
|
KeyCode::PageDown => state.next_page(),
|
|
|
|
|
KeyCode::Up | KeyCode::Char('k') => state.selected_place.select_previous(),
|
|
|
|
|
KeyCode::Down | KeyCode::Char('j') => state.selected_place.select_next(),
|
|
|
|
|
KeyCode::Esc | KeyCode::Char('q') => state.quit = true,
|
|
|
|
|
_ => {}
|
|
|
|
|
},
|
2025-06-13 18:48:22 -04:00
|
|
|
Mode::Edit => match (key_event.modifiers, key_event.code) {
|
|
|
|
|
(KeyModifiers::NONE, KeyCode::Esc) => state.mode = Mode::List,
|
|
|
|
|
(KeyModifiers::NONE, KeyCode::Tab) => {}
|
|
|
|
|
(KeyModifiers::SHIFT, KeyCode::Tab) => {}
|
2025-06-13 18:38:31 -04:00
|
|
|
_ => {}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|