Skip to main content

text_width

Function text_width 

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

Width of plain (non-markup) text in terminal columns.

Use this for layout arithmetic — column padding, gauge widths, the widest label in a report. A character count is wrong for any locale with CJK text, where one glyph occupies two cells, and for combining marks, which occupy none.

This is deliberately separate from crate::pango::visible_width, which additionally strips <span> markup. Feeding plain text to that function would treat a literal < as the start of a tag and silently undercount the rest of the line; feeding markup to this one would count the tags.

Character counts remain correct for limits (a config field documented as “1 to 48 characters”) and for edit-cursor positions, which move per character rather than per column. Those are not layout.