Added fmt_file to setupt activity

This commit is contained in:
veeso
2021-01-23 16:22:32 +01:00
parent c16a2f6441
commit 7a9ee697ff
3 changed files with 90 additions and 26 deletions

View File

@@ -181,16 +181,28 @@ impl SetupActivity {
KeyCode::Backspace => { KeyCode::Backspace => {
// Pop character from selected input // Pop character from selected input
if let Some(config_cli) = self.config_cli.as_mut() { if let Some(config_cli) = self.config_cli.as_mut() {
// NOTE: replace with match if other text fields are added match field {
if matches!(field, UserInterfaceInputField::TextEditor) { UserInterfaceInputField::TextEditor => {
// Pop from text editor // Pop from text editor
let mut input: String = String::from( let mut input: String = String::from(
config_cli.get_text_editor().as_path().to_string_lossy(), config_cli.get_text_editor().as_path().to_string_lossy(),
); );
input.pop(); input.pop();
// Update text editor value // Update text editor value
config_cli.set_text_editor(PathBuf::from(input.as_str())); 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 => { KeyCode::Left => {
@@ -270,6 +282,7 @@ impl SetupActivity {
KeyCode::Up => { KeyCode::Up => {
// Change selected field // Change selected field
self.tab = SetupTab::UserInterface(match field { self.tab = SetupTab::UserInterface(match field {
UserInterfaceInputField::FileFmt => UserInterfaceInputField::GroupDirs,
UserInterfaceInputField::GroupDirs => { UserInterfaceInputField::GroupDirs => {
UserInterfaceInputField::ShowHiddenFiles UserInterfaceInputField::ShowHiddenFiles
} }
@@ -279,7 +292,7 @@ impl SetupActivity {
UserInterfaceInputField::DefaultProtocol => { UserInterfaceInputField::DefaultProtocol => {
UserInterfaceInputField::TextEditor UserInterfaceInputField::TextEditor
} }
UserInterfaceInputField::TextEditor => UserInterfaceInputField::GroupDirs, // Wrap UserInterfaceInputField::TextEditor => UserInterfaceInputField::FileFmt, // Wrap
}); });
} }
KeyCode::Down => { KeyCode::Down => {
@@ -294,7 +307,8 @@ impl SetupActivity {
UserInterfaceInputField::ShowHiddenFiles => { UserInterfaceInputField::ShowHiddenFiles => {
UserInterfaceInputField::GroupDirs UserInterfaceInputField::GroupDirs
} }
UserInterfaceInputField::GroupDirs => UserInterfaceInputField::TextEditor, // Wrap UserInterfaceInputField::GroupDirs => UserInterfaceInputField::FileFmt,
UserInterfaceInputField::FileFmt => UserInterfaceInputField::TextEditor, // Wrap
}); });
} }
KeyCode::Char(ch) => { KeyCode::Char(ch) => {
@@ -328,14 +342,24 @@ impl SetupActivity {
// Push character to input field // Push character to input field
if let Some(config_cli) = self.config_cli.as_mut() { if let Some(config_cli) = self.config_cli.as_mut() {
// NOTE: change to match if other fields are added // NOTE: change to match if other fields are added
if matches!(field, UserInterfaceInputField::TextEditor) { match field {
// Get current text editor and push character UserInterfaceInputField::TextEditor => {
let mut input: String = String::from( // Get current text editor and push character
config_cli.get_text_editor().as_path().to_string_lossy(), let mut input: String = String::from(
); config_cli.get_text_editor().as_path().to_string_lossy(),
input.push(ch); );
// Update text editor value input.push(ch);
config_cli.set_text_editor(PathBuf::from(input.as_str())); // 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 */ }
} }
} }
} }

View File

@@ -89,6 +89,7 @@ impl SetupActivity {
Constraint::Length(3), Constraint::Length(3),
Constraint::Length(3), Constraint::Length(3),
Constraint::Length(3), Constraint::Length(3),
Constraint::Length(3),
Constraint::Length(1), Constraint::Length(1),
] ]
.as_ref(), .as_ref(),
@@ -107,15 +108,28 @@ impl SetupActivity {
if let Some(tab) = self.draw_default_group_dirs_tab() { if let Some(tab) = self.draw_default_group_dirs_tab() {
f.render_widget(tab, ui_cfg_chunks[3]); 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 // Set cursor
if let Some(cli) = &self.config_cli { if let Some(cli) = &self.config_cli {
if matches!(form_field, UserInterfaceInputField::TextEditor) { match form_field {
let editor_text: String = UserInterfaceInputField::TextEditor => {
String::from(cli.get_text_editor().as_path().to_string_lossy()); let editor_text: String =
f.set_cursor( String::from(cli.get_text_editor().as_path().to_string_lossy());
ui_cfg_chunks[0].x + editor_text.width() as u16 + 1, f.set_cursor(
ui_cfg_chunks[0].y + 1, 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
/// ///
/// Draw ssh keys list /// Draw ssh keys list

View File

@@ -55,6 +55,7 @@ enum UserInterfaceInputField {
TextEditor, TextEditor,
ShowHiddenFiles, ShowHiddenFiles,
GroupDirs, GroupDirs,
FileFmt,
} }
/// ### SetupTab /// ### SetupTab