4 ms·
Most terminal emulators date back to a time when one byte of input occupied one character-cell on-screen. Since Unicode arrived with combining characters, termi
by thristian 6y ago
Most terminal emulators date back to a time when one byte of input occupied one character-cell on-screen. Since Unicode arrived with combining characters, terminals have adapted to N bytes of input occupying one character-cell, or under special circumstances (Chinese characters, emoji) two character-cells.
Proper ligature support requires terminals to support N bytes of input mapping to M character cells... and unlike the N:1 or N:2 cases, the N:M case doesn't allow a hard-coded list of how many cells an input string covers, it varies from font to font. And that risks software designed for one font breaking in a terminal that uses a different font, if it has a different set of ligatures, or the ligatures are different sizes.
- wezfurlong 6y agoYeah, this stuff is hard. The approach used in wezterm is to use unicode graphemes for cells, and use the unicode width of the grapheme to decide whether a given cell is double-width. Ligatures are handled at rendering time, partly because the terminal emulation and model layer doesn't know about fonts (it can run "headless" in a multiplexer where there are no fonts), and partly because the shaper library doesn't output information about cells but rather about which glyphs to render in which positions--that information doesn't easily map to the terminal cell model. For extra pain, some font designers have ligatured sequences that map to a single glyph that may be several cells wide, while others use alternative glyph fragments for each component of the ligature, and others may emit two blank glyphs, followed by a triple wide glyph with a negative x offset of almost two blank glyphs in width. It's difficult to map this information to cells.
- sime2009 6y agoThe problem actually existed before Unicode appeared. Terminals which supported Chinese, Japanese, or Korean characters have had to deal with 2 cell wide glyphs, even for text encodings which use 1 byte per glyph. If you see the term "full width" character in old terminal related specs and documents, they are talking about 2 cell CJK glyphs/characters.