Documentation
¶
Overview ¶
Package textwidth measures how many terminal columns a string occupies.
The diagram engine sized every box, centered every label and placed every edge caption with len(s) — the byte count. That is the display width only for ASCII. A label carrying an emoji measured four columns per glyph and drew two, so its box came out too wide and its text sat off-center; CJK had the opposite problem, measuring one column per glyph and drawing two, so the text overran its border.
The rules implemented here are the ones that matter for diagram labels: combining marks and zero-width joiners take no space, East Asian Wide and Fullwidth characters and emoji take two columns, and everything else takes one. This is a deliberate subset of UAX #11 rather than the whole table — enough to place a label correctly, and small enough that this package keeps its property of depending on nothing outside the standard library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cell ¶
Cell is one rune together with the columns it occupies.
func Split ¶
Split walks s and reports each rune with the width it will actually render at, resolving the one thing a per-rune answer cannot: a variation selector.
U+FE0F asks for emoji presentation, which makes an otherwise narrow symbol render two columns wide. It carries no width of its own, so measuring rune by rune misses it — "🛠️" is two columns and "🛠" is one, and the only difference between them is the selector that follows.