1use crate::app::App;
2use crate::ui;
3use crossterm::event::{KeyCode, KeyEvent};
4
5pub fn handle_help_key(app: &mut App, key: KeyEvent) {
6 let max_scroll = app.help_page_max_scroll();
7 match key.code {
8 KeyCode::Down | KeyCode::Char('j') => {
9 if app.help_scroll_offset < max_scroll {
10 app.help_scroll_offset = app.help_scroll_offset.saturating_add(1);
11 }
12 }
13 KeyCode::Up | KeyCode::Char('k') => {
14 app.help_scroll_offset = app.help_scroll_offset.saturating_sub(1);
15 }
16 KeyCode::Left | KeyCode::Char('h') => {
17 app.overlay.help_page = app.overlay.help_page.saturating_sub(1);
18 app.help_scroll_offset = 0;
19 }
20 KeyCode::Right | KeyCode::Char('l') => {
21 if app.overlay.help_page + 1 < ui::HELP_PAGE_COUNT {
22 app.overlay.help_page += 1;
23 app.help_scroll_offset = 0;
24 }
25 }
26 _ => {
27 app.overlay.help = false;
28 app.overlay.help_page = 0;
29 app.help_scroll_offset = 0;
30 }
31 }
32}