mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-21 12:16:54 +02:00
Add color functions to templates funcMaps
This commit is contained in:
parent
b5d8849c06
commit
e8e4fa5957
@ -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()))
|
return nil, gui.surfaceError(errors.New("unable to parse value format, error: " + err.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
colorFuncMap := template.FuncMap{}
|
colorFuncMap := style.TemplateFuncMapAddColors(template.FuncMap{})
|
||||||
for k, v := range style.ColorMap {
|
|
||||||
colorFuncMap[k] = v.Foreground.Sprint
|
|
||||||
}
|
|
||||||
|
|
||||||
descTemp, err := template.New("format").Funcs(colorFuncMap).Parse(labelFormat)
|
descTemp, err := template.New("format").Funcs(colorFuncMap).Parse(labelFormat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -2,6 +2,7 @@ package style
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -51,3 +52,12 @@ func FromBasicFg(fg color.Color) TextStyle {
|
|||||||
func FromBasicBg(bg color.Color) TextStyle {
|
func FromBasicBg(bg color.Color) TextStyle {
|
||||||
return New().SetBg(NewBasicColor(bg))
|
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
|
||||||
|
}
|
||||||
|
@ -6,8 +6,6 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var colorMap = style.ColorMap
|
|
||||||
|
|
||||||
func GetTextStyle(keys []string, background bool) style.TextStyle {
|
func GetTextStyle(keys []string, background bool) style.TextStyle {
|
||||||
s := style.New()
|
s := style.New()
|
||||||
|
|
||||||
@ -20,7 +18,7 @@ func GetTextStyle(keys []string, background bool) style.TextStyle {
|
|||||||
case "underline":
|
case "underline":
|
||||||
s = s.SetUnderline()
|
s = s.SetUnderline()
|
||||||
default:
|
default:
|
||||||
value, present := colorMap[key]
|
value, present := style.ColorMap[key]
|
||||||
if present {
|
if present {
|
||||||
var c style.TextStyle
|
var c style.TextStyle
|
||||||
if background {
|
if background {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user