musichoard/src/tui/handler.rs

22 lines
633 B
Rust
Raw Normal View History

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 {
// Exit application on `ESC` or `q`
KeyCode::Esc | KeyCode::Char('q') => {
app.quit();
}
// Exit application on `Ctrl-C`
KeyCode::Char('c') | KeyCode::Char('C') => {
if key_event.modifiers == KeyModifiers::CONTROL {
app.quit();
}
}
// Other handlers you could add here.
_ => {}
}
}