huellas/src/tui/keys.rs

27 lines
955 B
Rust
Raw Normal View History

2025-06-13 18:38:31 -04:00
//! Keyboard handling
use crossterm::event::{KeyCode, KeyEvent};
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,
_ => {}
},
Mode::Edit => match key_event.code {
KeyCode::Esc => state.mode = Mode::List,
_ => {}
},
}
}