Re-enable label colors for issue list#4106
Conversation
|
As noted here, we might consider a couple alternatives if returning a closure for truncating labels isn't desirable:
|
|
In case it comes up, this new |
|
I updated the PR to colorize (if supported TTY) the label separators as well |
mislav
left a comment
There was a problem hiding this comment.
This is a pretty great use of the new DisplayWidth and Truncate implementations that pay respect to ANSI sequences 😍
One thing that I would like us to also think about before enabling label color in other places in gh is what happens to labels whose color is very dark? Currently they will get rendered with dark color on a dark background. This, of course, affects the gh issue view command too, but if we roll out the colors to issue list as well then we've made the problem more visible.
|
I was considering that last night and thought maybe any R, G, and/or B component beyond a certain threshold could trigger a lighter background, but for people that have light backgrounds the reverse is a problem (and is today) as well. I did some searching and can't find a reliable cross-platform way of querying background colors or even default colors. Could instead take a page from git itself and add a FWIW, the random color generator for labels seems to favor more pastels and may already have some limit that randomly-chosen colors are rarely dark. Of course, people can always set them themselves. For the Azure SDK, we actually use color codes with intent, but still tend to favor medium hues since they look good on light or dark background. |
|
To note, I love the colored labels because my team uses colors with intent. I can better identify issues at a glance. I agree there's already a problem with colors in the console, but more and more CLIs across platforms are doing it to the point I doubt a significant number of people have light-colored terminal backgrounds. I imagine it would get more difficult to use various CLIs and few I've seen support user-defined color schemes. |
For rendering Markdown we do query the terminal for whether it has light or dark background, but this is brittle and doesn't work with Dark mode on macOS (Dark mode Terminal.app reports that it has a light background even though the colors are inverted per Dark mode) cli/pkg/iostreams/iostreams.go Line 77 in c39dd1e We also allow the user to override the dark/light style with GLAMOUR_STYLE, but it might be confusing if that environment variable starts affecting more than just Markdown rendering.
You can already disable color per invocation with
That's true! In my experience, most colors for existing labels render really nicely out of the box. I haven't tested with light backgrounds or on Windows, though. (PowerShell default background color is blue, if I recall correctly.) |
Yes, but with Terminal going in-box for Windows 11, I wonder how much it'll matter; though, I admit I don't remember if the default Windows PowerShell (PowerShell nee "PowerShell Core" defaults to black background) profile for Terminal is blue or black. Hopefully, too, more people are using PowerShell over Windows PowerShell since the latter is effectively in sustained engineering. Still, as you noted: you already have label colors elsewhere. While |
See that's tricky. I also want everyone to use Windows Terminal instead of powershell.exe and cmd.exe. But I don't know how many developers are actually doing that. Furthermore, I personally wasn't able to install Windows Terminal from the Windows Store for months (installing would fail without visible error) until I spent 1h on the phone with Windows Support this week. |
|
It's a fair point, but as you pointed out previously, color is already a problem. Here's powershell.exe on my system with defaults (I used to change the default to black before switching to Terminal): Some of the colors already don't pop, including the default grays, but still legible. My main point was that color from any CLI for any terminal can already be a problem that people in that predicament have probably already worked around, and I'll leave it at that. 🙂 If you're still interested and have feedback specific to the implementation I'm happy to make changes. It's primarily just a revert, though I had to add |
|
I appreciate your contribution and thoughts. This will likely be accepted, I just need to ruminate about this for a bit and run it by my team. Thank you! |
|
I have pushed updates to:
Now I wonder should we have fallback color (other than default foreground color) for terminals that don't support truecolor 🤔 |
|
@heaths And before my changes you've seen label colors in Windows Terminal? It looks like Windows Terminal doesn't set either TERM nor COLORTERM variables, so I'm wondering how it assumed that the terminal even supported 256 colors before my changes. |
heaths
left a comment
There was a problem hiding this comment.
From https://github.com/gookit/color, I found a link to https://github.com/termstandard/colors (via a gist that recommends that repo) that has another way to detect true color, but not sure how well that will work in practice. It also makes mention that several terminals do approximate.
As mentioned in previous comments, people can always disable color entirely if it's a problem, which with existing commands it may have been. Or maybe true colors were approximated and they never noticed.
Checking out my last commit - 2433eeb - no, it didn't (I've been developing this in WSL2/Ubuntu since it's faster): But if I do set That said, trying this out in cmd.exe (the shell and terminal) shows that colors are effectively ignored, and I wonder if all (major, at least) terminals do this. As long as ANSI escape sequences have been a thing, any unrecognized sequences are supposed to be ignored anyway: |
|
For some context, here's been one discussion about general detection but As a compromise, would it make sense to detect other heuristics like checking for |
- Assume 256-color by default on all Windows - When in Windows Terminal, assume truecolor
It seems that in powershell.exe terminal, if a line has exactly as many characters as available viewport width, it will wrap. So on Windows (but not under Windows Terminal) assume that the available width for table output is one character narrower.
heaths
left a comment
There was a problem hiding this comment.
Mainly, WT_SESSION is still defined for WSL(2) because Windows Terminal defines it regardless of the shell or platform running within it. I think just adding a check for it in the old color.go would be best, but the availableWidth check makes an incorrect assumption and would affect linux shells as well.
pkg/iostreams/color_windows.go
Outdated
|
|
||
| func IsTrueColorSupported() bool { | ||
| // Windows Terminal supports true color. | ||
| return os.Getenv("WT_SESSION") != "" |
There was a problem hiding this comment.
This isn't Windows-specific. Windows Terminal defines this environment variable in WSL2 as well, despite TERM being defined as xterm-256color. I think either how you had it is fine (other Windows terminals may define TERM, and hopefully WT will as well per the link I posted), or just add a check for WT_SESSION:
utils/table_printer_windows.go
Outdated
| ) | ||
|
|
||
| func (t *ttyTablePrinter) availableWidth() int { | ||
| if os.Getenv("WT_SESSION") == "" { |
There was a problem hiding this comment.
As mentioned above, WT defines this. It's not specific to powershell.exe which, if run directly, doesn't run in WT (though it may in Windows 11 if WT is set as the default terminal).
cmd.exe, powershell.exe, and pwsh.exe by default run in conhost.exe, and this problem - which I can repro - appears to happen only there (though, to be frank, I don't have anything other than conhost and WT installed). But with WT, I've never seen this.
So given all that, the check for WT_SESSION for truecolor should be platform agnostic, but if you wanted to solve this problem here, perhaps check that the environment windir is defined byt not WT_SESSION. Short of getting the current process name - certainly another option - that would probably be easiest.
There was a problem hiding this comment.
Sorry, I misread this as it was checking for empty. This is probably fine then. Checking for windir in this case would be pointless. If there are any other terminals people are running in Windows they are only losing a single block char. Anything popular enough could always be added to this.
|
I don't know if you're already started, but I'm fixing up the PR (and the build break) and can push another commit. |
|
Please do not use Detecting I know that I am asking for you to do nothing to detect color support on Windows, and that that will cause some trouble. However, there only one version of Windows 10 still in support that supports SGR but not true color SGR. I'm curious -- is the problem actually that this library does not turn on Going forward, and in general, any VT feature that is supported by Windows Terminal will in the fullness of time become supported by the Windows Console. They share a VT parser. |
|
Thanks for reviewing! Don't worry about fixing the break; I will push a fix tomorrow. I now recognize that @DHowett Yeah, in retrospect I feel queasy about relying on WT_SESSION for anything. I will undo that as well, and likely just assume that on Windows we have truecolor support. I'm not familiar with ENABLE_VIRTUAL_TERMINAL_PROCESSING. What is that, and is the responsibility of the app to turn it on or of the user? |
|
@DHowett thanks for the recommendations, but I don't think @mislav you can call the Windows-native I agree if there's a better way it's worth doing. As for assuming truecolor - basically going back to the original color.go, it's seemingly been working in |
|
Thanks for the info on the console modes -- you beat me to it!
That's not what I'm recommending 😄. After all, Terminal has to support Windows 7 as well! We're well aware of the price we pay for compatibility. I think the most correct thing to do¹ is to try to enable ¹ There is a small portion of Windows devices running 10.0.10240 that will accept this flag but do not support true color SGR. That's why it's only "most" correct, not completely correct! 😁 |
|
Thanks, @DHowett. I'm working on these changes now. |
|
I found mattn/go-isatty#59 that may be a request for this already. Don't know if it's worth waiting to confirm or just implement locally, though a TODO in code may be sufficient for now. The brunt of the code necessary is arleady there, and |
|
There's a number of ways to do this. I see from here that we're already using mattn/go-colorable to call Talking with @DHowett offline, in this case probably the only reason we care if it's enabled (and can be enabled) is to know if we can use 256color or truecolor. Reading the environment variables is still worth it since other terminals - like cygwin - could be in use on Windows. |
|
FWIW, |
|
In the course of testing on Windows 10 and linux (WSL2/Ubuntu 18.04), I found that - unrelated to this change (occurs with gh 1.14) - |
|
@heaths Thanks for the updates on this PR! It looks great. I will review in depth and merge on Monday.
Even though that environment variable forces color across all gh, the "is the output a tty?" bit is still off if you've piped stdout to anywhere. In that case, commands like We're adding an environment variable that will force tty-style output even when redirected: #4146 |
Makes sense. It wasn't really a problem - just unexpected. I can't think of any reason - apart from maybe debugging an output template with color or something e.g., piping to |
Exactly. And when piping to a program that will ultimately render the content to a terminal, like |
pkg/iostreams/iostreams.go
Outdated
| if stdoutIsTTY { | ||
| // also enables truecolor support for NewColorable below | ||
| if err := enableVirtualTerminalProcessing(os.Stdout); err == nil { | ||
| hasTrueColor = true |
There was a problem hiding this comment.
This looks like it unconditionally considers that every non-Windows terminal supports truecolor. We will rely on TERM and COLORTERM variables instead. I'll push an update
* Re-enable label colors for issue list * Drop parentheses wrapping issue labels * Support ANSI escape codes in TablePrinter cells * Switch to a Truncate implementation that correctly measures ANSI escape codes * Only output RGB color if terminal has truecolor capabilities * Enable `ENABLE_VIRTUAL_TERMINAL_PROCESSING` on Windows - fixes wrapping issues with full lines and allows truecolor rendering
|
What about the same thing but for |
|
@stalkerg Sorry, right now |









This reverts commit 930ee60
and uses the text.Truncate function from PR #3519 that correctly
measures ANSI escape codes.