2023-04-11 09:04:00 +02:00
|
|
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
|
|
|
|
|
|
|
use super::app::App;
|
|
|
|
|
|
|
|
/// Handles the key events and updates the state of [`App`].
|
|
|
|
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) {
|
|
|
|
match key_event.code {
|
2023-04-11 14:53:27 +02:00
|
|
|
// Exit application on `ESC` or `q`.
|
2023-04-11 09:04:00 +02:00
|
|
|
KeyCode::Esc | KeyCode::Char('q') => {
|
|
|
|
app.quit();
|
|
|
|
}
|
2023-04-11 14:53:27 +02:00
|
|
|
// Exit application on `Ctrl-C`.
|
2023-04-11 09:04:00 +02:00
|
|
|
KeyCode::Char('c') | KeyCode::Char('C') => {
|
|
|
|
if key_event.modifiers == KeyModifiers::CONTROL {
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
}
|
2023-04-11 14:53:27 +02:00
|
|
|
// Category change.
|
|
|
|
KeyCode::Left => {
|
|
|
|
app.decrement_category();
|
|
|
|
}
|
|
|
|
KeyCode::Right => {
|
|
|
|
app.increment_category();
|
|
|
|
}
|
|
|
|
// Selection change.
|
|
|
|
KeyCode::Up => {
|
|
|
|
app.decrement_selection();
|
|
|
|
}
|
|
|
|
KeyCode::Down => {
|
|
|
|
app.increment_selection();
|
|
|
|
}
|
2023-04-11 09:04:00 +02:00
|
|
|
// Other handlers you could add here.
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|