Skip to main content

visible_width

Function visible_width 

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

Returns the visible display width of a string, stripping both BBCode tags and ANSI escape codes before measurement.

Use this for any text that may contain markup. For strings known to be tag-free (e.g., separator literals), display_width avoids the overhead.

ยงExample

use standout_render::tabular::visible_width;

assert_eq!(visible_width("hello"), 5);
assert_eq!(visible_width("[bold]hello[/bold]"), 5);
assert_eq!(visible_width("\x1b[31m[red]hi[/red]\x1b[0m"), 2);