Skip to main content

truncate_start

Function truncate_start 

Source
pub fn truncate_start(s: &str, max_width: usize, ellipsis: &str) -> String
Expand description

Truncates a string from the start to fit within a maximum display width.

Characters are removed from the beginning, and the ellipsis is prepended. Useful for paths where the filename at the end is more important than the directory prefix.

ANSI escape codes are preserved but don’t count toward display width.

§Example

use standout_render::tabular::truncate_start;

assert_eq!(truncate_start("Hello World", 8, "…"), "…o World");
assert_eq!(truncate_start("/path/to/file.rs", 12, "…"), "…/to/file.rs");