Description
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.
func HasDarkBackground() bool {
_, _, fgLightness := termenv.ConvertToRGB(termenv.ForegroundColor()).Hsl()
_, _, bgLightness := termenv.ConvertToRGB(termenv.BackgroundColor()).Hsl()
return bgLightness < 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.