Terminal display width of text, in columns.
Width is derived from Unicode East Asian Width (UAX #11 W and F are two
columns) combined with Emoji Presentation (UTS #51), and from the general
categories that occupy no column at all — non-spacing combining marks,
format characters, and C0/C1 controls.
Measurement is per grapheme cluster, not per codepoint. A cluster's width is
the width of its base character; trailing combining marks, skin-tone
modifiers, and regional-indicator continuations add nothing. Variation
selectors override the base: U+FE0F forces emoji presentation (two columns)
and U+FE0E forces text presentation (one column). A cluster joined by
U+200D (ZWJ) renders as a single emoji and measures two columns.
This module answers "how many columns" only. It performs no bidirectional reordering, so right-to-left text is measured correctly but still emitted in logical order.
Summary
Functions
Display width in columns of a single codepoint.
Display width in columns of a single grapheme cluster.
Whether every byte is printable ASCII, over which display width equals byte size.
Display width in columns of a string.
Functions
@spec codepoint(non_neg_integer()) :: non_neg_integer()
Display width in columns of a single codepoint.
@spec grapheme(String.t()) :: non_neg_integer()
Display width in columns of a single grapheme cluster.
The cluster's base character determines the width; combining marks, skin-tone modifiers and regional-indicator continuations add nothing.
Whether every byte is printable ASCII, over which display width equals byte size.
@spec string(String.t()) :: non_neg_integer()
Display width in columns of a string.
Pure printable-ASCII input is measured by byte size, which is exact over that range; anything else is measured per grapheme cluster.