summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyooooooga <eial5q265e5@gmail.com>2022-05-04 19:02:08 +0900
committerRyooooooga <eial5q265e5@gmail.com>2022-05-04 19:03:00 +0900
commit494368a241634e3473f46a10256df19d85dbb5f7 (patch)
tree935f6781e645462c7acf0ee6c605ec0ff1152872
parentf143d04d87320eda588a35763e4dcb562cc59047 (diff)
feat: accept named colors for `gui.authorColors`
-rw-r--r--docs/Config.md5
-rw-r--r--pkg/utils/color.go13
2 files changed, 10 insertions, 8 deletions
diff --git a/docs/Config.md b/docs/Config.md
index 591078580..f40cc5c63 100644
--- a/docs/Config.md
+++ b/docs/Config.md
@@ -384,7 +384,8 @@ You can customize the color in case you're not happy with the randomly assigned
```yaml
gui:
authorColors:
- 'John Smith': '#ff0000' # use red for John Smith
+ 'John Smith': 'red' # use red for John Smith
+ 'Alan Smithee': '#00ff00' # use green for Alan Smithee
```
You can use wildcard to set a unified color in case your are lazy to customize the color for every author or you just want a single color for all/other authors:
@@ -393,7 +394,7 @@ You can use wildcard to set a unified color in case your are lazy to customize t
gui:
authorColors:
# use red for John Smith
- 'John Smith': '#ff0000'
+ 'John Smith': 'red'
# use blue for other authors
'*': '#0000ff'
```
diff --git a/pkg/utils/color.go b/pkg/utils/color.go
index 2eced49e2..a4ad578e0 100644
--- a/pkg/utils/color.go
+++ b/pkg/utils/color.go
@@ -6,6 +6,7 @@ import (
"github.com/gookit/color"
"github.com/jesseduffield/lazygit/pkg/gui/style"
+ "github.com/samber/lo"
)
var (
@@ -55,10 +56,10 @@ func IsValidHexValue(v string) bool {
}
func SetCustomColors(customColors map[string]string) map[string]style.TextStyle {
- colors := make(map[string]style.TextStyle)
- for key, colorSequence := range customColors {
- style := style.New().SetFg(style.NewRGBColor(color.HEX(colorSequence, false)))
- colors[key] = style
- }
- return colors
+ return lo.MapValues(customColors, func(c string, key string) style.TextStyle {
+ if s, ok := style.ColorMap[c]; ok {
+ return s.Foreground
+ }
+ return style.New().SetFg(style.NewRGBColor(color.HEX(c, false)))
+ })
}