pub fn visible_len(s: &str) -> usizeExpand description
Strip ANSI escape sequences and return the string’s width in terminal columns.
Not a character count. A CJK ideograph or a Hangul syllable occupies two columns, a
combining mark occupies none, and an emoji followed by the variation selector U+FE0F
(☀️) is two columns even though its base character alone would be one — none of which a
chars().count() can express.
This matters because every layout decision in this module is denominated in columns: the
padding that positions the logo, the wrap width for beside-logo lines, and the logo’s own
measured width. Counting characters undercounted Media: 宇多田ヒカル - 花束を君に by 11
columns, so the line overran its column and pushed the logo out of alignment on that row.
media/player (v0.8.0) read arbitrary track metadata, so non-Latin text is an ordinary
input here, not an exotic one.
Escape handling is unchanged: \x1b opens a sequence that ends at the first ASCII letter,
which covers the CSI (\x1b[…m), charset (\x1b(B) and private (\x1b[?25l) forms that
owo_colors and chafa emit.
The visible characters are measured as one run rather than summed per character, because width is not a per-character property: variation-selector and zero-width-joiner sequences are only correct when the whole grapheme is measured together.