CRT::Ansi::DisplayWidth
Constants
TABLES = begin
tables = {"COMBINING" => [] of ::Tuple(Int32, Int32), "DOUBLEWIDTH" => [] of ::Tuple(Int32, Int32), "AMBIGUOUS" => [] of ::Tuple(Int32, Int32), "NARROW" => [] of ::Tuple(Int32, Int32), "EMOJI" => [] of ::Tuple(Int32, Int32)}
current = nil
({{ read_file("/tmp/tmp.hNaJjc/src/src/crt/ansi/data/widths.txt") }}).each_line do |line|
line = line.strip
if line.empty? || (line.starts_with?('#'))
next
end
if tables.has_key?(line)
current = tables[line]
elsif target = current
parts = line.split
if parts.size == 2
target << {parts[0].to_i(16), parts[1].to_i(16)}
end
end
end
tables
end
Width tables parsed from data/widths.txt at compile time. The file is generated by scripts/generate_width_tables.cr from Unicode consortium EastAsianWidth.txt and emoji-data.txt.
ZERO_WIDTH_JOINER = 8205
ZERO_WIDTH_NON_JOINER = 8204
Instance methods
Returns the grapheme index at or before the given absolute display column.
Returns the maximum display width across an array of strings.
Returns the display width of a string by summing grapheme cluster widths.