SGR 1 and SGR 8 don't work when adjusting lightness of indistinguishable text #16091

Closed
opened 2026-01-31 04:57:19 +00:00 by claunia · 6 comments
Owner

Originally created by @j4james on GitHub (Dec 9, 2021).

Windows Terminal version

1.12.2931.0

Windows build number

10.0.19041.1348

Other Software

No response

Steps to reproduce

  1. In the Setting UI, go to the Profiles Defaults page and select the Appearance tab.
  2. Make sure the option Automaticaly adjust lightness of indistinguishable text is enabled.
  3. Open a bash shell.
  4. Execute the following command: printf "\e[m DEFAULT \e[1m BRIGHT \e[8m CONCEALED \e[m\n"

Expected Behavior

I'd expect the text with the SGR 1 attribute to be brighter, and the text with SGR 8 attribute to be invisible.

image

Actual Behavior

All of the text looks exactly the same.

image

This wouldn't be that big a deal if it was an option that users specifically opted in to, but I realise now that it's actually on by default. Was that really intentional? Even ignoring these problems, I would have thought the performance overhead alone was enough of a reason to make it opt-in.

Originally created by @j4james on GitHub (Dec 9, 2021). ### Windows Terminal version 1.12.2931.0 ### Windows build number 10.0.19041.1348 ### Other Software _No response_ ### Steps to reproduce 1. In the Setting UI, go to the _Profiles Defaults_ page and select the _Appearance_ tab. 2. Make sure the option _Automaticaly adjust lightness of indistinguishable text_ is enabled. 3. Open a bash shell. 4. Execute the following command: `printf "\e[m DEFAULT \e[1m BRIGHT \e[8m CONCEALED \e[m\n"` ### Expected Behavior I'd expect the text with the `SGR 1` attribute to be brighter, and the text with `SGR 8` attribute to be invisible. ![image](https://user-images.githubusercontent.com/4181424/145468815-ef7ada85-8373-468d-bcd7-2da471911520.png) ### Actual Behavior All of the text looks exactly the same. ![image](https://user-images.githubusercontent.com/4181424/145469002-4338741b-4214-40dc-bf38-08fa7d9c1dcf.png) This wouldn't be that big a deal if it was an option that users specifically opted in to, but I realise now that it's actually on by default. Was that really intentional? Even ignoring these problems, I would have thought the performance overhead alone was enough of a reason to make it opt-in.
Author
Owner

@DHowett commented on GitHub (Dec 9, 2021):

Augh, I knew that cribbing the color selection code would blow us up somehow. Even with this option on, we shouldn't be nudging those colors. Concealed was an oversight, even.

performance

We ended up going with an option that pre-cooks nudged colors for pairs in the lower 16x16 color grid, instead of doing it per color pair on render (which I think you'd suggested -- so we didn't nudge direct RGB colors or anything from the xterm 256 palette above the base sixteen specified in the color scheme.) That significantly reduced the performance impact.

@PankajBhojwani, would you mind taking a look at this? Bold=bright + nudge + \e[39;1m should definitely result in bright foreground. It looks like we're mishandling "bright default" in a pretty significant way.

@DHowett commented on GitHub (Dec 9, 2021): Augh, I knew that cribbing the color selection code would blow us up somehow. Even with this option on, we shouldn't be nudging those colors. Concealed was an oversight, even. > performance We ended up going with an option that pre-cooks nudged colors for pairs in the lower 16x16 color grid, instead of doing it per color pair on render (which I think you'd suggested -- so we didn't nudge direct RGB colors or anything from the xterm 256 palette above the base sixteen specified in the color scheme.) That significantly reduced the performance impact. @PankajBhojwani, would you mind taking a look at this? Bold=bright + nudge + `\e[39;1m` should definitely result in bright foreground. It looks like we're mishandling "bright default" in a pretty significant way.
Author
Owner

@DHowett commented on GitHub (Dec 9, 2021):

(I'll hold this feature back from 1.12 stable)

@DHowett commented on GitHub (Dec 9, 2021): (I'll hold this feature back from 1.12 stable)
Author
Owner

@j4james commented on GitHub (Dec 9, 2021):

We ended up going with an option that pre-cooks nudged colors for pairs in the lower 16x16 color grid, instead of doing it per color pair on render (which I think you'd suggested -- so we didn't nudge direct RGB colors or anything from the xterm 256 palette above the base sixteen specified in the color scheme.) That significantly reduced the performance impact.

Yeah, I've seen the code - I've actually been trying to optimise it to some extent as part of another PR I was working on (which is how I discovered these issues). I haven't actually tested the hit on performance, but it just seems like there's still a lot code being executed there. I had actually hoped we could implement this with zero run-time overhead, but maybe that was wishful thinking.

I should also mention that there are probably other scenarios in which this option can break things - SGR 1 and SGR 8 are just the two most obvious examples. I'll follow up here with more examples if/when I find them.

@j4james commented on GitHub (Dec 9, 2021): > We ended up going with an option that pre-cooks nudged colors for pairs in the lower 16x16 color grid, instead of doing it per color pair on render (which I think you'd suggested -- so we didn't nudge direct RGB colors or anything from the xterm 256 palette above the base sixteen specified in the color scheme.) That significantly reduced the performance impact. Yeah, I've seen the code - I've actually been trying to optimise it to some extent as part of another PR I was working on (which is how I discovered these issues). I haven't actually tested the hit on performance, but it just seems like there's still a lot code being executed there. I had actually hoped we could implement this with zero run-time overhead, but maybe that was wishful thinking. I should also mention that there are probably other scenarios in which this option can break things - SGR 1 and SGR 8 are just the two most obvious examples. I'll follow up here with more examples if/when I find them.
Author
Owner

@PankajBhojwani commented on GitHub (Dec 9, 2021):

So I can't seem to completely repro this - I can repro the issue with the concealed text showing up when it shouldn't (looking into that right now), but the bright text seems to be working as it should for me:

bright

Ignore that, if I set my intense text style to be only 'Bright colors' then I can repro the issue.

@PankajBhojwani commented on GitHub (Dec 9, 2021): <del>So I can't seem to _completely_ repro this - I can repro the issue with the concealed text showing up when it shouldn't (looking into that right now), but the bright text seems to be working as it should for me:</del> <img width="585" alt="bright" src="https://user-images.githubusercontent.com/26824113/145493603-1d008f43-26a6-4ace-ba7a-6222af936eb8.png"> Ignore that, if I set my intense text style to be only 'Bright colors' then I can repro the issue.
Author
Owner

@j4james commented on GitHub (Dec 10, 2021):

Here's another example of the kind of problem you can get with the color adjustment enabled.

  1. Set your color scheme in the settings to Solarized Light.
  2. Execute the following command in bash: printf "\e[m DEFAULT \e[7m REVERSED \e[m\n"
  3. Using escape sequences, change the palette to Campbell.

Instead of getting the Campbell color scheme, you get a mix of the two, I think probably with the foreground colors still coming from the Solarized Light scheme.

image

If we could make the color adjustment algorithm only apply to the initial color scheme, then that would avoid problems like this (and also improve the performance).

Just spitballing here, but consider an algorithm that can calculate some kind of brightness value for each color in the color scheme, and sort them on a linear scale. If there is a minimum brightness difference that would make all colors reasonably distinguishable, it shouldn't be too hard to spread those values out until they're all visibly distinguishable. You then regenerate the color scheme with the adjusted brightness levels and you're done - no runtime modification required. Does that not seem feasible?

@j4james commented on GitHub (Dec 10, 2021): Here's another example of the kind of problem you can get with the color adjustment enabled. 1. Set your color scheme in the settings to _Solarized Light_. 2. Execute the following command in bash: `printf "\e[m DEFAULT \e[7m REVERSED \e[m\n"` 3. Using escape sequences, change the palette to _Campbell_. Instead of getting the _Campbell_ color scheme, you get a mix of the two, I think probably with the foreground colors still coming from the _Solarized Light_ scheme. ![image](https://user-images.githubusercontent.com/4181424/145494742-c69b12d2-6893-4c00-a732-03cf8bc177ed.png) If we could make the color adjustment algorithm only apply to the initial color scheme, then that would avoid problems like this (and also improve the performance). Just spitballing here, but consider an algorithm that can calculate some kind of brightness value for each color in the color scheme, and sort them on a linear scale. If there is a minimum brightness difference that would make all colors reasonably distinguishable, it shouldn't be too hard to spread those values out until they're all visibly distinguishable. You then regenerate the color scheme with the adjusted brightness levels and you're done - no runtime modification required. Does that not seem feasible?
Author
Owner

@ghost commented on GitHub (Sep 13, 2022):

:tada:This issue was addressed in #13343, which has now been successfully released as Windows Terminal Preview v1.16.252.🎉

Handy links:

@ghost commented on GitHub (Sep 13, 2022): :tada:This issue was addressed in #13343, which has now been successfully released as `Windows Terminal Preview v1.16.252`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.16.252) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16091