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

available_color_count is wrong on Windows #882

Closed
heaths opened this issue May 4, 2024 · 1 comment · Fixed by #885
Closed

available_color_count is wrong on Windows #882

heaths opened this issue May 4, 2024 · 1 comment · Fixed by #885

Comments

@heaths
Copy link
Contributor

heaths commented May 4, 2024

Describe the bug
Windows pseudo-TTYs support true color, yes crossterm::style::available_color_count reports 8. You need to query if you're in a pseudo-terminal which, BTW, means you can do just about any VT100 sequence including keyboard support, though I'm not sure what "progressive keyboard support" means.

A better detection of what colors are supported can be found at https://github.com/cli/go-gh/blob/dbd982eba2a041d88d398cce01cb708c4c3503f7/pkg/term/env.go#L70-L72. I worked on that for the GitHub CLI (was refactored into cli/go-gh from cli/cli) along with colleagues on the Windows terminal team that own conhost and conpty - both of which support VT100 sequences since some version of Windows 10 (TH2, maybe? Anything older isn't supported anyway.)

To Reproduce
Steps to reproduce the behavior:

  1. Write a simple bin:
    fn main() {
        println!("{}", crossterm::style::available_color_count());
    }
  2. Run cargo run

Expected behavior
256 is printed to stdout.

OS

  • Windows 11

Terminal/Console

  • Windows Terminal; though, conhost.exe supports this - which cmd.exe and powershell.exe/pwsh.exe use by default unless you default to wt.exe, which uses conpty.exe. Effectively, conpty is dead on built-in terminals and shells.
@heaths
Copy link
Contributor Author

heaths commented May 4, 2024

For that matter, just checking TERM is not sufficient on any platform. See helper functions used by the cli/go-ch link above: https://github.com/cli/go-gh/blob/dbd982eba2a041d88d398cce01cb708c4c3503f7/pkg/term/env.go#L170-L184.

heaths added a commit to heaths/crossterm that referenced this issue May 4, 2024
heaths added a commit to heaths/crossterm that referenced this issue May 4, 2024
heaths added a commit to heaths/crossterm that referenced this issue May 4, 2024
heaths added a commit to heaths/crossterm that referenced this issue May 7, 2024
Fixes crossterm-rs#882 by improving `style::available_color_count()`:
- Checks ANSI support on Windows.
- Uses the COLORTERM environment variable and falls back to the TERM environment variable.
- Supports "xterm-24bit" and "truecolor" values which return `u16::MAX`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant