From efad2b96dba633eb67818a7f8504a64777d4d6cf Mon Sep 17 00:00:00 2001 From: veeso Date: Wed, 16 Jun 2021 13:57:11 +0200 Subject: [PATCH] Status bar improvements: 'Show hidden files' in status bar; Status bar is has now been splitted into two, one for each explorer tab --- CHANGELOG.md | 3 + src/fs/explorer/mod.rs | 9 ++ src/ui/activities/filetransfer/mod.rs | 3 +- src/ui/activities/filetransfer/update.rs | 12 ++- src/ui/activities/filetransfer/view.rs | 112 +++++++++++++++++------ 5 files changed, 110 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cab7cb..40852bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,9 @@ Released on FIXME: ?? - Found many bugs which has now been fixed - Build in CI won't fail due to test servers not responding - We're now able to test all the functionalities of the file transfers + - **Status bar improvements** + - "Show hidden files" in status bar + - Status bar is has now been splitted into two, one for each explorer tab - Bugfix: - Fixed broken input cursor when typing UTF8 characters (tui-realm 0.3.2) - Fixed [Issue 44](https://github.com/veeso/termscp/issues/44): Could not move files to other paths in FTP diff --git a/src/fs/explorer/mod.rs b/src/fs/explorer/mod.rs index ec90def..66b78cd 100644 --- a/src/fs/explorer/mod.rs +++ b/src/fs/explorer/mod.rs @@ -306,6 +306,13 @@ impl FileExplorer { pub fn toggle_hidden_files(&mut self) { self.opts.toggle(ExplorerOpts::SHOW_HIDDEN_FILES); } + + /// ### hidden_files_visible + /// + /// Returns whether hidden files are visible + pub fn hidden_files_visible(&self) -> bool { + self.opts.intersects(ExplorerOpts::SHOW_HIDDEN_FILES) + } } // Traits @@ -411,6 +418,7 @@ mod tests { let mut explorer: FileExplorer = FileExplorer::default(); // Don't show hidden files explorer.opts.remove(ExplorerOpts::SHOW_HIDDEN_FILES); + assert_eq!(explorer.hidden_files_visible(), false); // Create files explorer.set_files(vec![ make_fs_entry("README.md", false), @@ -434,6 +442,7 @@ mod tests { assert_eq!(explorer.iter_files().count(), 4); // Toggle hidden explorer.toggle_hidden_files(); + assert_eq!(explorer.hidden_files_visible(), true); assert_eq!(explorer.iter_files().count(), 6); // All files are returned now } diff --git a/src/ui/activities/filetransfer/mod.rs b/src/ui/activities/filetransfer/mod.rs index 5cedb60..ee71995 100644 --- a/src/ui/activities/filetransfer/mod.rs +++ b/src/ui/activities/filetransfer/mod.rs @@ -88,7 +88,8 @@ const COMPONENT_RADIO_DELETE: &str = "RADIO_DELETE"; const COMPONENT_RADIO_DISCONNECT: &str = "RADIO_DISCONNECT"; const COMPONENT_RADIO_QUIT: &str = "RADIO_QUIT"; const COMPONENT_RADIO_SORTING: &str = "RADIO_SORTING"; -const COMPONENT_SPAN_STATUS_BAR: &str = "STATUS_BAR"; +const COMPONENT_SPAN_STATUS_BAR_LOCAL: &str = "STATUS_BAR_LOCAL"; +const COMPONENT_SPAN_STATUS_BAR_REMOTE: &str = "STATUS_BAR_REMOTE"; const COMPONENT_LIST_FILEINFO: &str = "LIST_FILEINFO"; /// ## LogLevel diff --git a/src/ui/activities/filetransfer/update.rs b/src/ui/activities/filetransfer/update.rs index 7f63f2d..61aa72e 100644 --- a/src/ui/activities/filetransfer/update.rs +++ b/src/ui/activities/filetransfer/update.rs @@ -107,6 +107,8 @@ impl Update for FileTransferActivity { (COMPONENT_EXPLORER_LOCAL, &MSG_KEY_CHAR_A) => { // Toggle hidden files self.local_mut().toggle_hidden_files(); + // Update status bar + self.refresh_local_status_bar(); // Reload file list component self.update_local_filelist() } @@ -180,6 +182,8 @@ impl Update for FileTransferActivity { (COMPONENT_EXPLORER_REMOTE, &MSG_KEY_CHAR_A) => { // Toggle hidden files self.remote_mut().toggle_hidden_files(); + // Update status bar + self.refresh_remote_status_bar(); // Reload file list component self.update_remote_filelist() } @@ -277,7 +281,7 @@ impl Update for FileTransferActivity { // Toggle browser sync self.browser.toggle_sync_browsing(); // Update status bar - self.refresh_status_bar(); + self.refresh_remote_status_bar(); None } (COMPONENT_EXPLORER_LOCAL, &MSG_KEY_ESC) @@ -618,7 +622,11 @@ impl Update for FileTransferActivity { _ => panic!("Found result doesn't support SORTING"), } // Update status bar - self.refresh_status_bar(); + match self.browser.tab() { + FileExplorerTab::Local => self.refresh_local_status_bar(), + FileExplorerTab::Remote => self.refresh_remote_status_bar(), + _ => panic!("Found result doesn't support SORTING"), + }; // Reload files match self.browser.tab() { FileExplorerTab::Local => self.update_local_filelist(), diff --git a/src/ui/activities/filetransfer/view.rs b/src/ui/activities/filetransfer/view.rs index ce2f416..3ec366b 100644 --- a/src/ui/activities/filetransfer/view.rs +++ b/src/ui/activities/filetransfer/view.rs @@ -100,13 +100,18 @@ impl FileTransferActivity { .build(), )), ); - // Mount status bar + // Mount status bars self.view.mount( - super::COMPONENT_SPAN_STATUS_BAR, + super::COMPONENT_SPAN_STATUS_BAR_LOCAL, + Box::new(Span::new(SpanPropsBuilder::default().build())), + ); + self.view.mount( + super::COMPONENT_SPAN_STATUS_BAR_REMOTE, Box::new(Span::new(SpanPropsBuilder::default().build())), ); // Load process bar - self.refresh_status_bar(); + self.refresh_local_status_bar(); + self.refresh_remote_status_bar(); // Update components let _ = self.update_local_filelist(); let _ = self.update_remote_filelist(); @@ -145,6 +150,12 @@ impl FileTransferActivity { .constraints([Constraint::Length(1), Constraint::Length(10)].as_ref()) .direction(Direction::Vertical) .split(chunks[1]); + // Create status bar chunks + let status_bar_chunks = Layout::default() + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) + .direction(Direction::Horizontal) + .horizontal_margin(1) + .split(bottom_chunks[0]); // If width is unset in the storage, set width if !store.isset(super::STORAGE_EXPLORER_WIDTH) { store.set_unsigned(super::STORAGE_EXPLORER_WIDTH, tabs_chunks[0].width as usize); @@ -170,11 +181,20 @@ impl FileTransferActivity { .view .render(super::COMPONENT_EXPLORER_REMOTE, f, tabs_chunks[1]), } - // Draw log box and status bar + // Draw log box self.view .render(super::COMPONENT_LOG_BOX, f, bottom_chunks[1]); - self.view - .render(super::COMPONENT_SPAN_STATUS_BAR, f, bottom_chunks[0]); + // Draw status bar + self.view.render( + super::COMPONENT_SPAN_STATUS_BAR_LOCAL, + f, + status_bar_chunks[0], + ); + self.view.render( + super::COMPONENT_SPAN_STATUS_BAR_REMOTE, + f, + status_bar_chunks[1], + ); // @! Draw popups if let Some(props) = self.view.get_props(super::COMPONENT_INPUT_COPY) { if props.visible { @@ -840,9 +860,54 @@ impl FileTransferActivity { self.view.umount(super::COMPONENT_LIST_FILEINFO); } - pub(super) fn refresh_status_bar(&mut self) { - let bar_spans: Vec = vec![ - TextSpanBuilder::new("Synchronized Browsing: ") + pub(super) fn refresh_local_status_bar(&mut self) { + let local_bar_spans: Vec = vec![ + TextSpanBuilder::new("File sorting: ") + .with_foreground(Color::LightYellow) + .build(), + TextSpanBuilder::new(Self::get_file_sorting_str(self.local().get_file_sorting())) + .with_foreground(Color::LightYellow) + .reversed() + .build(), + TextSpanBuilder::new(" Hidden files: ") + .with_foreground(Color::LightBlue) + .build(), + TextSpanBuilder::new(Self::get_hidden_files_str( + self.local().hidden_files_visible(), + )) + .with_foreground(Color::LightBlue) + .reversed() + .build(), + ]; + if let Some(props) = self.view.get_props(super::COMPONENT_SPAN_STATUS_BAR_LOCAL) { + self.view.update( + super::COMPONENT_SPAN_STATUS_BAR_LOCAL, + SpanPropsBuilder::from(props) + .with_spans(local_bar_spans) + .build(), + ); + } + } + + pub(super) fn refresh_remote_status_bar(&mut self) { + let remote_bar_spans: Vec = vec![ + TextSpanBuilder::new("File sorting: ") + .with_foreground(Color::LightYellow) + .build(), + TextSpanBuilder::new(Self::get_file_sorting_str(self.remote().get_file_sorting())) + .with_foreground(Color::LightYellow) + .reversed() + .build(), + TextSpanBuilder::new(" Hidden files: ") + .with_foreground(Color::LightBlue) + .build(), + TextSpanBuilder::new(Self::get_hidden_files_str( + self.remote().hidden_files_visible(), + )) + .with_foreground(Color::LightBlue) + .reversed() + .build(), + TextSpanBuilder::new(" Sync Browsing: ") .with_foreground(Color::LightGreen) .build(), TextSpanBuilder::new(match self.browser.sync_browsing { @@ -852,25 +917,13 @@ impl FileTransferActivity { .with_foreground(Color::LightGreen) .reversed() .build(), - TextSpanBuilder::new(" Localhost file sorting: ") - .with_foreground(Color::LightYellow) - .build(), - TextSpanBuilder::new(Self::get_file_sorting_str(self.local().get_file_sorting())) - .with_foreground(Color::LightYellow) - .reversed() - .build(), - TextSpanBuilder::new(" Remote host file sorting: ") - .with_foreground(Color::LightBlue) - .build(), - TextSpanBuilder::new(Self::get_file_sorting_str(self.remote().get_file_sorting())) - .with_foreground(Color::LightBlue) - .reversed() - .build(), ]; - if let Some(props) = self.view.get_props(super::COMPONENT_SPAN_STATUS_BAR) { + if let Some(props) = self.view.get_props(super::COMPONENT_SPAN_STATUS_BAR_REMOTE) { self.view.update( - super::COMPONENT_SPAN_STATUS_BAR, - SpanPropsBuilder::from(props).with_spans(bar_spans).build(), + super::COMPONENT_SPAN_STATUS_BAR_REMOTE, + SpanPropsBuilder::from(props) + .with_spans(remote_bar_spans) + .build(), ); } } @@ -1128,4 +1181,11 @@ impl FileTransferActivity { FileSorting::BySize => "By size", } } + + fn get_hidden_files_str(show: bool) -> &'static str { + match show { + true => "Show", + false => "Hide", + } + } }