Feature Request: Support "direct" (24bit) escape sequences
nevans opened this issue · comments
24-bit color RGB escape sequences are also sometimes referred to as "TrueColor"
Example use case: Sometimes logfiles use 24bit RGB color escape sequences to make it easy to identify different entities at a glance e.g. assign different email addresses to different RGB values using a checksum.
...or sometimes people just like to do crazy terminal hacks, e.g:
convert -thumbnail "$(tput cols)" "$image" txt:- |
awk -F '[)(,:]' '/white/{$9=$10=$11=255}!/^#/{if($2%2){printf"\033[48;2;"pR[$1]";"pG[$1]";"pB[$1]";38;2;"$9";"$10";"$11"m▄"}else{pR[$1]=$9;pG[$1]=$10;pB[$1]=$11}}'
tput sgr0
Either way, supporting the entire RGB color space would be useful. 🙁
The escape sequences used by almost all terminals with 24-bit RGB support are:
ESC[38;2;⟨r⟩;⟨g⟩;⟨b⟩m => Select RGB foreground color
ESC[48;2;⟨r⟩;⟨g⟩;⟨b⟩m => Select RGB background color
E.g. see infocmp tmux-direct | grep seta
FWIW, my primary use-case for this is grafana/grafana#35588
... but it is occasionally fun to pipe jpgs through imagemagick and awk to output inside a terminal window. ;)
I was looking for something similar although for 8-bit colors rather than 24-bit color, for example:
ansicolor.parse('\u001b[38;5;9merror[E0423]\u001b[0m')
The resulting span seems to be parsed with an unnamed field (??) and undefined: true
{
"css": "",
"text": "error[E0423]",
"code": {
"value": 0
},
"": true,
"undefined": true
}
I suppose ideally the API for this could match the 24-bit color API in terms of accessing the output RGB, since the values can be derived from the 8-bit color value if it doesn't map to one of the standard 16 base colors (e.g. https://stackoverflow.com/a/27165165/14436105)