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