(bug) isDarkColor returns incorrect value for some blues
isDarkColor (color.go:225) takes its lightness from Hsl(), which is
(max+min)/2 of the channels and is not perceptual. it returns exactly 0.500
for all three saturated primaries, so pure blue -- relative luminance 0.072 --
is reported light.
reachable from public api, not internal. HasDarkBackground calls it, and
compat/color.go:13 evaluates
HasDarkBackground = lipgloss.HasDarkBackground(os.Stdin, os.Stdout)as a package-level variable at init. the v2 upgrade guide's quick start, item
one, tells every v1 user migrating AdaptiveColor to use compat. on a
saturated blue background that resolves the wrong branch once, for the whole
program.
contrast, measured: a developer's light-background choice is typically dark text, which against #0000FF is 1.47:1 to 2.03:1 where WCAG AA asks 4.5:1. the dark-background choice would have been 8.59:1. included image shows both
the fix is Hsl() -> Lab(). go-colorful is already imported and normalises
L to 0..1, so the threshold does not move and no dependency changes. every real
terminal background gives the same answer as before -- solarized dark and
light, dracula, DOS blue, black, white -- and the only value that moves is
saturated blue.
Setup Please complete the following information along with version numbers, if applicable.
- OS macos
- Shell zsh
- Terminal Emulator ghostty
- Terminal Multiplexer tmux
- Locale en_US.UTF-8
Source Code
- see difff
Screenshots
- see above
Source: charmbracelet/lipgloss