//! Keyboard handling use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use super::state::{Mode, State}; /// Event handling pub async fn handle_key(state: &mut State, key_event: KeyEvent) { match state.mode { Mode::List => { if state.confirmation.is_some() { match key_event.code { KeyCode::Char('y') => state.proceed_confirmation().await, KeyCode::Char('n') | KeyCode::Esc => state.cancel_confirmation(), _ => {} } } else { match key_event.code { KeyCode::Char('d') => state.confirm_deletion(), 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.modifiers, key_event.code) { (KeyModifiers::NONE, KeyCode::Esc) => state.mode = Mode::List, (KeyModifiers::NONE, KeyCode::Tab) => {} (KeyModifiers::SHIFT, KeyCode::Tab) => {} _ => {} }, } }