pub fn truncate_path(path: &str, max_cols: usize) -> StringExpand description
Truncate a file-system path to max_cols display columns, using a
path-aware strategy that preserves the last segment (the project or
folder name — the most useful bit) and replaces leading segments with
.../. Both / and \ are treated as separators.
Examples (max_cols = 20):
~/Documents/WPSDrive/NotLoginPage → …/NotLoginPage (keeps the last segment)
~/a/b/c (max_cols = 6)
→ …/c (keeps .../ + last segment)
~/foo (max_cols = 5) → ~/foo (fits, no truncation)
If the last segment alone exceeds max_cols, the function falls back
to a plain truncate_with_ellipsis so the output always fits.