truncate_width

Function truncate_width 

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

Truncate a string to a maximum display width, adding “…” if truncated.

This accounts for unicode character display widths (e.g., CJK characters take 2 columns, emoji may take 2, etc.). Essential for TUI rendering.

§Example

let result = truncate_width("Hello, World!", 8);
assert_eq!(result, "Hello,…");