mirror of
https://github.com/veeso/termscp.git
synced 2026-04-05 09:41:53 -07:00
Reuse mounts
This commit is contained in:
@@ -36,10 +36,10 @@ pub use ssh_keys::*;
|
||||
pub use theme::*;
|
||||
// Ext
|
||||
use tui_realm_stdlib::{
|
||||
List, ListPropsBuilder, Paragraph, ParagraphPropsBuilder, Radio, RadioPropsBuilder, Span,
|
||||
SpanPropsBuilder,
|
||||
Input, InputPropsBuilder, List, ListPropsBuilder, Paragraph, ParagraphPropsBuilder, Radio,
|
||||
RadioPropsBuilder, Span, SpanPropsBuilder,
|
||||
};
|
||||
use tuirealm::props::{Alignment, PropsBuilder, TableBuilder, TextSpan};
|
||||
use tuirealm::props::{Alignment, InputType, PropsBuilder, TableBuilder, TextSpan};
|
||||
use tuirealm::tui::{
|
||||
style::Color,
|
||||
widgets::{BorderType, Borders},
|
||||
@@ -74,21 +74,7 @@ impl SetupActivity {
|
||||
///
|
||||
/// Mount error box
|
||||
pub(super) fn mount_error(&mut self, text: &str) {
|
||||
// Mount
|
||||
self.view.mount(
|
||||
super::COMPONENT_TEXT_ERROR,
|
||||
Box::new(Paragraph::new(
|
||||
ParagraphPropsBuilder::default()
|
||||
.with_foreground(Color::Red)
|
||||
.bold()
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::Red)
|
||||
.with_texts(vec![TextSpan::from(text)])
|
||||
.with_text_alignment(Alignment::Center)
|
||||
.build(),
|
||||
)),
|
||||
);
|
||||
// Give focus to error
|
||||
self.view.active(super::COMPONENT_TEXT_ERROR);
|
||||
self.mount_text_dialog(super::COMPONENT_TEXT_ERROR, text, Color::Red);
|
||||
}
|
||||
|
||||
/// ### umount_error
|
||||
@@ -102,28 +88,13 @@ impl SetupActivity {
|
||||
///
|
||||
/// Mount quit popup
|
||||
pub(super) fn mount_quit(&mut self) {
|
||||
self.view.mount(
|
||||
self.mount_radio_dialog(
|
||||
super::COMPONENT_RADIO_QUIT,
|
||||
Box::new(Radio::new(
|
||||
RadioPropsBuilder::default()
|
||||
.with_color(Color::LightRed)
|
||||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightRed)
|
||||
.with_title(
|
||||
"There are unsaved changes! Save changes before leaving?",
|
||||
Alignment::Center,
|
||||
)
|
||||
.with_options(&[
|
||||
String::from("Save"),
|
||||
String::from("Don't save"),
|
||||
String::from("Cancel"),
|
||||
])
|
||||
.rewind(true)
|
||||
.build(),
|
||||
)),
|
||||
"There are unsaved changes! Save changes before leaving?",
|
||||
&["Save", "Don't save", "Cancel"],
|
||||
0,
|
||||
Color::LightRed,
|
||||
);
|
||||
// Active
|
||||
self.view.active(super::COMPONENT_RADIO_QUIT);
|
||||
}
|
||||
|
||||
/// ### umount_quit
|
||||
@@ -137,21 +108,13 @@ impl SetupActivity {
|
||||
///
|
||||
/// Mount save popup
|
||||
pub(super) fn mount_save_popup(&mut self) {
|
||||
self.view.mount(
|
||||
self.mount_radio_dialog(
|
||||
super::COMPONENT_RADIO_SAVE,
|
||||
Box::new(Radio::new(
|
||||
RadioPropsBuilder::default()
|
||||
.with_color(Color::LightYellow)
|
||||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightYellow)
|
||||
.with_title("Save changes?", Alignment::Center)
|
||||
.with_options(&[String::from("Yes"), String::from("No")])
|
||||
.rewind(true)
|
||||
.build(),
|
||||
)),
|
||||
"Save changes?",
|
||||
&["Yes", "No"],
|
||||
0,
|
||||
Color::LightYellow,
|
||||
);
|
||||
// Active
|
||||
self.view.active(super::COMPONENT_RADIO_SAVE);
|
||||
}
|
||||
|
||||
/// ### umount_quit
|
||||
@@ -253,4 +216,95 @@ impl SetupActivity {
|
||||
pub(super) fn umount_help(&mut self) {
|
||||
self.view.umount(super::COMPONENT_TEXT_HELP);
|
||||
}
|
||||
|
||||
// -- mount helpers
|
||||
|
||||
fn mount_text_dialog(&mut self, id: &str, text: &str, color: Color) {
|
||||
// Mount
|
||||
self.view.mount(
|
||||
id,
|
||||
Box::new(Paragraph::new(
|
||||
ParagraphPropsBuilder::default()
|
||||
.with_borders(Borders::ALL, BorderType::Thick, color)
|
||||
.with_foreground(color)
|
||||
.bold()
|
||||
.with_text_alignment(Alignment::Center)
|
||||
.with_texts(vec![TextSpan::from(text)])
|
||||
.build(),
|
||||
)),
|
||||
);
|
||||
// Give focus to error
|
||||
self.view.active(id);
|
||||
}
|
||||
|
||||
fn mount_radio_dialog(
|
||||
&mut self,
|
||||
id: &str,
|
||||
text: &str,
|
||||
opts: &[&str],
|
||||
default: usize,
|
||||
color: Color,
|
||||
) {
|
||||
self.view.mount(
|
||||
id,
|
||||
Box::new(Radio::new(
|
||||
RadioPropsBuilder::default()
|
||||
.with_color(color)
|
||||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, color)
|
||||
.with_title(text, Alignment::Center)
|
||||
.with_options(opts)
|
||||
.with_value(default)
|
||||
.rewind(true)
|
||||
.build(),
|
||||
)),
|
||||
);
|
||||
// Active
|
||||
self.view.active(id);
|
||||
}
|
||||
|
||||
fn mount_radio(&mut self, id: &str, text: &str, opts: &[&str], default: usize, color: Color) {
|
||||
self.view.mount(
|
||||
id,
|
||||
Box::new(Radio::new(
|
||||
RadioPropsBuilder::default()
|
||||
.with_color(color)
|
||||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, color)
|
||||
.with_title(text, Alignment::Left)
|
||||
.with_options(opts)
|
||||
.with_value(default)
|
||||
.rewind(true)
|
||||
.build(),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
fn mount_input(&mut self, id: &str, label: &str, fg: Color, typ: InputType) {
|
||||
self.mount_input_ex(id, label, fg, typ, None, None);
|
||||
}
|
||||
|
||||
fn mount_input_ex(
|
||||
&mut self,
|
||||
id: &str,
|
||||
label: &str,
|
||||
fg: Color,
|
||||
typ: InputType,
|
||||
len: Option<usize>,
|
||||
value: Option<String>,
|
||||
) {
|
||||
let mut props = InputPropsBuilder::default();
|
||||
props
|
||||
.with_foreground(fg)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, fg)
|
||||
.with_label(label, Alignment::Left)
|
||||
.with_input(typ);
|
||||
if let Some(len) = len {
|
||||
props.with_input_len(len);
|
||||
}
|
||||
if let Some(value) = value {
|
||||
props.with_value(value);
|
||||
}
|
||||
self.view.mount(id, Box::new(Input::new(props.build())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,14 +27,14 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
// Locals
|
||||
use super::{Context, SetupActivity};
|
||||
use super::{Context, InputType, SetupActivity};
|
||||
use crate::filetransfer::FileTransferProtocol;
|
||||
use crate::fs::explorer::GroupDirs;
|
||||
use crate::ui::components::bytes::{Bytes, BytesPropsBuilder};
|
||||
use crate::utils::ui::draw_area_in;
|
||||
// Ext
|
||||
use std::path::PathBuf;
|
||||
use tui_realm_stdlib::{Input, InputPropsBuilder, Radio, RadioPropsBuilder};
|
||||
use tui_realm_stdlib::{InputPropsBuilder, RadioPropsBuilder};
|
||||
use tuirealm::tui::{
|
||||
layout::{Constraint, Direction, Layout},
|
||||
style::Color,
|
||||
@@ -60,118 +60,66 @@ impl SetupActivity {
|
||||
// Footer
|
||||
self.mount_footer();
|
||||
// Input fields
|
||||
self.view.mount(
|
||||
self.mount_input(
|
||||
super::COMPONENT_INPUT_TEXT_EDITOR,
|
||||
Box::new(Input::new(
|
||||
InputPropsBuilder::default()
|
||||
.with_foreground(Color::LightGreen)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightGreen)
|
||||
.with_label("Text editor", Alignment::Left)
|
||||
.build(),
|
||||
)),
|
||||
"Text editor",
|
||||
Color::LightGreen,
|
||||
InputType::Text,
|
||||
);
|
||||
self.view.active(super::COMPONENT_INPUT_TEXT_EDITOR); // <-- Focus
|
||||
self.view.mount(
|
||||
self.mount_radio(
|
||||
super::COMPONENT_RADIO_DEFAULT_PROTOCOL,
|
||||
Box::new(Radio::new(
|
||||
RadioPropsBuilder::default()
|
||||
.with_color(Color::LightCyan)
|
||||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightCyan)
|
||||
.with_title("Default file transfer protocol", Alignment::Left)
|
||||
.with_options(&["SFTP", "SCP", "FTP", "FTPS", "AWS S3"])
|
||||
.rewind(true)
|
||||
.build(),
|
||||
)),
|
||||
"Default protocol",
|
||||
&["SFTP", "SCP", "FTP", "FTPS", "AWS S3"],
|
||||
0,
|
||||
Color::LightCyan,
|
||||
);
|
||||
self.view.mount(
|
||||
self.mount_radio(
|
||||
super::COMPONENT_RADIO_HIDDEN_FILES,
|
||||
Box::new(Radio::new(
|
||||
RadioPropsBuilder::default()
|
||||
.with_color(Color::LightRed)
|
||||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightRed)
|
||||
.with_title("Show hidden files (by default)?", Alignment::Left)
|
||||
.with_options(&[String::from("Yes"), String::from("No")])
|
||||
.rewind(true)
|
||||
.build(),
|
||||
)),
|
||||
"Show hidden files (by default)?",
|
||||
&["Yes", "No"],
|
||||
0,
|
||||
Color::LightRed,
|
||||
);
|
||||
self.view.mount(
|
||||
self.mount_radio(
|
||||
super::COMPONENT_RADIO_UPDATES,
|
||||
Box::new(Radio::new(
|
||||
RadioPropsBuilder::default()
|
||||
.with_color(Color::LightYellow)
|
||||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightYellow)
|
||||
.with_title("Check for updates?", Alignment::Left)
|
||||
.with_options(&[String::from("Yes"), String::from("No")])
|
||||
.rewind(true)
|
||||
.build(),
|
||||
)),
|
||||
"Check for updates?",
|
||||
&["Yes", "No"],
|
||||
0,
|
||||
Color::LightYellow,
|
||||
);
|
||||
self.view.mount(
|
||||
self.mount_radio(
|
||||
super::COMPONENT_RADIO_PROMPT_ON_FILE_REPLACE,
|
||||
Box::new(Radio::new(
|
||||
RadioPropsBuilder::default()
|
||||
.with_color(Color::LightCyan)
|
||||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightCyan)
|
||||
.with_title("Prompt when replacing existing files?", Alignment::Left)
|
||||
.with_options(&[String::from("Yes"), String::from("No")])
|
||||
.rewind(true)
|
||||
.build(),
|
||||
)),
|
||||
"Prompt when replacing existing files?",
|
||||
&["Yes", "No"],
|
||||
0,
|
||||
Color::LightCyan,
|
||||
);
|
||||
self.view.mount(
|
||||
self.mount_radio(
|
||||
super::COMPONENT_RADIO_GROUP_DIRS,
|
||||
Box::new(Radio::new(
|
||||
RadioPropsBuilder::default()
|
||||
.with_color(Color::LightMagenta)
|
||||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightMagenta)
|
||||
.with_title("Group directories", Alignment::Left)
|
||||
.with_options(&[
|
||||
String::from("Display first"),
|
||||
String::from("Display Last"),
|
||||
String::from("No"),
|
||||
])
|
||||
.rewind(true)
|
||||
.build(),
|
||||
)),
|
||||
"Group directories",
|
||||
&["Display first", "Display last", "No"],
|
||||
0,
|
||||
Color::LightMagenta,
|
||||
);
|
||||
self.view.mount(
|
||||
self.mount_input(
|
||||
super::COMPONENT_INPUT_LOCAL_FILE_FMT,
|
||||
Box::new(Input::new(
|
||||
InputPropsBuilder::default()
|
||||
.with_foreground(Color::LightGreen)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightGreen)
|
||||
.with_label("File formatter syntax (local)", Alignment::Left)
|
||||
.build(),
|
||||
)),
|
||||
"File formatter syntax (local)",
|
||||
Color::LightGreen,
|
||||
InputType::Text,
|
||||
);
|
||||
self.view.mount(
|
||||
self.mount_input(
|
||||
super::COMPONENT_INPUT_REMOTE_FILE_FMT,
|
||||
Box::new(Input::new(
|
||||
InputPropsBuilder::default()
|
||||
.with_foreground(Color::LightCyan)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightCyan)
|
||||
.with_label("File formatter syntax (remote)", Alignment::Left)
|
||||
.build(),
|
||||
)),
|
||||
"File formatter syntax (remote)",
|
||||
Color::LightCyan,
|
||||
InputType::Text,
|
||||
);
|
||||
self.view.mount(
|
||||
self.mount_radio(
|
||||
super::COMPONENT_RADIO_NOTIFICATIONS_ENABLED,
|
||||
Box::new(Radio::new(
|
||||
RadioPropsBuilder::default()
|
||||
.with_color(Color::LightRed)
|
||||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightRed)
|
||||
.with_title("Enable notifications?", Alignment::Left)
|
||||
.with_options(&[String::from("Yes"), String::from("No")])
|
||||
.rewind(true)
|
||||
.build(),
|
||||
)),
|
||||
"Enable notifications?",
|
||||
&["Yes", "No"],
|
||||
0,
|
||||
Color::LightRed,
|
||||
);
|
||||
self.view.mount(
|
||||
super::COMPONENT_INPUT_NOTIFICATIONS_THRESHOLD,
|
||||
|
||||
@@ -31,7 +31,7 @@ use super::{Context, SetupActivity};
|
||||
use crate::ui::components::bookmark_list::{BookmarkList, BookmarkListPropsBuilder};
|
||||
use crate::utils::ui::draw_area_in;
|
||||
// Ext
|
||||
use tui_realm_stdlib::{Input, InputPropsBuilder, Radio, RadioPropsBuilder};
|
||||
use tui_realm_stdlib::{Input, InputPropsBuilder};
|
||||
use tuirealm::tui::{
|
||||
layout::{Constraint, Direction, Layout},
|
||||
style::Color,
|
||||
@@ -169,22 +169,13 @@ impl SetupActivity {
|
||||
///
|
||||
/// Mount delete ssh key component
|
||||
pub(crate) fn mount_del_ssh_key(&mut self) {
|
||||
self.view.mount(
|
||||
self.mount_radio_dialog(
|
||||
super::COMPONENT_RADIO_DEL_SSH_KEY,
|
||||
Box::new(Radio::new(
|
||||
RadioPropsBuilder::default()
|
||||
.with_color(Color::LightRed)
|
||||
.with_inverted_color(Color::Black)
|
||||
.with_borders(Borders::ALL, BorderType::Rounded, Color::LightRed)
|
||||
.with_title("Delete key?", Alignment::Center)
|
||||
.with_options(&[String::from("Yes"), String::from("No")])
|
||||
.with_value(1) // Default: No
|
||||
.rewind(true)
|
||||
.build(),
|
||||
)),
|
||||
"Delete key?",
|
||||
&["Yes", "No"],
|
||||
1,
|
||||
Color::LightRed,
|
||||
);
|
||||
// Active
|
||||
self.view.active(super::COMPONENT_RADIO_DEL_SSH_KEY);
|
||||
}
|
||||
|
||||
/// ### umount_del_ssh_key
|
||||
|
||||
Reference in New Issue
Block a user