struct TermBuf::Unicode::WidthPolicy

Overview

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.

Defined in:

termbuf/unicode/policy.cr

Constant Summary

DEFAULT = new

What a current terminal does.

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

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

Constructors

Instance Method Summary

Constructor Detail

def self.new(ambiguous : Int32 = 1, emoji_presentation : Bool = true, joined_emoji : Bool = true, regional_indicators : Bool = true, spacing_marks : Bool = true) #

[View source]

Instance Method Detail

def ambiguous : Int32 #

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.


[View source]
def copy_with(ambiguous : Int32 = @ambiguous, emoji_presentation : Bool = @emoji_presentation, joined_emoji : Bool = @joined_emoji, regional_indicators : Bool = @regional_indicators, spacing_marks : Bool = @spacing_marks) : WidthPolicy #

[View source]
def emoji_presentation? : Bool #

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


[View source]
def 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.


[View source]
def joined_emoji? : Bool #

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.


[View source]
def regional_indicators? : Bool #

Whether a pair of regional indicators collapses to one flag.


[View source]
def spacing_marks? : Bool #

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


[View source]
def to_s(io : IO) : Nil #
Description copied from struct Struct

Same as #inspect(io).


[View source]
def with(name : String, enabled : Bool) : WidthPolicy #

The flags by the names TERMBUF_WIDTHS uses.


[View source]