From e36237426a2650bb9edf4261a7659b3b96fe3b71 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 1 Sep 2023 16:45:13 +0900 Subject: [PATCH] cli: elide path in snapshot progress in the same way --- cli/src/progress.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cli/src/progress.rs b/cli/src/progress.rs index 7560fe685..476a6c931 100644 --- a/cli/src/progress.rs +++ b/cli/src/progress.rs @@ -9,6 +9,7 @@ use jj_lib::git; use jj_lib::repo_path::RepoPath; use crate::cleanup_guard::CleanupGuard; +use crate::text_util; use crate::ui::{OutputGuard, ProgressOutput, Ui}; pub struct Progress { @@ -193,14 +194,15 @@ pub fn snapshot_progress(ui: &Ui) -> Option { } let line_width = state.output.term_width().map(usize::from).unwrap_or(80); - let path_width = line_width.saturating_sub(13); // Account for "Snapshotting " + let max_path_width = line_width.saturating_sub(13); // Account for "Snapshotting " + let fs_path = path.to_fs_path(Path::new("")); + let (display_path, _) = + text_util::elide_start(fs_path.to_str().unwrap(), "...", max_path_width); _ = write!( state.output, - "\r{}Snapshotting {:.*}", + "\r{}Snapshotting {display_path}", Clear(ClearType::CurrentLine), - path_width, - path.to_fs_path(Path::new("")).display() ); _ = state.output.flush(); })