You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, HasDarkBackground() just checks if the lightness is smaller than 0.5. This is obviously subjective (as acknowledged in the docs with the work "dark-ish") but what's more important is that it is missleading for low-contrast color schemes where both the foreground and the background has a high or low lightness.
Another approach to HasDarkBackground() would be to compare the foreground lightness to the background lightness. This would be more in line with what most people think of when a color scheme or background is light or dark.
An implementation could look like this:
// HasDarkBackground returns whether terminal uses a color scheme in which the// background is darker than the foreground.funcHasDarkBackground() bool {
_, _, fgLightness:=termenv.ConvertToRGB(termenv.ForegroundColor()).Hsl()
_, _, bgLightness:=termenv.ConvertToRGB(termenv.BackgroundColor()).Hsl()
returnbgLightness<fgLightness
}
This way, it can be used to implement color-scheme aware dimming as described in #45.
Alternatively, the functionality above could be added alongside HasDarkBackground() with the name HasDarkColorScheme().
I can submit a PR if you like this idea.
The text was updated successfully, but these errors were encountered:
While using the glow CLI program, I noticed that my gruvbox-light terminal colorscheme was determined by termenv to be "light" (through the dark-mode detection code), which was very counter-intuitive for a feature which is supposed to automatically detect whether the theme is dark or light.
This is an issue if you switch between light and dark themes daily, so that setting a theme in the config file and calling it a day isn't an option.
BachoSeven
added a commit
to BachoSeven/dotfiles
that referenced
this issue
Sep 10, 2023
Currently,
HasDarkBackground()
just checks if the lightness is smaller than 0.5. This is obviously subjective (as acknowledged in the docs with the work "dark-ish") but what's more important is that it is missleading for low-contrast color schemes where both the foreground and the background has a high or low lightness.Another approach to
HasDarkBackground()
would be to compare the foreground lightness to the background lightness. This would be more in line with what most people think of when a color scheme or background is light or dark.An implementation could look like this:
This way, it can be used to implement color-scheme aware dimming as described in #45.
Alternatively, the functionality above could be added alongside
HasDarkBackground()
with the nameHasDarkColorScheme()
.I can submit a PR if you like this idea.
The text was updated successfully, but these errors were encountered: