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

Detect Windows Terminal as a true color terminal #1200

Closed

Conversation

spenserblack
Copy link
Collaborator

Windows terminal does not seem to set COLORTERM, but it is capable of
the full range of RGB values. This detects if the WT_SESSION
environment variable is set to determine if this session is in Windows
Terminal.

Fixes #1199

Windows terminal does not seem to set `COLORTERM`, but it is capable of
the full range of RGB values. This detects if the `WT_SESSION`
environment variable is set to determine if this session is in Windows
Terminal.
@spenserblack
Copy link
Collaborator Author

spenserblack commented Nov 2, 2023

So I just dove down a rabbit hole (microsoft/terminal#11057) and what I found interesting is that WT_SESSION isn't 100% reliable (microsoft/terminal#11057 (comment), microsoft/terminal#13006). Basically, if Windows Terminal is not the first executable, but cmd.exe or powershell.exe starts up and then "attaches Windows Terminal to itself," then this environment variable isn't set.

@o2sh
Copy link
Owner

o2sh commented Nov 2, 2023

This one might be tricky. AFAIK, the only way to determine if a terminal supports truecolor is by using heuristics on environment variables, which can be somewhat 'hacky.'

I've discovered this crate called supports-color, which is quite popular and should meet our needs. Unfortunately, according to the code, it states that all terminals in Windows do not support truecolor 🤔, which is not accurate.

This crate is based on another project with the same name: https://www.npmjs.com/package/supports-color, and it actually does what we need. It returns 'truecolor' for Windows after a certain version chalk/supports-color#71

@spenserblack
Copy link
Collaborator Author

t returns 'truecolor' for Windows after a certain version chalk/supports-color#71

In that terminal issue one they did recommend just assuming that Windows can support true color as long as we're running on 10 (microsoft/terminal#11057 (comment)), so that certainly could be a valid option. But at the same time, I ran the custom_colors example from owo-colors on "plain" command prompt on Windows 10 and got results that weren't pretty 🤷

@spenserblack
Copy link
Collaborator Author

After a bit of digging, I've found that GitHub checks if the terminal is a virtual terminal, and then falls back to COLORTERM:
https://github.com/cli/go-gh/blob/debe718854c4ef26135c2348fd91db360fe5bae8/pkg/term/env.go#L72C47-L72C47
https://github.com/cli/go-gh/blob/debe718854c4ef26135c2348fd91db360fe5bae8/pkg/term/console_windows.go#L12-L18

Whatever the GitHub CLI does could be the way to go. It certainly has plenty of user testing.

@o2sh
Copy link
Owner

o2sh commented Nov 3, 2023

FYI, I've opened an issue on supports-color 👉 zkat/supports-color#17

@o2sh
Copy link
Owner

o2sh commented Jan 7, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@o2sh o2sh added the stale label Jan 7, 2024
@spenserblack
Copy link
Collaborator Author

spenserblack commented Jan 7, 2024

This is a bit of a stretch, but colored, with built-in color support checking, is now maintained again. IDK if we're interested in switching back and requesting improved Windows support there.

@o2sh
Copy link
Owner

o2sh commented Jan 7, 2024

Could be worth it, especially with colored-rs/colored#90 which could simplify the language template.

@o2sh o2sh removed the stale label Jan 14, 2024
@o2sh
Copy link
Owner

o2sh commented Mar 17, 2024

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@o2sh o2sh added the stale label Mar 17, 2024
@o2sh o2sh closed this Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

True color support not recognized on Windows Terminal
2 participants