mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Added 'save password' tab to auth activity when saving bookmarks
This commit is contained in:
@@ -53,6 +53,8 @@ impl AuthActivity {
|
||||
///
|
||||
/// Callback used to save bookmark with name
|
||||
pub(super) fn callback_save_bookmark(&mut self, input: String) {
|
||||
self.save_bookmark(input);
|
||||
if !input.is_empty() {
|
||||
self.save_bookmark(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,8 +160,10 @@ impl AuthActivity {
|
||||
self.input_mode = InputMode::Popup(PopupType::Help);
|
||||
}
|
||||
'S' | 's' => {
|
||||
// Default choice option to no
|
||||
self.choice_opt = DialogYesNoOption::No;
|
||||
// Save bookmark as...
|
||||
self.input_mode = InputMode::Popup(PopupType::Input(
|
||||
self.input_mode = InputMode::Popup(PopupType::SaveBookmark(
|
||||
String::from("Save bookmark as..."),
|
||||
AuthActivity::callback_save_bookmark,
|
||||
));
|
||||
@@ -282,8 +284,10 @@ impl AuthActivity {
|
||||
self.input_mode = InputMode::Popup(PopupType::Help);
|
||||
}
|
||||
'S' | 's' => {
|
||||
// Default choice option to no
|
||||
self.choice_opt = DialogYesNoOption::No;
|
||||
// Save bookmark as...
|
||||
self.input_mode = InputMode::Popup(PopupType::Input(
|
||||
self.input_mode = InputMode::Popup(PopupType::SaveBookmark(
|
||||
String::from("Save bookmark as..."),
|
||||
AuthActivity::callback_save_bookmark,
|
||||
));
|
||||
@@ -363,8 +367,10 @@ impl AuthActivity {
|
||||
self.input_mode = InputMode::Popup(PopupType::Help);
|
||||
}
|
||||
'S' | 's' => {
|
||||
// Default choice option to no
|
||||
self.choice_opt = DialogYesNoOption::No;
|
||||
// Save bookmark as...
|
||||
self.input_mode = InputMode::Popup(PopupType::Input(
|
||||
self.input_mode = InputMode::Popup(PopupType::SaveBookmark(
|
||||
String::from("Save bookmark as..."),
|
||||
AuthActivity::callback_save_bookmark,
|
||||
));
|
||||
@@ -383,7 +389,7 @@ impl AuthActivity {
|
||||
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::SaveBookmark(_, cb) => self.handle_input_event_mode_popup_save_bookmark(ev, cb),
|
||||
PopupType::YesNo(_, yes_cb, no_cb) => {
|
||||
self.handle_input_event_mode_popup_yesno(ev, yes_cb, no_cb)
|
||||
}
|
||||
@@ -418,10 +424,10 @@ impl AuthActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### handle_input_event_mode_popup_input
|
||||
/// ### handle_input_event_mode_popup_save_bookmark
|
||||
///
|
||||
/// Input event handler for input popup
|
||||
pub(super) fn handle_input_event_mode_popup_input(
|
||||
/// Input event handler for SaveBookmark popup
|
||||
pub(super) fn handle_input_event_mode_popup_save_bookmark(
|
||||
&mut self,
|
||||
ev: &InputEvent,
|
||||
cb: OnInputSubmitCallback,
|
||||
@@ -435,6 +441,8 @@ impl AuthActivity {
|
||||
self.input_txt.clear();
|
||||
// Set mode back to form
|
||||
self.input_mode = InputMode::Form;
|
||||
// Reset choice option to yes
|
||||
self.choice_opt = DialogYesNoOption::Yes;
|
||||
}
|
||||
KeyCode::Enter => {
|
||||
// Submit
|
||||
@@ -445,7 +453,11 @@ impl AuthActivity {
|
||||
self.input_mode = InputMode::Form;
|
||||
// Call cb
|
||||
cb(self, input_text);
|
||||
// Reset choice option to yes
|
||||
self.choice_opt = DialogYesNoOption::Yes;
|
||||
}
|
||||
KeyCode::Left => self.choice_opt = DialogYesNoOption::Yes, // Move yes/no with arrows
|
||||
KeyCode::Right => self.choice_opt = DialogYesNoOption::No, // Move yes/no with arrows
|
||||
KeyCode::Char(ch) => self.input_txt.push(ch),
|
||||
KeyCode::Backspace => {
|
||||
let _ = self.input_txt.pop();
|
||||
|
||||
@@ -126,7 +126,7 @@ impl AuthActivity {
|
||||
let (width, height): (u16, u16) = match popup {
|
||||
PopupType::Alert(_, _) => (50, 10),
|
||||
PopupType::Help => (50, 70),
|
||||
PopupType::Input(_, _) => (40, 10),
|
||||
PopupType::SaveBookmark(_, _) => (40, 20),
|
||||
PopupType::YesNo(_, _, _) => (30, 10),
|
||||
};
|
||||
let popup_area: Rect = self.draw_popup_area(f.size(), width, height);
|
||||
@@ -137,12 +137,27 @@ impl AuthActivity {
|
||||
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);
|
||||
PopupType::SaveBookmark(txt, _) => {
|
||||
let popup_chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.margin(1)
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Length(3), // Input form
|
||||
Constraint::Length(2), // Yes/No
|
||||
]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(popup_area);
|
||||
let (input, yes_no): (Paragraph, Tabs) =
|
||||
self.draw_popup_save_bookmark(txt.clone());
|
||||
// Render parts
|
||||
f.render_widget(input, popup_chunks[0]);
|
||||
f.render_widget(yes_no, popup_chunks[1]);
|
||||
// Set cursor
|
||||
f.set_cursor(
|
||||
popup_area.x + self.input_txt.width() as u16 + 1,
|
||||
popup_area.y + 1,
|
||||
popup_chunks[0].x + self.input_txt.width() as u16 + 1,
|
||||
popup_chunks[0].y + 1,
|
||||
)
|
||||
}
|
||||
PopupType::YesNo(txt, _, _) => {
|
||||
@@ -414,10 +429,29 @@ impl AuthActivity {
|
||||
/// ### draw_popup_input
|
||||
///
|
||||
/// Draw input popup
|
||||
pub(super) fn draw_popup_input(&self, text: String) -> Paragraph {
|
||||
Paragraph::new(self.input_txt.as_ref())
|
||||
.style(Style::default().fg(Color::White))
|
||||
.block(Block::default().borders(Borders::ALL).title(text))
|
||||
pub(super) fn draw_popup_save_bookmark(&self, text: String) -> (Paragraph, Tabs) {
|
||||
let input: Paragraph = Paragraph::new(self.input_txt.as_ref())
|
||||
.style(Style::default().fg(Color::LightYellow))
|
||||
.block(Block::default().borders(Borders::ALL).title(text));
|
||||
let choices: Vec<Spans> = vec![Spans::from("Yes"), Spans::from("No")];
|
||||
let index: usize = match self.choice_opt {
|
||||
DialogYesNoOption::Yes => 0,
|
||||
DialogYesNoOption::No => 1,
|
||||
};
|
||||
let tabs: Tabs = Tabs::new(choices)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("Save password?"),
|
||||
)
|
||||
.select(index)
|
||||
.style(Style::default())
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.add_modifier(Modifier::BOLD)
|
||||
.fg(Color::LightRed),
|
||||
);
|
||||
(input, tabs)
|
||||
}
|
||||
|
||||
/// ### draw_popup_yesno
|
||||
|
||||
@@ -76,7 +76,7 @@ enum DialogYesNoOption {
|
||||
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
|
||||
SaveBookmark(String, OnInputSubmitCallback), // Input description; Callback for submit
|
||||
YesNo(String, DialogCallback, DialogCallback), // Yes, no callback
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user