diff --git a/CHANGELOG.md b/CHANGELOG.md index 7618171..1e69a9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ Released on FIXME: ?? - **Start termscp from configuration**: Start termscp with `-c` or `--config` to start termscp from configuration page - Enhancements: - Show a "wait" message when deleting, copying and moving files and when executing commands + - Replaced all `...` with `…` in texts - Bugfix: - Fixed broken input cursor when typing UTF8 characters (tui-realm 0.3.2) - Fixed save bookmark dialog: you could switch out from dialog with `` diff --git a/src/fs/explorer/formatter.rs b/src/fs/explorer/formatter.rs index d3448fb..54ba14d 100644 --- a/src/fs/explorer/formatter.rs +++ b/src/fs/explorer/formatter.rs @@ -316,13 +316,13 @@ impl Formatter { }; let name: &str = fsentry.get_name(); let last_idx: usize = match fsentry.is_dir() { - // NOTE: For directories is 19, since we push '/' to name - true => file_len - 5, - false => file_len - 4, + // NOTE: For directories is l - 2, since we push '/' to name + true => file_len - 2, + false => file_len - 1, }; let mut name: String = match name.len() >= file_len { false => name.to_string(), - true => format!("{}...", &name[0..last_idx]), + true => format!("{}…", &name[0..last_idx]), }; if fsentry.is_dir() { name.push('/'); @@ -635,7 +635,7 @@ mod tests { assert_eq!( formatter.fmt(&entry), format!( - "piroparoporoperoperu... -rw-r--r-- root 8.2 KB {}", + "piroparoporoperoperupup… -rw-r--r-- root 8.2 KB {}", fmt_time(t, "%b %d %Y %H:%M") ) ); @@ -643,7 +643,7 @@ mod tests { assert_eq!( formatter.fmt(&entry), format!( - "piroparoporoperoperu... -rw-r--r-- 0 8.2 KB {}", + "piroparoporoperoperupup… -rw-r--r-- 0 8.2 KB {}", fmt_time(t, "%b %d %Y %H:%M") ) ); diff --git a/src/ui/activities/auth/view.rs b/src/ui/activities/auth/view.rs index 88839e6..4d366da 100644 --- a/src/ui/activities/auth/view.rs +++ b/src/ui/activities/auth/view.rs @@ -640,7 +640,7 @@ impl AuthActivity { Box::new(Input::new( InputPropsBuilder::default() .with_foreground(save_color) - .with_label(String::from("Save bookmark as...")) + .with_label(String::from("Save bookmark as…")) .with_borders( Borders::TOP | Borders::RIGHT | Borders::LEFT, BorderType::Rounded, diff --git a/src/ui/activities/filetransfer/actions/edit.rs b/src/ui/activities/filetransfer/actions/edit.rs index e6d3837..ba064a6 100644 --- a/src/ui/activities/filetransfer/actions/edit.rs +++ b/src/ui/activities/filetransfer/actions/edit.rs @@ -48,7 +48,7 @@ impl FileTransferActivity { if entry.is_file() { self.log( LogLevel::Info, - format!("Opening file \"{}\"...", entry.get_abs_path().display()), + format!("Opening file \"{}\"…", entry.get_abs_path().display()), ); // Edit file if let Err(err) = self.edit_local_file(entry.get_abs_path().as_path()) { @@ -72,7 +72,7 @@ impl FileTransferActivity { if let FsEntry::File(file) = entry { self.log( LogLevel::Info, - format!("Opening file \"{}\"...", file.abs_path.display()), + format!("Opening file \"{}\"…", file.abs_path.display()), ); // Edit file if let Err(err) = self.edit_remote_file(file) { diff --git a/src/ui/activities/filetransfer/mod.rs b/src/ui/activities/filetransfer/mod.rs index 2cb4e18..112d331 100644 --- a/src/ui/activities/filetransfer/mod.rs +++ b/src/ui/activities/filetransfer/mod.rs @@ -295,7 +295,7 @@ impl Activity for FileTransferActivity { "Client is not connected to remote; connecting to {}:{}", params.address, params.port ); - let msg: String = format!("Connecting to {}:{}...", params.address, params.port); + let msg: String = format!("Connecting to {}:{}…", params.address, params.port); // Set init state to connecting popup self.mount_wait(msg.as_str()); // Force ui draw diff --git a/src/ui/activities/filetransfer/session.rs b/src/ui/activities/filetransfer/session.rs index e864f1b..9ea0b12 100644 --- a/src/ui/activities/filetransfer/session.rs +++ b/src/ui/activities/filetransfer/session.rs @@ -122,7 +122,7 @@ impl FileTransferActivity { /// disconnect from remote pub(super) fn disconnect(&mut self) { let params = self.context().ft_params().unwrap(); - let msg: String = format!("Disconnecting from {}...", params.address); + let msg: String = format!("Disconnecting from {}…", params.address); // Show popup disconnecting self.mount_wait(msg.as_str()); // Disconnect @@ -236,7 +236,7 @@ impl FileTransferActivity { let total_transfer_size: usize = file.size; self.transfer.full.init(total_transfer_size); // Mount progress bar - self.mount_progress_bar(format!("Uploading {}...", file.abs_path.display())); + self.mount_progress_bar(format!("Uploading {}…", file.abs_path.display())); // Get remote path let file_name: String = file.name.clone(); let mut remote_path: PathBuf = PathBuf::from(curr_remote_path); @@ -268,7 +268,7 @@ impl FileTransferActivity { let total_transfer_size: usize = self.get_total_transfer_size_local(entry); self.transfer.full.init(total_transfer_size); // Mount progress bar - self.mount_progress_bar(format!("Uploading {}...", entry.get_abs_path().display())); + self.mount_progress_bar(format!("Uploading {}…", entry.get_abs_path().display())); // Send recurse self.filetransfer_send_recurse(entry, curr_remote_path, dst_name); // Umount progress bar @@ -293,7 +293,7 @@ impl FileTransferActivity { .sum(); self.transfer.full.init(total_transfer_size); // Mount progress bar - self.mount_progress_bar(format!("Uploading {} entries...", entries.len())); + self.mount_progress_bar(format!("Uploading {} entries…", entries.len())); // Send recurse entries .iter() @@ -502,7 +502,7 @@ impl FileTransferActivity { // Draw only if a significant progress has been made (performance improvement) if last_progress_val < self.transfer.partial.calc_progress() - 0.01 { // Draw - self.update_progress_bar(format!("Uploading \"{}\"...", file_name)); + self.update_progress_bar(format!("Uploading \"{}\"…", file_name)); self.view(); last_progress_val = self.transfer.partial.calc_progress(); } @@ -571,7 +571,7 @@ impl FileTransferActivity { let total_transfer_size: usize = self.get_total_transfer_size_remote(entry); self.transfer.full.init(total_transfer_size); // Mount progress bar - self.mount_progress_bar(format!("Downloading {}...", entry.get_abs_path().display())); + self.mount_progress_bar(format!("Downloading {}…", entry.get_abs_path().display())); // Receive self.filetransfer_recv_recurse(entry, local_path, dst_name); // Umount progress bar @@ -589,7 +589,7 @@ impl FileTransferActivity { let total_transfer_size: usize = entry.size; self.transfer.full.init(total_transfer_size); // Mount progress bar - self.mount_progress_bar(format!("Downloading {}...", entry.abs_path.display())); + self.mount_progress_bar(format!("Downloading {}…", entry.abs_path.display())); // Receive let result = self.filetransfer_recv_one(local_path, entry, entry.name.clone()); // Umount progress bar @@ -615,7 +615,7 @@ impl FileTransferActivity { .sum(); self.transfer.full.init(total_transfer_size); // Mount progress bar - self.mount_progress_bar(format!("Downloading {} entries...", entries.len())); + self.mount_progress_bar(format!("Downloading {} entries…", entries.len())); // Send recurse entries .iter() diff --git a/src/ui/activities/filetransfer/update.rs b/src/ui/activities/filetransfer/update.rs index 6067a32..723a0ff 100644 --- a/src/ui/activities/filetransfer/update.rs +++ b/src/ui/activities/filetransfer/update.rs @@ -40,8 +40,8 @@ use crate::fs::explorer::FileSorting; use crate::fs::FsEntry; use crate::ui::components::{file_list::FileListPropsBuilder, logbox::LogboxPropsBuilder}; use crate::ui::keymap::*; +use crate::utils::fmt::fmt_path_elide_ex; // externals -use std::path::{Path, PathBuf}; use tuirealm::{ components::progress_bar::ProgressBarPropsBuilder, props::{PropsBuilder, TableBuilder, TextSpan, TextSpanBuilder}, @@ -743,12 +743,7 @@ impl FileTransferActivity { let hostname: String = format!( "{}:{} ", hostname, - FileTransferActivity::elide_wrkdir_path( - self.local().wrkdir.as_path(), - hostname.as_str(), - width - ) - .display() + fmt_path_elide_ex(self.local().wrkdir.as_path(), width, hostname.len() + 3) // 3 because of '/…/' ); let files: Vec = self .local() @@ -782,12 +777,11 @@ impl FileTransferActivity { let hostname: String = format!( "{}:{} ", params.address, - FileTransferActivity::elide_wrkdir_path( + fmt_path_elide_ex( self.remote().wrkdir.as_path(), - params.address.as_str(), - width + width, + params.address.len() + 3 // 3 because of '/…/' ) - .display() ); let files: Vec = self .remote() @@ -910,38 +904,4 @@ impl FileTransferActivity { } } } - - /// ### elide_wrkdir_path - /// - /// Elide working directory path if longer than width + host.len - /// In this case, the path is formatted to {ANCESTOR[0]}/…/{PARENT[0]}/{BASENAME} - fn elide_wrkdir_path(wrkdir: &Path, host: &str, width: usize) -> PathBuf { - let fmt_path: String = format!("{}", wrkdir.display()); - // NOTE: +5 is const - match fmt_path.len() + host.len() + 5 > width { - false => PathBuf::from(wrkdir), - true => { - // Elide - let ancestors_len: usize = wrkdir.ancestors().count(); - let mut ancestors = wrkdir.ancestors(); - let mut elided_path: PathBuf = PathBuf::new(); - // If ancestors_len's size is bigger than 2, push count - 2 - if ancestors_len > 2 { - elided_path.push(ancestors.nth(ancestors_len - 2).unwrap()); - } - // If ancestors_len is bigger than 3, push '…' and parent too - if ancestors_len > 3 { - elided_path.push("…"); - if let Some(parent) = wrkdir.ancestors().nth(1) { - elided_path.push(parent.file_name().unwrap()); - } - } - // Push file_name - if let Some(name) = wrkdir.file_name() { - elided_path.push(name); - } - elided_path - } - } - } } diff --git a/src/ui/activities/filetransfer/view.rs b/src/ui/activities/filetransfer/view.rs index 41b7b49..e9046a5 100644 --- a/src/ui/activities/filetransfer/view.rs +++ b/src/ui/activities/filetransfer/view.rs @@ -521,7 +521,7 @@ impl FileTransferActivity { InputPropsBuilder::default() .with_borders(Borders::ALL, BorderType::Rounded, input_color) .with_foreground(input_color) - .with_label(String::from("Copy file(s) to...")) + .with_label(String::from("Copy file(s) to…")) .build(), )), ); @@ -672,7 +672,7 @@ impl FileTransferActivity { InputPropsBuilder::default() .with_borders(Borders::ALL, BorderType::Rounded, input_color) .with_foreground(input_color) - .with_label(String::from("Open file with...")) + .with_label(String::from("Open file with…")) .build(), )), ); @@ -691,7 +691,7 @@ impl FileTransferActivity { InputPropsBuilder::default() .with_borders(Borders::ALL, BorderType::Rounded, input_color) .with_foreground(input_color) - .with_label(String::from("Move file(s) to...")) + .with_label(String::from("Move file(s) to…")) .build(), )), ); @@ -710,7 +710,7 @@ impl FileTransferActivity { InputPropsBuilder::default() .with_borders(Borders::ALL, BorderType::Rounded, input_color) .with_foreground(input_color) - .with_label(String::from("Save as...")) + .with_label(String::from("Save as…")) .build(), )), ); diff --git a/src/utils/fmt.rs b/src/utils/fmt.rs index f1a6f98..703cd91 100644 --- a/src/utils/fmt.rs +++ b/src/utils/fmt.rs @@ -120,10 +120,19 @@ pub fn align_text_center(text: &str, width: u16) -> String { /// ### elide_path /// /// Elide a path if longer than width -/// In this case, the path is formatted to {ANCESTOR[0]}/.../{PARENT[0]}/{BASENAME} +/// In this case, the path is formatted to {ANCESTOR[0]}/…/{PARENT[0]}/{BASENAME} pub fn fmt_path_elide(p: &Path, width: usize) -> String { + fmt_path_elide_ex(p, width, 0) +} + +/// ### fmt_path_elide_ex +/// +/// Elide a path if longer than width +/// In this case, the path is formatted to {ANCESTOR[0]}/…/{PARENT[0]}/{BASENAME} +/// This function allows to specify an extra length to consider to elide path +pub fn fmt_path_elide_ex(p: &Path, width: usize, extra_len: usize) -> String { let fmt_path: String = format!("{}", p.display()); - match fmt_path.len() > width as usize { + match fmt_path.len() + extra_len > width as usize { false => fmt_path, true => { // Elide @@ -134,9 +143,9 @@ pub fn fmt_path_elide(p: &Path, width: usize) -> String { if ancestors_len > 2 { elided_path.push(ancestors.nth(ancestors_len - 2).unwrap()); } - // If ancestors_len is bigger than 3, push '...' and parent too + // If ancestors_len is bigger than 3, push '…' and parent too if ancestors_len > 3 { - elided_path.push("..."); + elided_path.push("…"); if let Some(parent) = p.ancestors().nth(1) { elided_path.push(parent.file_name().unwrap()); } @@ -390,7 +399,7 @@ mod tests { // Above max size, only one ancestor assert_eq!(fmt_path_elide(p, 8), String::from("/develop/pippo")); let p: &Path = &Path::new("/develop/pippo/foo/bar"); - assert_eq!(fmt_path_elide(p, 16), String::from("/develop/.../foo/bar")); + assert_eq!(fmt_path_elide(p, 16), String::from("/develop/…/foo/bar")); } #[test]