Documentation
¶
Overview ¶
Package charwidth answers the terminal display width of Unicode codepoints and grapheme clusters. It is the single source of truth shared by the SGR-aware ansi package and the plain text-editing primitives, and it is the Go port of Ruby's lib/char_width.rb.
Deliberately dependency-free apart from grapheme segmentation: no terminal, renderer, or SGR knowledge. Given a bare rune or grapheme it answers 0, 1, or 2 cells.
The tables below are transcribed from the Ruby kernel rather than taken from a general width library, because the Ruby answer is the oracle the rest of the port must agree with. In particular text-presentation symbols (⚠ U+26A0, ✓ U+2713) stay one cell, which is how terminals actually render them without a U+FE0F selector.
Index ¶
Constants ¶
const VariationSelector = 0xFE0F
VariationSelector is U+FE0F, the emoji presentation selector.
Variables ¶
This section is empty.
Functions ¶
func Cluster ¶
Cluster reports the display width of one grapheme cluster. A U+FE0F selector forces emoji (wide) presentation; otherwise the first visible codepoint sets the width and trailing combining marks add nothing.
func Clusters ¶
Clusters splits s into UAX #29 extended grapheme clusters, the same units Ruby's String#each_grapheme_cluster yields.
func FirstCluster ¶
FirstCluster returns the leading grapheme cluster of s and the remainder.
Types ¶
This section is empty.