mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-10 16:26:48 +00:00
36 lines
1009 B
Rust
36 lines
1009 B
Rust
use crate::{
|
|
app::{App, AppResult},
|
|
backend::event::BackendEvent,
|
|
};
|
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
|
|
|
/// Handles the key events and updates the state of [`App`].
|
|
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
|
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();
|
|
}
|
|
}
|
|
// Counter handlers
|
|
KeyCode::Right => {
|
|
app.increment_counter();
|
|
}
|
|
KeyCode::Left => {
|
|
app.decrement_counter();
|
|
}
|
|
// Other handlers you could add here.
|
|
_ => {}
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
pub fn handle_backend_events(_backend_event: BackendEvent, _app: &mut App) -> AppResult<()> {
|
|
return Ok(());
|
|
}
|