mod global;
mod help;
mod normal;
mod search;
#[cfg(test)]
mod keybind_tests;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use crate::tui::app::App;
pub(super) fn handle_key_event(
app: &mut App,
key: KeyEvent,
) {
match key.code {
KeyCode::Char('c') | KeyCode::Char('d') if key.modifiers.contains(KeyModifiers::CONTROL) => {
app.should_quit = true;
return;
},
KeyCode::Char('n') | KeyCode::Char('p') if key.modifiers.contains(KeyModifiers::CONTROL) => {
return;
},
_ => {},
}
if app.is_pending_key_expired() {
app.clear_pending_key();
}
if app.show_help() {
help::handle_help_mode(app, key);
return;
}
if global::handle_global_keybinds(app, &key) {
return;
}
match app.input_mode() {
crate::tui::state::InputMode::Normal => normal::handle_normal_mode(app, key),
crate::tui::state::InputMode::Search => search::handle_search_mode(app, key),
}
}