Comment by JdeBP
Alas, it's not finished. You've made the mistakes that all of us have made, and haven't caught up with us, must of us having fixed those mistakes, a few years back when implementing 24-bit RGB was in vogue.
This is not, as the function name suggests, a colon, but per ITU/IEC T.416 it should be:
https://github.com/cosmos72/twin/blob/truecolor/server/hw/hw...
And not only should this have colons too, but per ITU/IEC T.416 there's a colour space parameter that goes in there:
https://github.com/cosmos72/twin/blob/truecolor/server/hw/hw...
The unfortunate part is that when rendering to a terminal, you don't have any available mechanism apart from hand-decoding the family part of the TERM environment variable, and knowing who made which mistakes, to determine which of the 7 possible colour mechanisms are supported. They are:
1. ECMA-48 standard 8 colour, SGRs 30 to 37, 39, 40 to 47, and 49
2. AIXTerm 16 colour, ECMA-48 plus SGRs 90 to 97 and 100 to 107
3. XTerm 256 colour, ITU T.416 done wrongly with SGR 38;5;n and SGR 48;5;n
4. XTerm 256 colour corrected, ITU T.416 done right with SGR 38:5:n and SGR 48:5:n
5. 24-bit colour take 1, ITU T.416 done wrongly with SGR 38;2;r;g;b and SGR 48;2;r;g;b
6. 24-bit colour take 2, ITU T.416 done wrongly with SGR 38:2:r:g:b and SGR 48:2:r:g:b
7. 24-bit colour take 3, ITU T.416 done right with SGR 38:2::r:g:b::: and SGR 48:2::r:g:b:::
Few people support 4, and although quite a lot of us have finally got to supporting 7 it isn't quite universal. Egmont Koblinger, I, and others have been spreading the word where we can over the last few years.
This is where I was at in 2019:
https://github.com/jdebp/nosh/blob/trunk/source/TerminalCapa...
There a few updates to that that are going to come out in 1.41, but when it comes to colour they're mainly things like recognizing the "ms-terminal" and "netbsd6" terminal types in the right places.
Yep, I am well aware of the `;` vs `:` confusion in both 256 color and 24-bit color control sequences.
Short of hand-coding "which terminal supports which variant" I do not know any standard mechanism to detect that (beyond the well-known $TERM=...-256color and $COLORTERM=truecolor or $COLORTERM=24bit)
I guess I'll have to add command line options to choose among the variants 1...7 you helpfully listed above.
My main use it to render twin directly on X11, which avoids all these issues, and while rendering inside another terminal is important and is not going away, I am OK with a few minor color-related limitations (note: limitations, not bugs) in such setup, especially if the other terminal does not follow the relevant standards