use crate::app::{App, AppResult, TuiSection};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
match key_event.code {
KeyCode::Esc | KeyCode::Char('q') => {
app.quit();
}
KeyCode::Char('c') | KeyCode::Char('C') => {
if key_event.modifiers == KeyModifiers::CONTROL {
app.quit();
}
}
KeyCode::Left | KeyCode::Char('h') => {
app.pages.unselect();
app.select_prev_section();
match app.selected_section {
TuiSection::BOOKS => {}
TuiSection::PAGES => app.books.previous(),
TuiSection::CONTENT => app.pages.previous(),
}
}
KeyCode::Right | KeyCode::Char('l') => {
match app.selected_section {
TuiSection::BOOKS => app.pages.next(),
TuiSection::PAGES => {}
_ => {}
}
app.select_next_section();
}
KeyCode::Up | KeyCode::Char('k') => match app.selected_section {
TuiSection::BOOKS => app.books.previous(),
TuiSection::PAGES => app.pages.previous(),
_ => {}
},
KeyCode::Down | KeyCode::Char('j') => match app.selected_section {
TuiSection::BOOKS => app.books.next(),
TuiSection::PAGES => app.pages.next(),
_ => {}
},
_ => {}
}
Ok(())
}