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.

This is a convenience wrapper around console::measure_text_width that correctly handles:

  • ANSI escape sequences (colors, styles)
  • Unicode characters including CJK wide characters
  • Zero-width characters and combining marks

§Example

use standout::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