diff --git a/src/ui/mod.rs b/src/ui/mod.rs index afb7ffb..8d9cfa0 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -196,6 +196,7 @@ impl<'ws> Workspace<'ws> { "* CTRl-h: Shrink column width by 1".to_string(), "* CTRl-n: Next sheet. Starts over at beginning if at end.".to_string(), "* CTRl-p: Previous sheet. Starts over at end if at beginning.".to_string(), + "* CTRl-?: Previous sheet. Starts over at end if at beginning.".to_string(), "* q exit".to_string(), "* Ctrl-S Save sheet".to_string(), ], @@ -207,6 +208,7 @@ impl<'ws> Workspace<'ws> { Modality::Command => vec![ "Command Mode:".to_string(), "* ESC: Exit command mode".to_string(), + "* CTRL-?: Exit command mode".to_string(), "* ENTER/RETURN: run command and exit command mode".to_string(), ], _ => vec!["General help".to_string()], @@ -217,6 +219,10 @@ impl<'ws> Workspace<'ws> { if key.kind == KeyEventKind::Press { match key.code { KeyCode::Esc | KeyCode::Enter => self.exit_command_mode()?, + KeyCode::Char('h') if key.modifiers == KeyModifiers::ALT => { + self.enter_dialog_mode(self.render_help_text()); + return Ok(None); + } _ => { // NOOP } @@ -230,6 +236,7 @@ impl<'ws> Workspace<'ws> { if key.kind == KeyEventKind::Press { match key.code { KeyCode::Esc | KeyCode::Enter | KeyCode::Char('q') => self.exit_dialog_mode()?, + KeyCode::Char('h') if key.modifiers == KeyModifiers::ALT => self.exit_dialog_mode()?, _ => { // NOOP } @@ -241,7 +248,7 @@ impl<'ws> Workspace<'ws> { fn handle_edit_input(&mut self, key: event::KeyEvent) -> Result> { if key.kind == KeyEventKind::Press { match key.code { - KeyCode::Char('?') if key.modifiers == KeyModifiers::CONTROL => { + KeyCode::Char('h') if key.modifiers == KeyModifiers::ALT => { self.enter_dialog_mode(self.render_help_text()); return Ok(None); } @@ -339,7 +346,7 @@ impl<'ws> Workspace<'ws> { KeyCode::Char('s') if key.modifiers == KeyModifiers::CONTROL => { self.save_file()?; } - KeyCode::Char('?') => { + KeyCode::Char('h') if key.modifiers == KeyModifiers::ALT => { self.enter_dialog_mode(self.render_help_text()); } KeyCode::Char('n') if key.modifiers == KeyModifiers::CONTROL => { diff --git a/src/ui/render/mod.rs b/src/ui/render/mod.rs index 8f071a6..140d645 100644 --- a/src/ui/render/mod.rs +++ b/src/ui/render/mod.rs @@ -2,7 +2,7 @@ use ratatui::{ self, layout::Rect, text::{Line, Text}, - widgets::{Block, Tabs, Widget}, + widgets::{Block, Paragraph, Tabs, Widget}, Frame, }; use tui_popup::Popup; @@ -33,8 +33,11 @@ impl<'ws> Workspace<'ws> { tabs.render(rect, buf); }), Box::new(|rect: Rect, buf: &mut Buffer, ws: &mut Self| { - // TODO(zaphar): Show a small help text? - ws.text_area.render(rect, buf) + let [text_rect, info_rect] = Layout::horizontal(vec![Constraint::Fill(1),Constraint::Fill(1)]).areas(rect); + ws.text_area.render(text_rect, buf); + let hint = Paragraph::new(vec![Line::from(""),Line::from("ALT-h to toggle help dialog").centered()]); + // TODO(zaphar): Show a small getting-started text? + hint.render(info_rect, buf); }), Box::new(move |rect: Rect, buf: &mut Buffer, ws: &mut Self| { let sheet_name = ws.book.get_sheet_name().unwrap_or("Unknown"); diff --git a/src/ui/test.rs b/src/ui/test.rs index d4c80b0..7869cfa 100644 --- a/src/ui/test.rs +++ b/src/ui/test.rs @@ -266,7 +266,34 @@ fn test_edit_mode_help_keycode() { .expect("Failed to handle 'i' key"); assert_eq!(Some(&Modality::CellEdit), ws.state.modality_stack.last()); let edit_help = ws.render_help_text(); - ws.handle_input(construct_modified_key_event(KeyCode::Char('?'), KeyModifiers::CONTROL)) + ws.handle_input(construct_modified_key_event(KeyCode::Char('h'), KeyModifiers::ALT)) + .expect("Failed to handle 'ctrl-?' key event"); + assert_eq!(Some(&Modality::Dialog), ws.state.modality_stack.last()); + assert_eq!(edit_help, ws.state.popup); +} + +#[test] +fn test_navigation_mode_help_keycode() { + let mut ws = + Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook"); + assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); + let help_text = ws.render_help_text(); + ws.handle_input(construct_modified_key_event(KeyCode::Char('h'), KeyModifiers::ALT)) + .expect("Failed to handle 'ctrl-?' key event"); + assert_eq!(Some(&Modality::Dialog), ws.state.modality_stack.last()); + assert_eq!(help_text, ws.state.popup); +} + +#[test] +fn test_command_mode_help_keycode() { + let mut ws = + Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook"); + assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); + ws.handle_input(construct_key_event(KeyCode::Char(':'))) + .expect("Failed to handle ':' key"); + assert_eq!(Some(&Modality::Command), ws.state.modality_stack.last()); + let edit_help = ws.render_help_text(); + ws.handle_input(construct_modified_key_event(KeyCode::Char('h'), KeyModifiers::ALT)) .expect("Failed to handle 'ctrl-?' key event"); assert_eq!(Some(&Modality::Dialog), ws.state.modality_stack.last()); assert_eq!(edit_help, ws.state.popup);