Dust::UnicodeWidth
Display width of a string in terminal columns.
Not a full port of the unicode-width crate: the ranges below cover the
East Asian Wide/Fullwidth blocks and the emoji blocks, which is what dust's
alignment actually needs, plus the zero width combining marks.
Constants
EMOJI_BASES = [{35, 35}, {42, 42}, {48, 57}, {169, 169}, {174, 174}, {8252, 8252}, {8265, 8265}, {8482, 8482}, {8505, 8505}, {8592, 8703}, {8960, 9215}, {9312, 9471}, {9632, 10175}, {10548, 10549}, {11008, 11263}, {12336, 12336}, {12349, 12349}, {12951, 12951}, {12953, 12953}] of Tuple(Int32, Int32)
Symbols that take an emoji presentation with U+FE0F. Anything outside these blocks is left alone by the variation selector.
JOINER = 8205
VARIATION_16 = 65039
U+FE0F asks for the emoji (two column) presentation of the symbol before it.
WIDE_RANGES = [{4352, 4447}, {11904, 12350}, {12353, 13311}, {13312, 19903}, {19968, 40959}, {40960, 42191}, {43360, 43391}, {44032, 55203}, {63744, 64255}, {65040, 65049}, {65072, 65135}, {65280, 65376}, {65504, 65510}, {94208, 100343}, {110592, 111359}, {126980, 126980}, {127183, 127183}, {127374, 127374}, {127377, 127386}, {127488, 127776}, {127789, 127797}, {127799, 127868}, {127870, 127891}, {127904, 127946}, {127951, 127955}, {127968, 127984}, {127988, 127988}, {127992, 128062}, {128064, 128064}, {128066, 128252}, {128255, 128317}, {128331, 128334}, {128336, 128359}, {128378, 128378}, {128405, 128406}, {128420, 128420}, {128507, 128591}, {128640, 128709}, {128716, 128716}, {128720, 128722}, {128725, 128727}, {128733, 128735}, {128747, 128748}, {128756, 128764}, {128992, 129003}, {129008, 129008}, {129292, 129338}, {129340, 129349}, {129351, 129535}, {129648, 129791}, {131072, 196605}, {196608, 262141}] of Tuple(Int32, Int32)
ZERO_RANGES = [{768, 879}, {1155, 1161}, {1425, 1469}, {1552, 1562}, {1611, 1631}, {1750, 1756}, {3633, 3633}, {3636, 3642}, {3655, 3662}, {8203, 8207}, {8232, 8238}, {8400, 8432}, {8419, 8419}, {65024, 65039}, {65056, 65071}, {65279, 65279}, {6832, 6911}, {7616, 7679}, {917760, 917999}] of Tuple(Int32, Int32)
Instance methods
char_width(char : Char) : Int32
Sourceeach_cluster(string : String, & : Array(Char), Int32 -> )
Yields each display cluster: its characters and how many columns it takes.
Emoji joined with a zero width joiner (👩💻) render as one two column
cluster rather than as three separate glyphs.
width(string : String) : Int32
Source