Replaced '...' with '…' in texts

This commit is contained in:
veeso
2021-07-15 12:24:20 +02:00
parent e3a9d253f7
commit 4093ba169c
9 changed files with 42 additions and 72 deletions

View File

@@ -47,6 +47,7 @@ Released on FIXME: ??
- **Start termscp from configuration**: Start termscp with `-c` or `--config` to start termscp from configuration page - **Start termscp from configuration**: Start termscp with `-c` or `--config` to start termscp from configuration page
- Enhancements: - Enhancements:
- Show a "wait" message when deleting, copying and moving files and when executing commands - Show a "wait" message when deleting, copying and moving files and when executing commands
- Replaced all `...` with `…` in texts
- Bugfix: - Bugfix:
- Fixed broken input cursor when typing UTF8 characters (tui-realm 0.3.2) - Fixed broken input cursor when typing UTF8 characters (tui-realm 0.3.2)
- Fixed save bookmark dialog: you could switch out from dialog with `<TAB>` - Fixed save bookmark dialog: you could switch out from dialog with `<TAB>`

View File

@@ -316,13 +316,13 @@ impl Formatter {
}; };
let name: &str = fsentry.get_name(); let name: &str = fsentry.get_name();
let last_idx: usize = match fsentry.is_dir() { let last_idx: usize = match fsentry.is_dir() {
// NOTE: For directories is 19, since we push '/' to name // NOTE: For directories is l - 2, since we push '/' to name
true => file_len - 5, true => file_len - 2,
false => file_len - 4, false => file_len - 1,
}; };
let mut name: String = match name.len() >= file_len { let mut name: String = match name.len() >= file_len {
false => name.to_string(), false => name.to_string(),
true => format!("{}...", &name[0..last_idx]), true => format!("{}", &name[0..last_idx]),
}; };
if fsentry.is_dir() { if fsentry.is_dir() {
name.push('/'); name.push('/');
@@ -635,7 +635,7 @@ mod tests {
assert_eq!( assert_eq!(
formatter.fmt(&entry), formatter.fmt(&entry),
format!( 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") fmt_time(t, "%b %d %Y %H:%M")
) )
); );
@@ -643,7 +643,7 @@ mod tests {
assert_eq!( assert_eq!(
formatter.fmt(&entry), formatter.fmt(&entry),
format!( 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") fmt_time(t, "%b %d %Y %H:%M")
) )
); );

View File

@@ -640,7 +640,7 @@ impl AuthActivity {
Box::new(Input::new( Box::new(Input::new(
InputPropsBuilder::default() InputPropsBuilder::default()
.with_foreground(save_color) .with_foreground(save_color)
.with_label(String::from("Save bookmark as...")) .with_label(String::from("Save bookmark as"))
.with_borders( .with_borders(
Borders::TOP | Borders::RIGHT | Borders::LEFT, Borders::TOP | Borders::RIGHT | Borders::LEFT,
BorderType::Rounded, BorderType::Rounded,

View File

@@ -48,7 +48,7 @@ impl FileTransferActivity {
if entry.is_file() { if entry.is_file() {
self.log( self.log(
LogLevel::Info, LogLevel::Info,
format!("Opening file \"{}\"...", entry.get_abs_path().display()), format!("Opening file \"{}\"", entry.get_abs_path().display()),
); );
// Edit file // Edit file
if let Err(err) = self.edit_local_file(entry.get_abs_path().as_path()) { 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 { if let FsEntry::File(file) = entry {
self.log( self.log(
LogLevel::Info, LogLevel::Info,
format!("Opening file \"{}\"...", file.abs_path.display()), format!("Opening file \"{}\"", file.abs_path.display()),
); );
// Edit file // Edit file
if let Err(err) = self.edit_remote_file(file) { if let Err(err) = self.edit_remote_file(file) {

View File

@@ -295,7 +295,7 @@ impl Activity for FileTransferActivity {
"Client is not connected to remote; connecting to {}:{}", "Client is not connected to remote; connecting to {}:{}",
params.address, params.port 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 // Set init state to connecting popup
self.mount_wait(msg.as_str()); self.mount_wait(msg.as_str());
// Force ui draw // Force ui draw

View File

@@ -122,7 +122,7 @@ impl FileTransferActivity {
/// disconnect from remote /// disconnect from remote
pub(super) fn disconnect(&mut self) { pub(super) fn disconnect(&mut self) {
let params = self.context().ft_params().unwrap(); 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 // Show popup disconnecting
self.mount_wait(msg.as_str()); self.mount_wait(msg.as_str());
// Disconnect // Disconnect
@@ -236,7 +236,7 @@ impl FileTransferActivity {
let total_transfer_size: usize = file.size; let total_transfer_size: usize = file.size;
self.transfer.full.init(total_transfer_size); self.transfer.full.init(total_transfer_size);
// Mount progress bar // 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 // Get remote path
let file_name: String = file.name.clone(); let file_name: String = file.name.clone();
let mut remote_path: PathBuf = PathBuf::from(curr_remote_path); 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); let total_transfer_size: usize = self.get_total_transfer_size_local(entry);
self.transfer.full.init(total_transfer_size); self.transfer.full.init(total_transfer_size);
// Mount progress bar // 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 // Send recurse
self.filetransfer_send_recurse(entry, curr_remote_path, dst_name); self.filetransfer_send_recurse(entry, curr_remote_path, dst_name);
// Umount progress bar // Umount progress bar
@@ -293,7 +293,7 @@ impl FileTransferActivity {
.sum(); .sum();
self.transfer.full.init(total_transfer_size); self.transfer.full.init(total_transfer_size);
// Mount progress bar // Mount progress bar
self.mount_progress_bar(format!("Uploading {} entries...", entries.len())); self.mount_progress_bar(format!("Uploading {} entries", entries.len()));
// Send recurse // Send recurse
entries entries
.iter() .iter()
@@ -502,7 +502,7 @@ impl FileTransferActivity {
// Draw only if a significant progress has been made (performance improvement) // Draw only if a significant progress has been made (performance improvement)
if last_progress_val < self.transfer.partial.calc_progress() - 0.01 { if last_progress_val < self.transfer.partial.calc_progress() - 0.01 {
// Draw // Draw
self.update_progress_bar(format!("Uploading \"{}\"...", file_name)); self.update_progress_bar(format!("Uploading \"{}\"", file_name));
self.view(); self.view();
last_progress_val = self.transfer.partial.calc_progress(); 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); let total_transfer_size: usize = self.get_total_transfer_size_remote(entry);
self.transfer.full.init(total_transfer_size); self.transfer.full.init(total_transfer_size);
// Mount progress bar // 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 // Receive
self.filetransfer_recv_recurse(entry, local_path, dst_name); self.filetransfer_recv_recurse(entry, local_path, dst_name);
// Umount progress bar // Umount progress bar
@@ -589,7 +589,7 @@ impl FileTransferActivity {
let total_transfer_size: usize = entry.size; let total_transfer_size: usize = entry.size;
self.transfer.full.init(total_transfer_size); self.transfer.full.init(total_transfer_size);
// Mount progress bar // Mount progress bar
self.mount_progress_bar(format!("Downloading {}...", entry.abs_path.display())); self.mount_progress_bar(format!("Downloading {}", entry.abs_path.display()));
// Receive // Receive
let result = self.filetransfer_recv_one(local_path, entry, entry.name.clone()); let result = self.filetransfer_recv_one(local_path, entry, entry.name.clone());
// Umount progress bar // Umount progress bar
@@ -615,7 +615,7 @@ impl FileTransferActivity {
.sum(); .sum();
self.transfer.full.init(total_transfer_size); self.transfer.full.init(total_transfer_size);
// Mount progress bar // Mount progress bar
self.mount_progress_bar(format!("Downloading {} entries...", entries.len())); self.mount_progress_bar(format!("Downloading {} entries", entries.len()));
// Send recurse // Send recurse
entries entries
.iter() .iter()

View File

@@ -40,8 +40,8 @@ use crate::fs::explorer::FileSorting;
use crate::fs::FsEntry; use crate::fs::FsEntry;
use crate::ui::components::{file_list::FileListPropsBuilder, logbox::LogboxPropsBuilder}; use crate::ui::components::{file_list::FileListPropsBuilder, logbox::LogboxPropsBuilder};
use crate::ui::keymap::*; use crate::ui::keymap::*;
use crate::utils::fmt::fmt_path_elide_ex;
// externals // externals
use std::path::{Path, PathBuf};
use tuirealm::{ use tuirealm::{
components::progress_bar::ProgressBarPropsBuilder, components::progress_bar::ProgressBarPropsBuilder,
props::{PropsBuilder, TableBuilder, TextSpan, TextSpanBuilder}, props::{PropsBuilder, TableBuilder, TextSpan, TextSpanBuilder},
@@ -743,12 +743,7 @@ impl FileTransferActivity {
let hostname: String = format!( let hostname: String = format!(
"{}:{} ", "{}:{} ",
hostname, hostname,
FileTransferActivity::elide_wrkdir_path( fmt_path_elide_ex(self.local().wrkdir.as_path(), width, hostname.len() + 3) // 3 because of '/…/'
self.local().wrkdir.as_path(),
hostname.as_str(),
width
)
.display()
); );
let files: Vec<String> = self let files: Vec<String> = self
.local() .local()
@@ -782,12 +777,11 @@ impl FileTransferActivity {
let hostname: String = format!( let hostname: String = format!(
"{}:{} ", "{}:{} ",
params.address, params.address,
FileTransferActivity::elide_wrkdir_path( fmt_path_elide_ex(
self.remote().wrkdir.as_path(), self.remote().wrkdir.as_path(),
params.address.as_str(), width,
width params.address.len() + 3 // 3 because of '/…/'
) )
.display()
); );
let files: Vec<String> = self let files: Vec<String> = self
.remote() .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
}
}
}
} }

View File

@@ -521,7 +521,7 @@ impl FileTransferActivity {
InputPropsBuilder::default() InputPropsBuilder::default()
.with_borders(Borders::ALL, BorderType::Rounded, input_color) .with_borders(Borders::ALL, BorderType::Rounded, input_color)
.with_foreground(input_color) .with_foreground(input_color)
.with_label(String::from("Copy file(s) to...")) .with_label(String::from("Copy file(s) to"))
.build(), .build(),
)), )),
); );
@@ -672,7 +672,7 @@ impl FileTransferActivity {
InputPropsBuilder::default() InputPropsBuilder::default()
.with_borders(Borders::ALL, BorderType::Rounded, input_color) .with_borders(Borders::ALL, BorderType::Rounded, input_color)
.with_foreground(input_color) .with_foreground(input_color)
.with_label(String::from("Open file with...")) .with_label(String::from("Open file with"))
.build(), .build(),
)), )),
); );
@@ -691,7 +691,7 @@ impl FileTransferActivity {
InputPropsBuilder::default() InputPropsBuilder::default()
.with_borders(Borders::ALL, BorderType::Rounded, input_color) .with_borders(Borders::ALL, BorderType::Rounded, input_color)
.with_foreground(input_color) .with_foreground(input_color)
.with_label(String::from("Move file(s) to...")) .with_label(String::from("Move file(s) to"))
.build(), .build(),
)), )),
); );
@@ -710,7 +710,7 @@ impl FileTransferActivity {
InputPropsBuilder::default() InputPropsBuilder::default()
.with_borders(Borders::ALL, BorderType::Rounded, input_color) .with_borders(Borders::ALL, BorderType::Rounded, input_color)
.with_foreground(input_color) .with_foreground(input_color)
.with_label(String::from("Save as...")) .with_label(String::from("Save as"))
.build(), .build(),
)), )),
); );

View File

@@ -120,10 +120,19 @@ pub fn align_text_center(text: &str, width: u16) -> String {
/// ### elide_path /// ### elide_path
/// ///
/// Elide a path if longer than width /// 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 { 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()); 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, false => fmt_path,
true => { true => {
// Elide // Elide
@@ -134,9 +143,9 @@ pub fn fmt_path_elide(p: &Path, width: usize) -> String {
if ancestors_len > 2 { if ancestors_len > 2 {
elided_path.push(ancestors.nth(ancestors_len - 2).unwrap()); 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 { if ancestors_len > 3 {
elided_path.push("..."); elided_path.push("");
if let Some(parent) = p.ancestors().nth(1) { if let Some(parent) = p.ancestors().nth(1) {
elided_path.push(parent.file_name().unwrap()); elided_path.push(parent.file_name().unwrap());
} }
@@ -390,7 +399,7 @@ mod tests {
// Above max size, only one ancestor // Above max size, only one ancestor
assert_eq!(fmt_path_elide(p, 8), String::from("/develop/pippo")); assert_eq!(fmt_path_elide(p, 8), String::from("/develop/pippo"));
let p: &Path = &Path::new("/develop/pippo/foo/bar"); 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] #[test]