display_width

Function display_width 

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

Strip ANSI escape codes from a string and return the display width This handles ANSI SGR (Select Graphic Rendition) codes like colors and styles and correctly calculates Unicode character widths (e.g., emoji take 2 columns)

§Examples

use sql_cli::utils::string_utils::display_width;

// Simple ASCII text
assert_eq!(display_width("hello"), 5);

// ANSI colored text (escape codes don't count toward width)
assert_eq!(display_width("\x1b[31mred\x1b[0m"), 3);

// Unicode emoji (takes 2 columns)
assert_eq!(display_width("→"), 1);  // Right arrow
assert_eq!(display_width("⚡"), 2);  // Lightning bolt emoji