From 99d377d4ce115da639ec59daaeb4b3f5e5a303b3 Mon Sep 17 00:00:00 2001 From: John Doty Date: Tue, 21 Mar 2023 23:17:16 -0700 Subject: [PATCH] Make help modal I don't like that ENTER and the arrow keys still manipulate the list while help is showing. Ignore other keypresses while the help screen is shown. Also, make the spelling/capitalization a little cleaner. --- src/client/ui.rs | 53 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/src/client/ui.rs b/src/client/ui.rs index 899ab62..ec0ac73 100644 --- a/src/client/ui.rs +++ b/src/client/ui.rs @@ -292,14 +292,14 @@ impl UI { let keybindings = vec![ Row::new(vec!["↑ / k", "Move cursor up"]), Row::new(vec!["↓ / j", "Move cursor down"]), - Row::new(vec!["e", "enable/disable forwarding"]), + Row::new(vec!["e", "Enable/disable forwarding"]), Row::new(vec!["RET", "Open port in web browser"]), - Row::new(vec!["ESC / q", "exit"]), + Row::new(vec!["ESC / q", "Quit"]), Row::new(vec!["? / h", "Show this help text"]), Row::new(vec!["l", "Show fwd's logs"]), ]; - let help_intro = 2; + let help_intro = 4; let border_lines = 3; let help_popup_area = centered_rect( @@ -322,17 +322,15 @@ impl UI { let keybindings = Table::new(keybindings) .widths(&[Constraint::Length(7), Constraint::Length(40)]) .column_spacing(1) - .block( - Block::default().title("key bindings").borders(Borders::TOP), - ); + .block(Block::default().title("Keys").borders(Borders::TOP)); let exp = Paragraph::new( - "fwd forwards all ports discovered on the target when it starts.", + "fwd automatically listens for connections on the same ports\nas the target, and forwards connections on those ports to the\ntarget.", ); // outer box frame.render_widget(Clear, help_popup_area); //this clears out the background - let helpbox = Block::default().title("help").borders(Borders::ALL); + let helpbox = Block::default().title("Help").borders(Borders::ALL); frame.render_widget(helpbox, help_popup_area); // explanation @@ -426,6 +424,37 @@ impl UI { fn handle_console_event( &mut self, ev: Option>, + ) { + if self.show_help { + self.handle_console_event_help(ev) + } else { + self.handle_console_event_main(ev) + } + } + + fn handle_console_event_help( + &mut self, + ev: Option>, + ) { + match ev { + Some(Ok(Event::Key(ev))) => match ev { + KeyEvent { code: KeyCode::Esc, .. } + | KeyEvent { code: KeyCode::Char('q'), .. } + | KeyEvent { code: KeyCode::Char('?'), .. } + | KeyEvent { code: KeyCode::Char('h'), .. } => { + self.show_help = false; + } + _ => (), + }, + Some(Ok(_)) => (), // Don't care about this event... + Some(Err(_)) => (), // Hmmmmmm.....? + None => (), // ....no events? what? + } + } + + fn handle_console_event_main( + &mut self, + ev: Option>, ) { match ev { Some(Ok(Event::Key(ev))) => match ev { @@ -436,13 +465,7 @@ impl UI { } KeyEvent { code: KeyCode::Esc, .. } | KeyEvent { code: KeyCode::Char('q'), .. } => { - // it's natural to press q to get out of a help screen, so - // don't shut down if users do ?q - if self.show_help { - self.show_help = false; - } else { - self.running = false; - } + self.running = false; } KeyEvent { code: KeyCode::Char('?'), .. } | KeyEvent { code: KeyCode::Char('h'), .. } => {