pub fn truncate_to_width(s: &str, max_width: usize) -> StringExpand description
Truncates a string to fit within a maximum display width, adding ellipsis if needed.
Uses Unicode width calculations for proper handling of CJK and other wide characters.
If the string fits within max_width, it is returned unchanged. If truncation is
needed, characters are removed from the end and replaced with … (ellipsis).
§Arguments
s- The string to truncatemax_width- Maximum display width (in terminal columns)
§Example
use standout::truncate_to_width;
assert_eq!(truncate_to_width("Hello", 10), "Hello");
assert_eq!(truncate_to_width("Hello World", 6), "Hello…");