diff options
author | Elwardi <elwardifadeli@gmail.com> | 2021-08-09 11:52:00 +0100 |
---|---|---|
committer | Elwardi <elwardifadeli@gmail.com> | 2021-08-09 11:52:00 +0100 |
commit | e8e4fa59572915f669c5daf272bb5721f53de2d7 (patch) | |
tree | 351e8c1e4cb8c93eaccb4df9669961d0a5c7913d /pkg | |
parent | b5d8849c06de3d0ea410e0ba03e66b101b1ec626 (diff) |
Add color functions to templates funcMaps
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/custom_commands.go | 5 | ||||
-rw-r--r-- | pkg/gui/style/basic_styles.go | 10 | ||||
-rw-r--r-- | pkg/theme/style.go | 4 |
3 files changed, 12 insertions, 7 deletions
diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go index d43f028cb..8f98d6597 100644 --- a/pkg/gui/custom_commands.go +++ b/pkg/gui/custom_commands.go @@ -136,10 +136,7 @@ func (gui *Gui) GenerateMenuCandidates(commandOutput, filter, valueFormat, label return nil, gui.surfaceError(errors.New("unable to parse value format, error: " + err.Error())) } - colorFuncMap := template.FuncMap{} - for k, v := range style.ColorMap { - colorFuncMap[k] = v.Foreground.Sprint - } + colorFuncMap := style.TemplateFuncMapAddColors(template.FuncMap{}) descTemp, err := template.New("format").Funcs(colorFuncMap).Parse(labelFormat) if err != nil { diff --git a/pkg/gui/style/basic_styles.go b/pkg/gui/style/basic_styles.go index 373172a8b..92b034f06 100644 --- a/pkg/gui/style/basic_styles.go +++ b/pkg/gui/style/basic_styles.go @@ -2,6 +2,7 @@ package style import ( "github.com/gookit/color" + "text/template" ) var ( @@ -51,3 +52,12 @@ func FromBasicFg(fg color.Color) TextStyle { func FromBasicBg(bg color.Color) TextStyle { return New().SetBg(NewBasicColor(bg)) } + +func TemplateFuncMapAddColors(m template.FuncMap) template.FuncMap { + for k, v := range ColorMap { + m[k] = v.Foreground.Sprint + } + m["underline"] = color.OpUnderscore.Sprint + m["bold"] = color.OpBold.Sprint + return m +} diff --git a/pkg/theme/style.go b/pkg/theme/style.go index 8f607256d..69c404e3b 100644 --- a/pkg/theme/style.go +++ b/pkg/theme/style.go @@ -6,8 +6,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/utils" ) -var colorMap = style.ColorMap - func GetTextStyle(keys []string, background bool) style.TextStyle { s := style.New() @@ -20,7 +18,7 @@ func GetTextStyle(keys []string, background bool) style.TextStyle { case "underline": s = s.SetUnderline() default: - value, present := colorMap[key] + value, present := style.ColorMap[key] if present { var c style.TextStyle if background { |