From fcabbf517c58a68a48cb871838e2b5640fe46ada Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 25 Sep 2026 14:26:23 +0200 Subject: [PATCH] Split an author's color into where the name lands and the color there The next commit adds a tool that creates a repository of authors at the edges of the range their colors are picked from. To find such names, it needs to know where a name lands in the range, and it shouldn't keep a copy of the hashing that could drift from this one. Later commits test the colors, and need the colors themselves for that rather than the styles made from them. Co-Authored-By: Claude Opus 5.5 (1M context) --- pkg/gui/presentation/authors/authors.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/gui/presentation/authors/authors.go b/pkg/gui/presentation/authors/authors.go index 93482eb69..6d2c4f428 100644 --- a/pkg/gui/presentation/authors/authors.go +++ b/pkg/gui/presentation/authors/authors.go @@ -101,12 +101,23 @@ func AuthorStyle(authorName string) *style.TextStyle { } func trueColorStyle(str string) style.TextStyle { - hash := md5.Sum([]byte(str)) - c := colorful.Hsl(randFloat(hash[0:4])*360.0, 0.6+0.4*randFloat(hash[4:8]), 0.4+randFloat(hash[8:12])*0.2) + c := colorAtPosition(ColorPosition(str)) return style.New().SetFg(style.NewRGBColor(color.RGB(uint8(c.R*255), uint8(c.G*255), uint8(c.B*255)))) } +func colorAtPosition(hue, saturation, lightness float64) colorful.Color { + return colorful.Hsl(hue*360.0, 0.6+0.4*saturation, 0.4+lightness*0.2) +} + +// ColorPosition says where an author's color lies within the range of hues, +// saturations and lightnesses that colorAtPosition picks from. Each is a +// fraction from 0 up to 1, derived from a hash of the author's name. +func ColorPosition(authorName string) (hue, saturation, lightness float64) { + hash := md5.Sum([]byte(authorName)) + return randFloat(hash[0:4]), randFloat(hash[4:8]), randFloat(hash[8:12]) +} + func randFloat(hash []byte) float64 { return float64(randInt(hash, 100)) / 100 }