termstandard / colors

Color standards for terminal emulators
The Unlicense
1.15k stars 45 forks source link

True color colon syntax #38

Open mintty opened 2 years ago

mintty commented 2 years ago

About Querying the Terminal: the response should actually look like ...;48:2::1:2:3m - note the double colon which allows a position for the optional color space value.

SlySven commented 2 years ago

Yeah, for reference the documentation is in https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-T.416-199303-I!!PDF-E&type=items take a look at page 49 of 77 (confusingly numbered 41!) - unfortunately many interpretations forget about the second sub-parameter after the first one of 2 (or 3 or 4) and it isn't optional unless one is specifying a black which has all of the red, green and blue components as zero! Using a semi-colon as the sub-parameter separator is just so broken as it makes it so very hard to interpret an incoming code sequence...!

kurahaupo commented 2 years ago

(edited; sorry, the first semicolon was a typo) @SlySven Generally one gets eitherCSI 48 : 2 : colourspace : red : green : blue m or CSI 48 ; 2 ; red ; green ; blue m . That is, the colourspace slot depends on which separator is used. The terminals that use : tend to stick more closely to the IEC spec, while those that use ; tend to omit the colourspace & "unnecessary" values.

So in practice, one can read a semicolon-separated sequence simply by looking at each element to determine how many additional elements to consume:

I grant you that this isn't particularly robust, as it will fail if a new colourspace is introduced with a new code. But if I had to guess, I'd speculate that the next colourspace to be added would be RGBA, so it's probably reasonable to assume that an unknown colourspace takes 4 elements.

mintty commented 2 years ago

There is no hybrid syntax (neither specified nor legacy) where the first separator would be ; and the others : Standard syntax is colon-only, and you would need to swallow as many sub-parameters as are separated with colons, whether their number fits the type or not. Heuristics would apply to legacy semicolon syntax only.