termstandard / colors

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

General purpose command to query for color support programatically #36

Open BridgeAR opened 2 years ago

BridgeAR commented 2 years ago

I would like to discuss a similar command as DECRQSS that would be recommended to be implemented by commonly used terminals across different OS.

That way there would be a reliable way to detect actual color support. For now it's not reliable at all by checking for environment variables.

I did not yet think of an ideal solution and would first like to know if there's interest in drafting such command.

eabase commented 2 years ago

@BridgeAR Can you link to info about that DECRQSS?

kurahaupo commented 2 years ago

@eabase In the Xterm escape sequence documentation it describes the general form as:

Request Status String DECRQSS

DCS $ q Pt ST

Pt Designation
" q DECSCA
" p DECSCL
r DECSTBM
m SGR

Xterm responds with

DCS 1 $ r Pt ST

for valid requests, replacing the Pt with the corresponding CSI string, or

DCS 0 $ r Pt ST

for invalid requests.

The original Xterm documentation used the convention of P denoting a parameter string, with two sub-forms P1 ... P9 being an array of numeric parameters; and Pt meaning any byte sequence excluding BEL and ST.

Unfortunately the version on that page has lost the subscript and italicization so it just looks like Pt. Where it mentions "the first parameter", that's Pt within the DECRQSS sequence.

Where it mentions "the corresponding CSI string", I think it simply means the Pt parameter as supplied.

kurahaupo commented 2 years ago

Example of DECRQSS:

$ ( echo "Wait 2 seconds then hit ^D^D^D"
>   stty -echo
>   printf '\eP$qm\e\\'
>   hd
>   stty echo )
Wait 2 seconds then hit ^D^D^D
00000000  1b 50 31 24 72 30 6d 1b  5c                       |.P1$r0m.\|
00000009

or

$ ( echo "Wait 2 seconds then hit ^D^D^D"
>   stty -echo
>   printf '\eP$qq\e\\'
>   hd
>   stty echo )
Wait 2 seconds then hit ^D^D^D
00000000  18                                                |.|
00000001