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

Reinterpret HasDarkBackground as Relative to ForegroundColor #44

Open
erikgeiser opened this issue Jul 31, 2021 · 1 comment
Open

Reinterpret HasDarkBackground as Relative to ForegroundColor #44

erikgeiser opened this issue Jul 31, 2021 · 1 comment

Comments

@erikgeiser
Copy link

erikgeiser commented Jul 31, 2021

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.

@BachoSeven
Copy link

I second this.

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
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

No branches or pull requests

2 participants