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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
ch | string | A single character (may be a grapheme cluster). |
Returns
Section titled “Returns”number
0, 1, or 2.
Example
Section titled “Example”ttyCharWidth("a") // 1ttyCharWidth("文") // 2ttyCharWidth("↗") // 1