Skip to content

ttyCharWidth

function ttyCharWidth(ch): number;

Compute the display width of a single character in a terminal cell.

Fast-paths ASCII (always 1) and uses codepointWidth for non-ASCII. Used by the diff engine for cursor tracking.

ParameterTypeDescription
chstringA single character (may be a grapheme cluster).

number

0, 1, or 2.

ttyCharWidth("a") // 1
ttyCharWidth("") // 2
ttyCharWidth("") // 1