From e7d53a7d00ccfe57e05bc4bd65824218e417bdeb Mon Sep 17 00:00:00 2001 From: ChristianVisintin Date: Tue, 15 Dec 2020 15:00:21 +0100 Subject: [PATCH] Help page in auth activity --- src/ui/activities/auth_activity/input.rs | 44 ++++++-- src/ui/activities/auth_activity/layout.rs | 119 ++++++++++++++++++++-- src/ui/activities/auth_activity/mod.rs | 1 + 3 files changed, 150 insertions(+), 14 deletions(-) diff --git a/src/ui/activities/auth_activity/input.rs b/src/ui/activities/auth_activity/input.rs index 2dc291b..8f6040f 100644 --- a/src/ui/activities/auth_activity/input.rs +++ b/src/ui/activities/auth_activity/input.rs @@ -154,12 +154,19 @@ impl AuthActivity { // Check if Ctrl is enabled if key.modifiers.intersects(KeyModifiers::CONTROL) { // If 'S', save bookmark as... - if matches!(ch, 'S' | 's') { - // Save bookmark as... - self.input_mode = InputMode::Popup(PopupType::Input( - String::from("Save bookmark as..."), - AuthActivity::callback_save_bookmark, - )); + match ch { + 'H' | 'h' => { + // Show help + self.input_mode = InputMode::Popup(PopupType::Help); + } + 'S' | 's' => { + // Save bookmark as... + self.input_mode = InputMode::Popup(PopupType::Input( + String::from("Save bookmark as..."), + AuthActivity::callback_save_bookmark, + )); + } + _ => { /* Nothing to do */ } } } else { match self.selected_field { @@ -270,6 +277,10 @@ impl AuthActivity { AuthActivity::callback_nothing_to_do, )); } + 'H' | 'h' => { + // Show help + self.input_mode = InputMode::Popup(PopupType::Help); + } 'S' | 's' => { // Save bookmark as... self.input_mode = InputMode::Popup(PopupType::Input( @@ -347,6 +358,10 @@ impl AuthActivity { AuthActivity::callback_nothing_to_do, )); } + 'H' | 'h' => { + // Show help + self.input_mode = InputMode::Popup(PopupType::Help); + } 'S' | 's' => { // Save bookmark as... self.input_mode = InputMode::Popup(PopupType::Input( @@ -367,6 +382,7 @@ impl AuthActivity { pub(super) fn handle_input_event_mode_popup(&mut self, ev: &InputEvent, ptype: PopupType) { match ptype { PopupType::Alert(_, _) => self.handle_input_event_mode_popup_alert(ev), + PopupType::Help => self.handle_input_event_mode_popup_help(ev), PopupType::Input(_, cb) => self.handle_input_event_mode_popup_input(ev, cb), PopupType::YesNo(_, yes_cb, no_cb) => { self.handle_input_event_mode_popup_yesno(ev, yes_cb, no_cb) @@ -386,6 +402,22 @@ impl AuthActivity { } } + /// ### handle_input_event_mode_popup_help + /// + /// Input event handler for popup help + pub(super) fn handle_input_event_mode_popup_help(&mut self, ev: &InputEvent) { + // If enter, close popup + if let InputEvent::Key(key) = ev { + match key.code { + KeyCode::Enter | KeyCode::Esc => { + // Set input mode back to form + self.input_mode = InputMode::Form; + } + _ => { /* Nothing to do */ } + } + } + } + /// ### handle_input_event_mode_popup_input /// /// Input event handler for input popup diff --git a/src/ui/activities/auth_activity/layout.rs b/src/ui/activities/auth_activity/layout.rs index d008c03..e91087d 100644 --- a/src/ui/activities/auth_activity/layout.rs +++ b/src/ui/activities/auth_activity/layout.rs @@ -127,6 +127,7 @@ impl AuthActivity { // Calculate popup size let (width, height): (u16, u16) = match popup { PopupType::Alert(_, _) => (50, 10), + PopupType::Help => (50, 70), PopupType::Input(_, _) => (40, 10), PopupType::YesNo(_, _, _) => (30, 10), }; @@ -137,6 +138,7 @@ impl AuthActivity { self.draw_popup_alert(*color, txt.clone(), popup_area.width), popup_area, ), + PopupType::Help => f.render_widget(self.draw_popup_help(), popup_area), PopupType::Input(txt, _) => { f.render_widget(self.draw_popup_input(txt.clone()), popup_area); // Set cursor @@ -257,14 +259,8 @@ impl AuthActivity { let (footer, h_style) = ( vec![ Span::raw("Press "), - Span::styled("", Style::default().add_modifier(Modifier::BOLD)), - Span::raw(" to exit, "), - Span::styled("", Style::default().add_modifier(Modifier::BOLD)), - Span::raw(" to change input field, "), - Span::styled("", Style::default().add_modifier(Modifier::BOLD)), - Span::raw(" to change input form, "), - Span::styled("", Style::default().add_modifier(Modifier::BOLD)), - Span::raw(" to submit form"), + Span::styled("", Style::default().add_modifier(Modifier::BOLD)), + Span::raw(" to show keybindings"), ], Style::default().add_modifier(Modifier::BOLD), ); @@ -439,4 +435,111 @@ impl AuthActivity { .fg(Color::Yellow), ) } + + /// ### draw_footer + /// + /// Draw authentication page footer + pub(super) fn draw_popup_help(&self) -> List { + // Write header + let cmds: Vec = vec![ + ListItem::new(Spans::from(vec![ + Span::styled( + "", + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), + ), + Span::raw(" "), + Span::raw("Quit TermSCP"), + ])), + ListItem::new(Spans::from(vec![ + Span::styled( + "", + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), + ), + Span::raw(" "), + Span::raw("Switch input form and bookmarks"), + ])), + ListItem::new(Spans::from(vec![ + Span::styled( + "", + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), + ), + Span::raw(" "), + Span::raw("Change bookmark tab"), + ])), + ListItem::new(Spans::from(vec![ + Span::styled( + "", + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), + ), + Span::raw(" "), + Span::raw("Move up/down in current tab"), + ])), + ListItem::new(Spans::from(vec![ + Span::styled( + "", + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), + ), + Span::raw(" "), + Span::raw("Submit"), + ])), + ListItem::new(Spans::from(vec![ + Span::styled( + "", + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), + ), + Span::raw(" "), + Span::raw("Delete bookmark"), + ])), + ListItem::new(Spans::from(vec![ + Span::styled( + "", + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), + ), + Span::raw(" "), + Span::raw("Delete selected bookmark"), + ])), + ListItem::new(Spans::from(vec![ + Span::styled( + "", + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), + ), + Span::raw(" "), + Span::raw("Show help"), + ])), + ListItem::new(Spans::from(vec![ + Span::styled( + "", + Style::default() + .fg(Color::Cyan) + .add_modifier(Modifier::BOLD), + ), + Span::raw(" "), + Span::raw("Save bookmark"), + ])), + ]; + List::new(cmds) + .block( + Block::default() + .borders(Borders::ALL) + .border_style(Style::default()) + .title("Help"), + ) + .start_corner(Corner::TopLeft) + } } diff --git a/src/ui/activities/auth_activity/mod.rs b/src/ui/activities/auth_activity/mod.rs index fc79be9..fe66be7 100644 --- a/src/ui/activities/auth_activity/mod.rs +++ b/src/ui/activities/auth_activity/mod.rs @@ -75,6 +75,7 @@ enum DialogYesNoOption { #[derive(Clone)] enum PopupType { Alert(Color, String), // Show a message displaying text with the provided color + Help, // Help page Input(String, OnInputSubmitCallback), // Input description; Callback for submit YesNo(String, DialogCallback, DialogCallback), // Yes, no callback }