Skip to main content

text_width

Function text_width 

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

The display width of s in terminal cells.

Measured per grapheme cluster, because that is the unit a surface advances by: 👨‍👩‍👧 is five codepoints measuring 2 + 0 + 2 + 0 + 2 cells one at a time, but the character they spell is drawn in 2. Both frontends already measure it that way — ratatui asks unicode-width per cluster, and the GUI asks its own text system — so the caret only lands where the text is if this agrees with them.