| 1234567891011121314151617181920212223242526 |
- use crate::app::{App, AppResult};
- 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();
- }
- }
- KeyCode::Down => {
- app.lumps.next();
- }
- KeyCode::Up => {
- app.lumps.previous();
- }
- _ => {}
- }
- Ok(())
- }
|