summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorElwardi <elwardifadeli@gmail.com>2021-08-07 16:06:36 +0100
committerElwardi <elwardifadeli@gmail.com>2021-08-07 16:06:36 +0100
commitb5d8849c06de3d0ea410e0ba03e66b101b1ec626 (patch)
tree07671c4286286cae63621d92e801ffbbdd213ac1 /pkg
parent5d1a9639b6dc7f2a5267cb2f919f96a6f7bd95d1 (diff)
Support match colors in `labelFormat` entry in menuFromCommand prompts
Diffstat (limited to 'pkg')
-rw-r--r--pkg/gui/custom_commands.go7
-rw-r--r--pkg/gui/style/basic_styles.go15
-rw-r--r--pkg/theme/style.go19
3 files changed, 24 insertions, 17 deletions
diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go
index a9795f7b6..d43f028cb 100644
--- a/pkg/gui/custom_commands.go
+++ b/pkg/gui/custom_commands.go
@@ -136,7 +136,12 @@ func (gui *Gui) GenerateMenuCandidates(commandOutput, filter, valueFormat, label
return nil, gui.surfaceError(errors.New("unable to parse value format, error: " + err.Error()))
}
- descTemp, err := template.New("format").Parse(labelFormat)
+ colorFuncMap := template.FuncMap{}
+ for k, v := range style.ColorMap {
+ colorFuncMap[k] = v.Foreground.Sprint
+ }
+
+ descTemp, err := template.New("format").Funcs(colorFuncMap).Parse(labelFormat)
if err != nil {
return nil, gui.surfaceError(errors.New("unable to parse label format, error: " + err.Error()))
}
diff --git a/pkg/gui/style/basic_styles.go b/pkg/gui/style/basic_styles.go
index ef29904bc..373172a8b 100644
--- a/pkg/gui/style/basic_styles.go
+++ b/pkg/gui/style/basic_styles.go
@@ -27,6 +27,21 @@ var (
AttrUnderline = New().SetUnderline()
AttrBold = New().SetBold()
+
+ ColorMap = map[string]struct {
+ Foreground TextStyle
+ Background TextStyle
+ }{
+ "default": {FgWhite, BgBlack},
+ "black": {FgBlack, BgBlack},
+ "red": {FgRed, BgRed},
+ "green": {FgGreen, BgGreen},
+ "yellow": {FgYellow, BgYellow},
+ "blue": {FgBlue, BgBlue},
+ "magenta": {FgMagenta, BgMagenta},
+ "cyan": {FgCyan, BgCyan},
+ "white": {FgWhite, BgWhite},
+ }
)
func FromBasicFg(fg color.Color) TextStyle {
diff --git a/pkg/theme/style.go b/pkg/theme/style.go
index ba014681a..8f607256d 100644
--- a/pkg/theme/style.go
+++ b/pkg/theme/style.go
@@ -6,20 +6,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils"
)
-var colorMap = map[string]struct {
- foreground style.TextStyle
- background style.TextStyle
-}{
- "default": {style.FgWhite, style.BgBlack},
- "black": {style.FgBlack, style.BgBlack},
- "red": {style.FgRed, style.BgRed},
- "green": {style.FgGreen, style.BgGreen},
- "yellow": {style.FgYellow, style.BgYellow},
- "blue": {style.FgBlue, style.BgBlue},
- "magenta": {style.FgMagenta, style.BgMagenta},
- "cyan": {style.FgCyan, style.BgCyan},
- "white": {style.FgWhite, style.BgWhite},
-}
+var colorMap = style.ColorMap
func GetTextStyle(keys []string, background bool) style.TextStyle {
s := style.New()
@@ -37,9 +24,9 @@ func GetTextStyle(keys []string, background bool) style.TextStyle {
if present {
var c style.TextStyle
if background {
- c = value.background
+ c = value.Background
} else {
- c = value.foreground
+ c = value.Foreground
}
s = s.MergeStyle(c)
} else if utils.IsValidHexValue(key) {