mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
show_hidden_files and group_dirs in termscp configuration; instantiate FileExplorer based on current configuration in FileTransferActivity
This commit is contained in:
@@ -53,7 +53,7 @@ impl AuthActivity {
|
||||
/// ### handle_input_event_mode_form
|
||||
///
|
||||
/// Handler for input event when in form mode
|
||||
pub(super) fn handle_input_event_mode_form(&mut self, ev: &InputEvent) {
|
||||
fn handle_input_event_mode_form(&mut self, ev: &InputEvent) {
|
||||
match self.input_form {
|
||||
InputForm::AuthCredentials => self.handle_input_event_mode_form_auth(ev),
|
||||
InputForm::Bookmarks => self.handle_input_event_mode_form_bookmarks(ev),
|
||||
@@ -64,7 +64,7 @@ impl AuthActivity {
|
||||
/// ### handle_input_event_mode_form_auth
|
||||
///
|
||||
/// Handle input event when input mode is Form and Tab is Auth
|
||||
pub(super) fn handle_input_event_mode_form_auth(&mut self, ev: &InputEvent) {
|
||||
fn handle_input_event_mode_form_auth(&mut self, ev: &InputEvent) {
|
||||
if let InputEvent::Key(key) = ev {
|
||||
match key.code {
|
||||
KeyCode::Esc => {
|
||||
@@ -220,7 +220,7 @@ impl AuthActivity {
|
||||
/// ### handle_input_event_mode_form_bookmarks
|
||||
///
|
||||
/// Handle input event when input mode is Form and Tab is Bookmarks
|
||||
pub(super) fn handle_input_event_mode_form_bookmarks(&mut self, ev: &InputEvent) {
|
||||
fn handle_input_event_mode_form_bookmarks(&mut self, ev: &InputEvent) {
|
||||
if let InputEvent::Key(key) = ev {
|
||||
match key.code {
|
||||
KeyCode::Esc => {
|
||||
@@ -304,7 +304,7 @@ impl AuthActivity {
|
||||
/// ### handle_input_event_mode_form_recents
|
||||
///
|
||||
/// Handle input event when input mode is Form and Tab is Recents
|
||||
pub(super) fn handle_input_event_mode_form_recents(&mut self, ev: &InputEvent) {
|
||||
fn handle_input_event_mode_form_recents(&mut self, ev: &InputEvent) {
|
||||
if let InputEvent::Key(key) = ev {
|
||||
match key.code {
|
||||
KeyCode::Esc => {
|
||||
@@ -388,7 +388,7 @@ impl AuthActivity {
|
||||
/// ### handle_input_event_mode_text
|
||||
///
|
||||
/// Handler for input event when in popup mode
|
||||
pub(super) fn handle_input_event_mode_popup(&mut self, ev: &InputEvent, ptype: PopupType) {
|
||||
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),
|
||||
@@ -402,7 +402,7 @@ impl AuthActivity {
|
||||
/// ### handle_input_event_mode_popup_alert
|
||||
///
|
||||
/// Handle input event when the input mode is popup, and popup type is alert
|
||||
pub(super) fn handle_input_event_mode_popup_alert(&mut self, ev: &InputEvent) {
|
||||
fn handle_input_event_mode_popup_alert(&mut self, ev: &InputEvent) {
|
||||
// Only enter should be allowed here
|
||||
if let InputEvent::Key(key) = ev {
|
||||
if matches!(key.code, KeyCode::Esc | KeyCode::Enter) {
|
||||
@@ -414,7 +414,7 @@ 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) {
|
||||
fn handle_input_event_mode_popup_help(&mut self, ev: &InputEvent) {
|
||||
// If enter, close popup
|
||||
if let InputEvent::Key(key) = ev {
|
||||
if matches!(key.code, KeyCode::Esc | KeyCode::Enter) {
|
||||
@@ -427,7 +427,7 @@ impl AuthActivity {
|
||||
/// ### handle_input_event_mode_popup_save_bookmark
|
||||
///
|
||||
/// Input event handler for SaveBookmark popup
|
||||
pub(super) fn handle_input_event_mode_popup_save_bookmark(&mut self, ev: &InputEvent) {
|
||||
fn handle_input_event_mode_popup_save_bookmark(&mut self, ev: &InputEvent) {
|
||||
// If enter, close popup, otherwise push chars to input
|
||||
if let InputEvent::Key(key) = ev {
|
||||
match key.code {
|
||||
@@ -466,7 +466,7 @@ impl AuthActivity {
|
||||
/// ### handle_input_event_mode_popup_yesno
|
||||
///
|
||||
/// Input event handler for popup alert
|
||||
pub(super) fn handle_input_event_mode_popup_yesno(
|
||||
fn handle_input_event_mode_popup_yesno(
|
||||
&mut self,
|
||||
ev: &InputEvent,
|
||||
yes_cb: DialogCallback,
|
||||
|
||||
@@ -318,7 +318,7 @@ impl AuthActivity {
|
||||
/// ### draw_local_explorer
|
||||
///
|
||||
/// Draw local explorer list
|
||||
pub(super) fn draw_bookmarks_tab(&self) -> Option<List> {
|
||||
fn draw_bookmarks_tab(&self) -> Option<List> {
|
||||
self.bookmarks_client.as_ref()?;
|
||||
let hosts: Vec<ListItem> = self
|
||||
.bookmarks_client
|
||||
@@ -366,7 +366,7 @@ impl AuthActivity {
|
||||
/// ### draw_local_explorer
|
||||
///
|
||||
/// Draw local explorer list
|
||||
pub(super) fn draw_recents_tab(&self) -> Option<List> {
|
||||
fn draw_recents_tab(&self) -> Option<List> {
|
||||
self.bookmarks_client.as_ref()?;
|
||||
let hosts: Vec<ListItem> = self
|
||||
.bookmarks_client
|
||||
@@ -463,7 +463,7 @@ impl AuthActivity {
|
||||
/// ### draw_popup_input
|
||||
///
|
||||
/// Draw input popup
|
||||
pub(super) fn draw_popup_save_bookmark(&self) -> (Paragraph, Tabs) {
|
||||
fn draw_popup_save_bookmark(&self) -> (Paragraph, Tabs) {
|
||||
let input: Paragraph = Paragraph::new(self.input_txt.as_ref())
|
||||
.style(Style::default().fg(Color::White))
|
||||
.block(
|
||||
@@ -497,7 +497,7 @@ impl AuthActivity {
|
||||
/// ### draw_popup_yesno
|
||||
///
|
||||
/// Draw yes/no select popup
|
||||
pub(super) fn draw_popup_yesno(&self, text: String) -> Tabs {
|
||||
fn draw_popup_yesno(&self, text: String) -> Tabs {
|
||||
let choices: Vec<Spans> = vec![Spans::from("Yes"), Spans::from("No")];
|
||||
let index: usize = match self.choice_opt {
|
||||
DialogYesNoOption::Yes => 0,
|
||||
@@ -522,7 +522,7 @@ impl AuthActivity {
|
||||
/// ### draw_popup_help
|
||||
///
|
||||
/// Draw authentication page help popup
|
||||
pub(super) fn draw_popup_help(&self) -> List {
|
||||
fn draw_popup_help(&self) -> List {
|
||||
// Write header
|
||||
let cmds: Vec<ListItem> = vec![
|
||||
ListItem::new(Spans::from(vec![
|
||||
|
||||
@@ -130,11 +130,19 @@ impl FileTransferActivity {
|
||||
///
|
||||
/// Build explorer reading configuration from `ConfigClient`
|
||||
pub(super) fn build_explorer(cli: Option<&ConfigClient>) -> FileExplorer {
|
||||
FileExplorerBuilder::new()
|
||||
.with_file_sorting(FileSorting::ByName)
|
||||
.with_group_dirs(Some(GroupDirs::First))
|
||||
.with_stack_size(16)
|
||||
.build()
|
||||
match &cli {
|
||||
Some(cli) => FileExplorerBuilder::new() // Build according to current configuration
|
||||
.with_file_sorting(FileSorting::ByName)
|
||||
.with_group_dirs(cli.get_group_dirs())
|
||||
.with_hidden_files(cli.get_show_hidden_files())
|
||||
.with_stack_size(16)
|
||||
.build(),
|
||||
None => FileExplorerBuilder::new() // Build default
|
||||
.with_file_sorting(FileSorting::ByName)
|
||||
.with_group_dirs(Some(GroupDirs::First))
|
||||
.with_stack_size(16)
|
||||
.build(),
|
||||
}
|
||||
}
|
||||
|
||||
/// ### setup_text_editor
|
||||
|
||||
@@ -30,6 +30,7 @@ use super::{
|
||||
UserInterfaceInputField, YesNoDialogOption,
|
||||
};
|
||||
use crate::filetransfer::FileTransferProtocol;
|
||||
use crate::fs::explorer::GroupDirs;
|
||||
// Ext
|
||||
use crossterm::event::{KeyCode, KeyModifiers};
|
||||
use std::path::PathBuf;
|
||||
@@ -195,59 +196,105 @@ impl SetupActivity {
|
||||
KeyCode::Left => {
|
||||
// Move left on fields which are tabs
|
||||
if let Some(config_cli) = self.config_cli.as_mut() {
|
||||
if matches!(field, UserInterfaceInputField::DefaultProtocol) {
|
||||
// Move left
|
||||
config_cli.set_default_protocol(
|
||||
match config_cli.get_default_protocol() {
|
||||
FileTransferProtocol::Ftp(secure) => match secure {
|
||||
true => FileTransferProtocol::Ftp(false),
|
||||
false => FileTransferProtocol::Scp,
|
||||
match field {
|
||||
UserInterfaceInputField::DefaultProtocol => {
|
||||
// Move left
|
||||
config_cli.set_default_protocol(
|
||||
match config_cli.get_default_protocol() {
|
||||
FileTransferProtocol::Ftp(secure) => match secure {
|
||||
true => FileTransferProtocol::Ftp(false),
|
||||
false => FileTransferProtocol::Scp,
|
||||
},
|
||||
FileTransferProtocol::Scp => FileTransferProtocol::Sftp,
|
||||
FileTransferProtocol::Sftp => {
|
||||
FileTransferProtocol::Ftp(true)
|
||||
} // Wrap
|
||||
},
|
||||
FileTransferProtocol::Scp => FileTransferProtocol::Sftp,
|
||||
FileTransferProtocol::Sftp => FileTransferProtocol::Ftp(true), // Wrap
|
||||
},
|
||||
);
|
||||
);
|
||||
}
|
||||
UserInterfaceInputField::GroupDirs => {
|
||||
// Move left
|
||||
config_cli.set_group_dirs(match config_cli.get_group_dirs() {
|
||||
None => Some(GroupDirs::Last),
|
||||
Some(val) => match val {
|
||||
GroupDirs::Last => Some(GroupDirs::First),
|
||||
GroupDirs::First => None,
|
||||
},
|
||||
});
|
||||
}
|
||||
UserInterfaceInputField::ShowHiddenFiles => {
|
||||
// Move left
|
||||
config_cli.set_show_hidden_files(true);
|
||||
}
|
||||
_ => { /* Not a tab field */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
KeyCode::Right => {
|
||||
// Move right on fields which are tabs
|
||||
if let Some(config_cli) = self.config_cli.as_mut() {
|
||||
if matches!(field, UserInterfaceInputField::DefaultProtocol) {
|
||||
// Move left
|
||||
config_cli.set_default_protocol(
|
||||
match config_cli.get_default_protocol() {
|
||||
FileTransferProtocol::Sftp => FileTransferProtocol::Scp,
|
||||
FileTransferProtocol::Scp => FileTransferProtocol::Ftp(false),
|
||||
FileTransferProtocol::Ftp(secure) => match secure {
|
||||
false => FileTransferProtocol::Ftp(true),
|
||||
true => FileTransferProtocol::Sftp, // Wrap
|
||||
match field {
|
||||
UserInterfaceInputField::DefaultProtocol => {
|
||||
// Move left
|
||||
config_cli.set_default_protocol(
|
||||
match config_cli.get_default_protocol() {
|
||||
FileTransferProtocol::Sftp => FileTransferProtocol::Scp,
|
||||
FileTransferProtocol::Scp => {
|
||||
FileTransferProtocol::Ftp(false)
|
||||
}
|
||||
FileTransferProtocol::Ftp(secure) => match secure {
|
||||
false => FileTransferProtocol::Ftp(true),
|
||||
true => FileTransferProtocol::Sftp, // Wrap
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
);
|
||||
}
|
||||
UserInterfaceInputField::GroupDirs => {
|
||||
// Move right
|
||||
config_cli.set_group_dirs(match config_cli.get_group_dirs() {
|
||||
Some(val) => match val {
|
||||
GroupDirs::First => Some(GroupDirs::Last),
|
||||
GroupDirs::Last => None,
|
||||
},
|
||||
None => Some(GroupDirs::First),
|
||||
});
|
||||
}
|
||||
UserInterfaceInputField::ShowHiddenFiles => {
|
||||
// Move right
|
||||
config_cli.set_show_hidden_files(false);
|
||||
}
|
||||
_ => { /* Not a tab field */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
KeyCode::Up => {
|
||||
// Change selected field
|
||||
self.tab = SetupTab::UserInterface(match field {
|
||||
UserInterfaceInputField::TextEditor => {
|
||||
UserInterfaceInputField::GroupDirs => {
|
||||
UserInterfaceInputField::ShowHiddenFiles
|
||||
}
|
||||
UserInterfaceInputField::ShowHiddenFiles => {
|
||||
UserInterfaceInputField::DefaultProtocol
|
||||
}
|
||||
UserInterfaceInputField::DefaultProtocol => {
|
||||
UserInterfaceInputField::TextEditor
|
||||
} // Wrap
|
||||
}
|
||||
UserInterfaceInputField::TextEditor => UserInterfaceInputField::GroupDirs, // Wrap
|
||||
});
|
||||
}
|
||||
KeyCode::Down => {
|
||||
// Change selected field
|
||||
self.tab = SetupTab::UserInterface(match field {
|
||||
UserInterfaceInputField::DefaultProtocol => {
|
||||
UserInterfaceInputField::TextEditor
|
||||
}
|
||||
UserInterfaceInputField::TextEditor => {
|
||||
UserInterfaceInputField::DefaultProtocol
|
||||
} // Wrap
|
||||
}
|
||||
UserInterfaceInputField::DefaultProtocol => {
|
||||
UserInterfaceInputField::ShowHiddenFiles
|
||||
}
|
||||
UserInterfaceInputField::ShowHiddenFiles => {
|
||||
UserInterfaceInputField::GroupDirs
|
||||
}
|
||||
UserInterfaceInputField::GroupDirs => UserInterfaceInputField::TextEditor, // Wrap
|
||||
});
|
||||
}
|
||||
KeyCode::Char(ch) => {
|
||||
@@ -450,7 +497,7 @@ impl SetupActivity {
|
||||
/// ### handle_input_event_mode_popup_yesno
|
||||
///
|
||||
/// Input event handler for popup alert
|
||||
pub(super) fn handle_input_event_mode_popup_yesno(
|
||||
fn handle_input_event_mode_popup_yesno(
|
||||
&mut self,
|
||||
ev: &InputEvent,
|
||||
yes_cb: OnChoiceCallback,
|
||||
|
||||
@@ -29,8 +29,9 @@ use super::{
|
||||
YesNoDialogOption,
|
||||
};
|
||||
use crate::filetransfer::FileTransferProtocol;
|
||||
use crate::fs::explorer::GroupDirs;
|
||||
use crate::utils::fmt::align_text_center;
|
||||
|
||||
// Ext
|
||||
use tui::{
|
||||
layout::{Constraint, Corner, Direction, Layout, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
@@ -84,6 +85,8 @@ impl SetupActivity {
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(
|
||||
[
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(3),
|
||||
Constraint::Length(1),
|
||||
@@ -98,6 +101,12 @@ impl SetupActivity {
|
||||
if let Some(tab) = self.draw_default_protocol_tab() {
|
||||
f.render_widget(tab, ui_cfg_chunks[1]);
|
||||
}
|
||||
if let Some(tab) = self.draw_hidden_files_tab() {
|
||||
f.render_widget(tab, ui_cfg_chunks[2]);
|
||||
}
|
||||
if let Some(tab) = self.draw_default_group_dirs_tab() {
|
||||
f.render_widget(tab, ui_cfg_chunks[3]);
|
||||
}
|
||||
// Set cursor
|
||||
if let Some(cli) = &self.config_cli {
|
||||
if matches!(form_field, UserInterfaceInputField::TextEditor) {
|
||||
@@ -217,6 +226,33 @@ impl SetupActivity {
|
||||
Paragraph::new(footer_text)
|
||||
}
|
||||
|
||||
/// ### draw_text_editor_input
|
||||
///
|
||||
/// Draw input text field for text editor parameter
|
||||
fn draw_text_editor_input(&self) -> Option<Paragraph> {
|
||||
match &self.config_cli {
|
||||
Some(cli) => Some(
|
||||
Paragraph::new(String::from(
|
||||
cli.get_text_editor().as_path().to_string_lossy(),
|
||||
))
|
||||
.style(Style::default().fg(match &self.tab {
|
||||
SetupTab::SshConfig => Color::White,
|
||||
SetupTab::UserInterface(field) => match field {
|
||||
UserInterfaceInputField::TextEditor => Color::LightGreen,
|
||||
_ => Color::White,
|
||||
},
|
||||
}))
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.title("Text Editor"),
|
||||
),
|
||||
),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// ### draw_default_protocol_tab
|
||||
///
|
||||
/// Draw default protocol input tab
|
||||
@@ -267,29 +303,91 @@ impl SetupActivity {
|
||||
}
|
||||
}
|
||||
|
||||
/// ### draw_text_editor_input
|
||||
/// ### draw_default_protocol_tab
|
||||
///
|
||||
/// Draw input text field for text editor parameter
|
||||
fn draw_text_editor_input(&self) -> Option<Paragraph> {
|
||||
/// Draw default protocol input tab
|
||||
fn draw_hidden_files_tab(&self) -> Option<Tabs> {
|
||||
// Check if config client is some
|
||||
match &self.config_cli {
|
||||
Some(cli) => Some(
|
||||
Paragraph::new(String::from(
|
||||
cli.get_text_editor().as_path().to_string_lossy(),
|
||||
))
|
||||
.style(Style::default().fg(match &self.tab {
|
||||
SetupTab::SshConfig => Color::White,
|
||||
Some(cli) => {
|
||||
let choices: Vec<Spans> = vec![Spans::from("Yes"), Spans::from("No")];
|
||||
let index: usize = match cli.get_show_hidden_files() {
|
||||
true => 0,
|
||||
false => 1,
|
||||
};
|
||||
let (bg, fg, block_fg): (Color, Color, Color) = match &self.tab {
|
||||
SetupTab::UserInterface(field) => match field {
|
||||
UserInterfaceInputField::TextEditor => Color::LightGreen,
|
||||
_ => Color::White,
|
||||
UserInterfaceInputField::ShowHiddenFiles => {
|
||||
(Color::LightRed, Color::Black, Color::LightRed)
|
||||
}
|
||||
_ => (Color::Reset, Color::LightRed, Color::Reset),
|
||||
},
|
||||
}))
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.title("Text Editor"),
|
||||
),
|
||||
),
|
||||
_ => (Color::Reset, Color::Reset, Color::Reset),
|
||||
};
|
||||
Some(
|
||||
Tabs::new(choices)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.style(Style::default().fg(block_fg))
|
||||
.title("Show hidden files (by default)"),
|
||||
)
|
||||
.select(index)
|
||||
.style(Style::default())
|
||||
.highlight_style(
|
||||
Style::default().add_modifier(Modifier::BOLD).fg(fg).bg(bg),
|
||||
),
|
||||
)
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// ### draw_default_group_dirs_tab
|
||||
///
|
||||
/// Draw group dirs input tab
|
||||
fn draw_default_group_dirs_tab(&self) -> Option<Tabs> {
|
||||
// Check if config client is some
|
||||
match &self.config_cli {
|
||||
Some(cli) => {
|
||||
let choices: Vec<Spans> = vec![
|
||||
Spans::from("Display First"),
|
||||
Spans::from("Display Last"),
|
||||
Spans::from("No"),
|
||||
];
|
||||
let index: usize = match cli.get_group_dirs() {
|
||||
None => 2,
|
||||
Some(val) => match val {
|
||||
GroupDirs::First => 0,
|
||||
GroupDirs::Last => 1,
|
||||
},
|
||||
};
|
||||
let (bg, fg, block_fg): (Color, Color, Color) = match &self.tab {
|
||||
SetupTab::UserInterface(field) => match field {
|
||||
UserInterfaceInputField::GroupDirs => {
|
||||
(Color::LightMagenta, Color::Black, Color::LightMagenta)
|
||||
}
|
||||
_ => (Color::Reset, Color::LightMagenta, Color::Reset),
|
||||
},
|
||||
_ => (Color::Reset, Color::Reset, Color::Reset),
|
||||
};
|
||||
Some(
|
||||
Tabs::new(choices)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.style(Style::default().fg(block_fg))
|
||||
.title("Group directories"),
|
||||
)
|
||||
.select(index)
|
||||
.style(Style::default())
|
||||
.highlight_style(
|
||||
Style::default().add_modifier(Modifier::BOLD).fg(fg).bg(bg),
|
||||
),
|
||||
)
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
@@ -481,7 +579,7 @@ impl SetupActivity {
|
||||
/// ### draw_popup_help
|
||||
///
|
||||
/// Draw authentication page help popup
|
||||
pub(super) fn draw_popup_help(&self) -> List {
|
||||
fn draw_popup_help(&self) -> List {
|
||||
// Write header
|
||||
let cmds: Vec<ListItem> = vec![
|
||||
ListItem::new(Spans::from(vec![
|
||||
|
||||
@@ -53,6 +53,8 @@ type OnChoiceCallback = fn(&mut SetupActivity);
|
||||
enum UserInterfaceInputField {
|
||||
DefaultProtocol,
|
||||
TextEditor,
|
||||
ShowHiddenFiles,
|
||||
GroupDirs,
|
||||
}
|
||||
|
||||
/// ### SetupTab
|
||||
|
||||
Reference in New Issue
Block a user