Skip to main content

display_width

Function display_width 

Source
pub fn display_width(s: &str) -> usize
Expand description

Returns the display width of a string, ignoring ANSI escape codes.

Warning: This only strips ANSI escape codes, not BBCode tags like [bold]...[/bold]. For user-facing content that may contain BBCode markup, use visible_width instead.

§Example

use standout_render::tabular::display_width;

assert_eq!(display_width("hello"), 5);
assert_eq!(display_width("\x1b[31mred\x1b[0m"), 3);  // ANSI codes ignored
assert_eq!(display_width("日本"), 4);  // CJK characters are 2 columns each