struct

TermBuf::Unicode::WidthPolicy

Inherits Struct < Value < Object

Stability: stable — changes only in a major release.

How a particular terminal measures a grapheme cluster.

UAX #29 says where a cluster ends and UAX #11 says how wide a character is. Neither says what a terminal does with four emoji joined by zero width joiners, and terminals disagree: some advance two columns, some eleven. A buffer measuring a cluster differently from the terminal drawing it has every later cell on that row in the wrong place, so the measurement has to come from the terminal rather than from the standard.

WidthProbe fills one of these in by asking. The defaults are what a current terminal does, and what a terminal that answers nothing is assumed to do.

Constants

DEFAULT = new

What a current terminal does.

NAMES = ["ambiguous_wide", "emoji_presentation", "joined_emoji", "joined_emoji_wide", "regional_indicators", "spacing_marks", "conjunct_wide", "conjunct_spacing_adds"] of ::String

Every rule by name, for diagnostics and for TERMBUF_WIDTHS to check against.

Constructors

new(ambiguous : Int32 = 1, emoji_presentation : Bool = true, joined_emoji : Bool = true, joined_emoji_wide : Bool = true, regional_indicators : Bool = true, spacing_marks : Bool = true, conjunct_wide : Bool = true, conjunct_spacing_adds : Bool = false)
Source

Instance methods

ambiguous

Cells an East Asian Ambiguous character takes. One on most terminals, two on a terminal configured for CJK text, and the standard leaves it to the environment.

Source
conjunct_spacing_adds?

Whether a spacing mark beside a conjunct adds a column on top of the two the conjunct already takes, rather than fitting inside them.

क्षि is a conjunct with a vowel sign, and iTerm2 3.6.11 advances three columns for it where ghostty and Terminal.app advance two. Every other rule here tops out at a cell pair; this is the one reading that needs a third cell, and Cell::MAX_WIDTH is as far as any of them may go.

Source
conjunct_wide?

Whether a consonant conjunct joined by a virama is two columns whatever it opens with, rather than as wide as the consonant it starts from.

A conjunct ligates into one glyph, and what a terminal charges for that glyph is its own decision: ghostty and Terminal.app take two, kitty 0.48.2 takes one — क्ष is a single column there, and so is क्षि. The companion of joined_emoji_wide, and the same kind of question.

Source
copy_with(ambiguous : Int32 = @ambiguous, emoji_presentation : Bool = @emoji_presentation, joined_emoji : Bool = @joined_emoji, joined_emoji_wide : Bool = @joined_emoji_wide, regional_indicators : Bool = @regional_indicators, spacing_marks : Bool = @spacing_marks, conjunct_wide : Bool = @conjunct_wide, conjunct_spacing_adds : Bool = @conjunct_spacing_adds) : WidthPolicy
Source
emoji_presentation?

Whether U+FE0F widens a pictograph that would otherwise be text. Without it ☺️ is as narrow as .

Source
enabled?(name : String) : Bool

Whether the rule name is on. ambiguous_wide reads as a flag here even though it is stored as a count.

Source
joined_emoji?

Whether an emoji sequence joined by U+200D collapses to the width of one emoji. Without it the cluster is as wide as its pieces laid end to end.

Source
joined_emoji_wide?

Whether a collapsed joined sequence is two columns whatever it opens with, rather than as wide as the code point it starts from.

Ghostty, kitty and tmux draw two for a weight lifter joined to a female sign, which opens with a narrow pictograph. iTerm2 3.6.11 draws one, and it is alone in that among the terminals surveyed — see measurements/survey/. It is not a Quirk: nothing is broken by it, and a buffer told about it lays the row out correctly.

Source
regional_indicators?

Whether a pair of regional indicators collapses to one flag.

Source
spacing_marks?

Whether a spacing mark takes a cell beside its base rather than none.

Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source
with(name : String, enabled : Bool) : WidthPolicy

The flags by the names TERMBUF_WIDTHS uses.

Source