Derive author colors in a color space where lightness means brightness

If gui.authorColors names no color for an author, lazygit picks one
from a hash of their name, at an HSL lightness between 0.4 and 0.6.
HSL lightness says nothing about how bright a color looks, though. At
0.5 a yellow is glaring and a blue is nearly black, so whether an
author's initials can be read comes down to where their name happens
to hash to. Against a background of #1e1e1e, 45% of four thousand
names fall below a contrast ratio of 4.5:1 and 21% below 3:1, with the
worst at 1.46:1. Several issues have been raised about author colors
being too dark to read.

Use HSLuv instead. Its lightness tracks perceived brightness, so the
range can be narrow now that a number in it means something. Against
#1e1e1e, every author now lands between 4.7:1 and 7.7:1, so no name is
unlucky any more.

This changes the color of every author who isn't named in
gui.authorColors. On a light background, the new colors are uniformly
too pale, where before they were mostly too pale. The next commit gives
a light background a range of its own.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-09-26 12:17:21 +02:00
co-authored by Claude Opus 5.5
parent d4f6e77d94
commit 7282c21aa5
+12 -1
View File
@@ -109,7 +109,18 @@ func trueColorStyle(str string) style.TextStyle {
// To check the colors at the edges of the ranges below, run
// `go run ./cmd/author_colors_repo <path>` and open the repository it creates.
func colorAtPosition(hue, saturation, lightness float64) colorful.Color {
return colorful.Hsl(hue*360.0, 0.6+0.4*saturation, 0.4+lightness*0.2)
// The lightness of an HSLuv color is how bright it looks, so every author
// comes out about equally readable whichever hue their name lands on. Plain
// HSL spreads them instead. At one and the same lightness, it gives a
// glaring yellow and a blue that all but disappears.
//
// The lightness range keeps every author above a contrast ratio of 4.5:1
// against common dark backgrounds, such as #1e1e1e.
//
// Saturation in HSLuv is a fraction of the most colorful a hue can get at
// that lightness, and pale colors are hard to tell apart, so keep it near
// the top of its range.
return colorful.HSLuv(hue*360.0, 0.8+0.2*saturation, 0.57+0.15*lightness)
}
// ColorPosition says where an author's color lies within the range of hues,