1 use crate::{
2     app::{App, AppResult},
3     backend::event::BackendEvent,
4 };
5 use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
6 
7 /// Handles the key events and updates the state of [`App`].
handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()>8 pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
9     match key_event.code {
10         // Exit application on `ESC` or `q`
11         KeyCode::Esc | KeyCode::Char('q') => {
12             app.quit();
13         }
14         // Exit application on `Ctrl-C`
15         KeyCode::Char('c') | KeyCode::Char('C') => {
16             if key_event.modifiers == KeyModifiers::CONTROL {
17                 app.quit();
18             }
19         }
20         // Counter handlers
21         KeyCode::Right => {
22             app.increment_counter();
23         }
24         KeyCode::Left => {
25             app.decrement_counter();
26         }
27         // Other handlers you could add here.
28         _ => {}
29     }
30     Ok(())
31 }
32 
handle_backend_events(_backend_event: BackendEvent, _app: &mut App) -> AppResult<()>33 pub fn handle_backend_events(_backend_event: BackendEvent, _app: &mut App) -> AppResult<()> {
34     return Ok(());
35 }
36