Skip to main content

display_width

Function display_width 

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

Returns the display width of s in columns, as the layout engine measures it: the sum, over the extended grapheme clusters of s, of each cluster’s Unicode display width, with East-Asian Ambiguous characters counted as one column.

A grapheme cluster is what a reader sees as one character (e followed by a combining accent, or a whole family emoji joined by zero-width joiners), as Unicode’s text segmentation rules delimit it. East-Asian Ambiguous characters are those a terminal configured for Western languages draws one column wide and one configured for East-Asian languages two (…, →, •, the em dash); the engine counts them as one column.

The printer wraps against this width, and an emitter uses it for anything it aligns by hand (a rule of = under a heading, a label padded to a column). "Über Bäume — 日本語" measures 19 (the three East-Asian characters are two columns each); a family emoji measures 2; a combining accent adds nothing.