mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Added fmt_file to setupt activity
This commit is contained in:
@@ -181,16 +181,28 @@ impl SetupActivity {
|
||||
KeyCode::Backspace => {
|
||||
// Pop character from selected input
|
||||
if let Some(config_cli) = self.config_cli.as_mut() {
|
||||
// NOTE: replace with match if other text fields are added
|
||||
if matches!(field, UserInterfaceInputField::TextEditor) {
|
||||
// Pop from text editor
|
||||
let mut input: String = String::from(
|
||||
config_cli.get_text_editor().as_path().to_string_lossy(),
|
||||
);
|
||||
input.pop();
|
||||
// Update text editor value
|
||||
config_cli.set_text_editor(PathBuf::from(input.as_str()));
|
||||
match field {
|
||||
UserInterfaceInputField::TextEditor => {
|
||||
// Pop from text editor
|
||||
let mut input: String = String::from(
|
||||
config_cli.get_text_editor().as_path().to_string_lossy(),
|
||||
);
|
||||
input.pop();
|
||||
// Update text editor value
|
||||
config_cli.set_text_editor(PathBuf::from(input.as_str()));
|
||||
}
|
||||
UserInterfaceInputField::FileFmt => {
|
||||
// Push char to current file fmt
|
||||
let mut file_fmt = config_cli.get_file_fmt().unwrap_or(String::new());
|
||||
// Pop from file fmt
|
||||
file_fmt.pop();
|
||||
// If len is 0, will become None
|
||||
config_cli.set_file_fmt(file_fmt);
|
||||
}
|
||||
_ => { /* Not a text field */ }
|
||||
}
|
||||
// NOTE: replace with match if other text fields are added
|
||||
if matches!(field, UserInterfaceInputField::TextEditor) {}
|
||||
}
|
||||
}
|
||||
KeyCode::Left => {
|
||||
@@ -270,6 +282,7 @@ impl SetupActivity {
|
||||
KeyCode::Up => {
|
||||
// Change selected field
|
||||
self.tab = SetupTab::UserInterface(match field {
|
||||
UserInterfaceInputField::FileFmt => UserInterfaceInputField::GroupDirs,
|
||||
UserInterfaceInputField::GroupDirs => {
|
||||
UserInterfaceInputField::ShowHiddenFiles
|
||||
}
|
||||
@@ -279,7 +292,7 @@ impl SetupActivity {
|
||||
UserInterfaceInputField::DefaultProtocol => {
|
||||
UserInterfaceInputField::TextEditor
|
||||
}
|
||||
UserInterfaceInputField::TextEditor => UserInterfaceInputField::GroupDirs, // Wrap
|
||||
UserInterfaceInputField::TextEditor => UserInterfaceInputField::FileFmt, // Wrap
|
||||
});
|
||||
}
|
||||
KeyCode::Down => {
|
||||
@@ -294,7 +307,8 @@ impl SetupActivity {
|
||||
UserInterfaceInputField::ShowHiddenFiles => {
|
||||
UserInterfaceInputField::GroupDirs
|
||||
}
|
||||
UserInterfaceInputField::GroupDirs => UserInterfaceInputField::TextEditor, // Wrap
|
||||
UserInterfaceInputField::GroupDirs => UserInterfaceInputField::FileFmt,
|
||||
UserInterfaceInputField::FileFmt => UserInterfaceInputField::TextEditor, // Wrap
|
||||
});
|
||||
}
|
||||
KeyCode::Char(ch) => {
|
||||
@@ -328,14 +342,24 @@ impl SetupActivity {
|
||||
// Push character to input field
|
||||
if let Some(config_cli) = self.config_cli.as_mut() {
|
||||
// NOTE: change to match if other fields are added
|
||||
if matches!(field, UserInterfaceInputField::TextEditor) {
|
||||
// Get current text editor and push character
|
||||
let mut input: String = String::from(
|
||||
config_cli.get_text_editor().as_path().to_string_lossy(),
|
||||
);
|
||||
input.push(ch);
|
||||
// Update text editor value
|
||||
config_cli.set_text_editor(PathBuf::from(input.as_str()));
|
||||
match field {
|
||||
UserInterfaceInputField::TextEditor => {
|
||||
// Get current text editor and push character
|
||||
let mut input: String = String::from(
|
||||
config_cli.get_text_editor().as_path().to_string_lossy(),
|
||||
);
|
||||
input.push(ch);
|
||||
// Update text editor value
|
||||
config_cli.set_text_editor(PathBuf::from(input.as_str()));
|
||||
}
|
||||
UserInterfaceInputField::FileFmt => {
|
||||
// Push char to current file fmt
|
||||
let mut file_fmt = config_cli.get_file_fmt().unwrap_or(String::new());
|
||||
file_fmt.push(ch);
|
||||
// update value
|
||||
config_cli.set_file_fmt(file_fmt);
|
||||
}
|
||||
_ => { /* Not a text field */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ impl SetupActivity {
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(1),
|
||||
]
|
||||
.as_ref(),
|
||||
@@ -107,15 +108,28 @@ impl SetupActivity {
|
||||
if let Some(tab) = self.draw_default_group_dirs_tab() {
|
||||
f.render_widget(tab, ui_cfg_chunks[3]);
|
||||
}
|
||||
if let Some(tab) = self.draw_file_fmt_input() {
|
||||
f.render_widget(tab, ui_cfg_chunks[4]);
|
||||
}
|
||||
// Set cursor
|
||||
if let Some(cli) = &self.config_cli {
|
||||
if matches!(form_field, UserInterfaceInputField::TextEditor) {
|
||||
let editor_text: String =
|
||||
String::from(cli.get_text_editor().as_path().to_string_lossy());
|
||||
f.set_cursor(
|
||||
ui_cfg_chunks[0].x + editor_text.width() as u16 + 1,
|
||||
ui_cfg_chunks[0].y + 1,
|
||||
)
|
||||
match form_field {
|
||||
UserInterfaceInputField::TextEditor => {
|
||||
let editor_text: String =
|
||||
String::from(cli.get_text_editor().as_path().to_string_lossy());
|
||||
f.set_cursor(
|
||||
ui_cfg_chunks[0].x + editor_text.width() as u16 + 1,
|
||||
ui_cfg_chunks[0].y + 1,
|
||||
);
|
||||
}
|
||||
UserInterfaceInputField::FileFmt => {
|
||||
let file_fmt: String = cli.get_file_fmt().unwrap_or(String::new());
|
||||
f.set_cursor(
|
||||
ui_cfg_chunks[4].x + file_fmt.width() as u16 + 1,
|
||||
ui_cfg_chunks[4].y + 1,
|
||||
);
|
||||
}
|
||||
_ => { /* Not a text field */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -392,6 +406,31 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### draw_file_fmt_input
|
||||
///
|
||||
/// Draw input text field for file fmt
|
||||
fn draw_file_fmt_input(&self) -> Option<Paragraph> {
|
||||
match &self.config_cli {
|
||||
Some(cli) => Some(
|
||||
Paragraph::new(cli.get_file_fmt().unwrap_or(String::new()))
|
||||
.style(Style::default().fg(match &self.tab {
|
||||
SetupTab::SshConfig => Color::White,
|
||||
SetupTab::UserInterface(field) => match field {
|
||||
UserInterfaceInputField::FileFmt => Color::LightCyan,
|
||||
_ => Color::White,
|
||||
},
|
||||
}))
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.title("File formatter syntax"),
|
||||
),
|
||||
),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// ### draw_ssh_keys_list
|
||||
///
|
||||
/// Draw ssh keys list
|
||||
|
||||
@@ -55,6 +55,7 @@ enum UserInterfaceInputField {
|
||||
TextEditor,
|
||||
ShowHiddenFiles,
|
||||
GroupDirs,
|
||||
FileFmt,
|
||||
}
|
||||
|
||||
/// ### SetupTab
|
||||
|
||||
Reference in New Issue
Block a user