mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
Support match colors in labelFormat
entry in menuFromCommand prompts
This commit is contained in:
parent
5d1a9639b6
commit
b5d8849c06
@ -48,7 +48,7 @@ customCommands:
|
|||||||
command: 'git branch -r --list {{index .PromptResponses 0}}/*'
|
command: 'git branch -r --list {{index .PromptResponses 0}}/*'
|
||||||
filter: '.*{{index .PromptResponses 0}}/(?P<branch>.*)'
|
filter: '.*{{index .PromptResponses 0}}/(?P<branch>.*)'
|
||||||
valueFormat: '{{ .branch }}'
|
valueFormat: '{{ .branch }}'
|
||||||
labelFormat: ''
|
labelFormat: '{{ .branch | green }}'
|
||||||
```
|
```
|
||||||
|
|
||||||
Looking at the command assigned to the 'n' key, here's what the result looks like:
|
Looking at the command assigned to the 'n' key, here's what the result looks like:
|
||||||
@ -110,8 +110,10 @@ The permitted prompt fields are:
|
|||||||
| | PS: named groups keep first match only | |
|
| | PS: named groups keep first match only | |
|
||||||
| labelFormat | (only applicable to 'menuFromCommand' prompts) how to format matched groups from | no |
|
| labelFormat | (only applicable to 'menuFromCommand' prompts) how to format matched groups from | no |
|
||||||
| | the filter to construct the item's label (What's shown on screen). You can use | |
|
| | the filter to construct the item's label (What's shown on screen). You can use | |
|
||||||
| | named groups, or `{{ .group_GROUPID }}`. If this is not specified, `valueFormat` | |
|
| | named groups, or `{{ .group_GROUPID }}`. You can also color each match with | |
|
||||||
| | is shown instead. | |
|
| | `{{ .group_GROUPID | colorname }}` (Color names from | |
|
||||||
|
| | [here](https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md)) | |
|
||||||
|
| | If `labelFormat` is not specified, `valueFormat` is shown instead. | |
|
||||||
| | PS: named groups keep first match only | |
|
| | PS: named groups keep first match only | |
|
||||||
|
|
||||||
The permitted option fields are:
|
The permitted option fields are:
|
||||||
|
@ -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()))
|
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 {
|
if err != nil {
|
||||||
return nil, gui.surfaceError(errors.New("unable to parse label format, error: " + err.Error()))
|
return nil, gui.surfaceError(errors.New("unable to parse label format, error: " + err.Error()))
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,21 @@ var (
|
|||||||
|
|
||||||
AttrUnderline = New().SetUnderline()
|
AttrUnderline = New().SetUnderline()
|
||||||
AttrBold = New().SetBold()
|
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 {
|
func FromBasicFg(fg color.Color) TextStyle {
|
||||||
|
@ -6,20 +6,7 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var colorMap = map[string]struct {
|
var colorMap = style.ColorMap
|
||||||
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},
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetTextStyle(keys []string, background bool) style.TextStyle {
|
func GetTextStyle(keys []string, background bool) style.TextStyle {
|
||||||
s := style.New()
|
s := style.New()
|
||||||
@ -37,9 +24,9 @@ func GetTextStyle(keys []string, background bool) style.TextStyle {
|
|||||||
if present {
|
if present {
|
||||||
var c style.TextStyle
|
var c style.TextStyle
|
||||||
if background {
|
if background {
|
||||||
c = value.background
|
c = value.Background
|
||||||
} else {
|
} else {
|
||||||
c = value.foreground
|
c = value.Foreground
|
||||||
}
|
}
|
||||||
s = s.MergeStyle(c)
|
s = s.MergeStyle(c)
|
||||||
} else if utils.IsValidHexValue(key) {
|
} else if utils.IsValidHexValue(key) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user