1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-09 13:47:11 +02:00

Add color functions to templates funcMaps

This commit is contained in:
Elwardi 2021-08-09 11:52:00 +01:00
parent b5d8849c06
commit e8e4fa5957
3 changed files with 12 additions and 7 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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 {