Expand description
Authoritative terminal display-cell width (“variable column width”) math.
A terminal cell is not one byte, nor even one character: combining marks occupy no cell, East-Asian wide glyphs occupy two, and East-Asian-ambiguous glyphs occupy one or two depending on terminal configuration. Every wrap/truncate/pad/hit-test decision must use the same verdict or frames, links and tool output drift out of alignment.
On a terminal configured to render East-Asian-ambiguous glyphs (UAX #11)
as two cells (ui.ambiguous_width = "wide"), the CJK width table is used
so the math matches what the terminal actually shows.
The halfwidth voiced sound marks U+FF9E (dakuten) and U+FF9F
(handakuten) are the one correction unicode-width tables have disagreed
on: older tables report them as zero width even though a terminal draws
them in one cell, so wrap and truncation math would otherwise credit one
cell for a two-cell glyph. Only the missing width is credited, so newer
tables that already count the mark are not double-counted.
Functions§
- char_
display_ width - Terminal display width of one character under the resolved ambiguous-width verdict, for char-by-char column mapping.
- char_
display_ width_ or - Terminal display width of one character, with
fallbackfor characters the width tables do not classify (control characters), matching call sites that treat unknown widths as one cell. - display_
width - Terminal display width of
textin cells.