mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-27 09:46:10 -04:00
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) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c06233073a
commit
fcabbf517c
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user