Curly and colored underlines
See original GitHub issueThis is originally a feature of Kitty, now also adopted by VTE (GNOME Terminal and friends). Technically two separate features, but they mostly make sense together, e.g. for spell checking.
Apparently vim and neovim have already / are about to support these, see e.g. vim undercurl, vim color, neovim.
The new SGR 4:3
(\e[4:3m
) attribute, strictly with a colon as separator, was introduced to start a curly underline.
In the mean time, 4:0
, 4:1
and 4:2
were also added as aliases for the standard 24
(turn off all kinds of underlining), 4
(single underline) and 21
(double underline), respectively.
At some point in the future, probably 4:4
and 4:5
could also stand for dotted and dashed underlines in some order (these are the five types of underlining supported by HTML/CSS).
The new SGR 58
and 59
sequences specify the color of the underline, following the pattern of 38
and 39
. That is, 58;5;idx
for an entry of the 256-color palette, or 58;2;r;g;b
for direct RGB. There’s no shortcut notation for the first 16 entries (corresponding to SGR 30-37 and 90-97), use the 256-color mode with indices of 0-15 instead.
59
reverts to the default, that is, the underline’s color auto-following the text color.
In case you’re short of bits, I believe it’s okay to drop some precision, e.g. store only 4 bits per color channel. We were also considering this in the VTE bug.
Update: In VTE we ended up approximating the truecolor underline to 4+5+4 bits (R, G, B respectively). This means: 8+8+8+1 = 25 bits for foreground (in addition to truecolor, we have to be able to denote palette and default values too). Same for background. 4+5+4+1 = 14 bits for underline (again, an extra bit to denote palette and default values). That’s a total of 64 bits for the colors, stored in an int64 (bold, italic etc. are additional bits are next to this in another variable). With multiplication instead of bitpacking, it could have been 5+5+5 bits for the underline. Of couse it’s not a necessity to put all the color and no other attributes in the same integer, we just decided it’s nice this way (and results in some performance improvement).
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:22 (13 by maintainers)
Top GitHub Comments
Early self-drawing approach with DOM renderer:
The underline is actually a 3px high background image on the line, thus text will print on top. It seems easier to get complex underlines working with this approach, will see.
(As per https://github.com/kovidgoyal/kitty/issues/226#issuecomment-381665023, mintty decided that
4:4
is dotted underline, and4:5
is dashed.)