Skip to main content

Module width

Module width 

Source
Expand description

Display width — the number of cells a character takes in a monospace font.

Table columns are aligned by display width, not character count (SPEC.md section 7). Hangul, Han characters, kana, fullwidth symbols, and emoji take two cells. Aligning with chars().count() always misaligns a table that contains Hangul — not occasionally, but by one cell for every Hangul character in a column.

Unicode East Asian Width W and F count as width 2; combining characters and zero-width control characters count as width 0. The core has no dependencies, so it carries its own range tables (AGENTS.md). The wide ranges are few enough that hardcoding them stays maintainable.

Functions§

char_width
The display width of one character: 0, 1, or 2.
is_cjk
Whether this is a “CJK character” as the CJK-adjacent emphasis policy sees it.
str_width
The display width of a string.