Extract converting a configured color to a text style

The next commit needs it for a single color.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-09-27 08:16:06 +02:00
co-authored by Claude Opus 5.5
parent 573cd8a005
commit ae1b43dc96
+10 -4
View File
@@ -60,10 +60,16 @@ func IsValidHexValue(v string) bool {
func SetCustomColors(customColors map[string]string) map[string]*style.TextStyle {
return lo.MapValues(customColors, func(c string, key string) *style.TextStyle {
if s, ok := style.ColorMap[c]; ok {
return &s.Foreground
}
value := style.New().SetFg(style.NewRGBColor(color.HEX(c, false)))
value := CustomColorStyle(c)
return &value
})
}
// CustomColorStyle returns the text style for a color that the user
// configured, either by the name of a terminal color or as a hex value.
func CustomColorStyle(c string) style.TextStyle {
if s, ok := style.ColorMap[c]; ok {
return s.Foreground
}
return style.New().SetFg(style.NewRGBColor(color.HEX(c, false)))
}