Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

true-color detection #90

Open
adamyg opened this issue Oct 21, 2024 · 0 comments
Open

true-color detection #90

adamyg opened this issue Oct 21, 2024 · 0 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@adamyg
Copy link
Owner

adamyg commented Oct 21, 2024

Consider true-color detection option, set rgb then inquire result.

Querying The Terminal

In an interactive program that can read terminal responses, a more reliable method is available, that is transparent to sudo & ssh.

Simply try sending a truecolor value to the terminal, followed by a query to ask what color it currently has. If the response indicates the same color as was just set, then truecolor is supported.

If the response indicates an 8-bit color, or does not indicate a color, or if no response is forthcoming within a few centiseconds, then assume that truecolor is not supported.

$ ( printf '\e[48:2:1:2:3m\eP$qm\e\\' ; xxd -g1 )
^[P1$r48:2:1:2:3m^[\
00000000: 1b 50 31 24 72 34 38 3a 32 3a 31 3a 32 3a 33 6d  .P1$r48:2:1:2:3m

Here we set the background color to RGB(1,2,3) - an unlikely default choice - and request the value that we just set. The response comes back that the request was understood (1), and that the color is indeed 48:2:1:2:3. This tells us also that the terminal supports the colon delimiter. If instead, the terminal did not support truecolor we might see a response like

^[P1$r40m^[\
00000000: 1b 50 31 24 72 34 30 6d 1b 5c 0a              .P1$r40m.\.

This terminal replied that the color is 40 - it has not accepted our request to set 48:2:1:2:3.

^[P0$r^[\
00000000: 1b 50 30 24 72 1b 5c 0a                      .P0$r.\.

This terminal did not even understand the DECRQSS request - its response was CSI+0$r. This does not indicate whether it set the color, but since it doesn't understand how to reply to our request it is unlikely to support truecolor either.

@adamyg adamyg added enhancement New feature or request question Further information is requested labels Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant