diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2020-12-07 19:07:17 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2020-12-07 19:11:00 +0900 |
commit | e0a22e76f8254eb5478f86bb43ccc0115a46c25f (patch) | |
tree | 8a61f9655b609da1a7b6c1209bea3e18a4191858 | |
parent | 00a36103316456227b5a3331e58155e43f713f79 (diff) |
Make --color attributes mergeable
So you can override the colors and still have the text attributes
# Default colors and attributes
fzf
export FZF_DEFAULT_OPTS='--color hl:-1:underline,hl+:-1:underline:reverse'
# Default colors with underline+reverse attributes
fzf
# Different colors with underline+reverse attributes
fzf --color hl:176,hl+:177
Related: https://github.com/junegunn/fzf.vim/issues/1197#issuecomment-739804363
-rw-r--r-- | src/options.go | 87 |
1 files changed, 44 insertions, 43 deletions
diff --git a/src/options.go b/src/options.go index 0607e5dc..f5a7c614 100644 --- a/src/options.go +++ b/src/options.go @@ -644,71 +644,72 @@ func parseTheme(defaultTheme *tui.ColorTheme, str string) *tui.ColorTheme { fail() } - cattr := tui.NewColorAttr() - for _, component := range components[1:] { - switch component { - case "regular": - cattr.Attr = tui.AttrRegular - case "bold", "strong": - cattr.Attr |= tui.Bold - case "dim": - cattr.Attr |= tui.Dim - case "italic": - cattr.Attr |= tui.Italic - case "underline": - cattr.Attr |= tui.Underline - case "blink": - cattr.Attr |= tui.Blink - case "reverse": - cattr.Attr |= tui.Reverse - case "": - default: - if rrggbb.MatchString(component) { - cattr.Color = tui.HexToColor(component) - } else { - ansi32, err := strconv.Atoi(component) - if err != nil || ansi32 < -1 || ansi32 > 255 { - fail() + mergeAttr := func(cattr *tui.ColorAttr) { + for _, component := range components[1:] { + switch component { + case "regular": + cattr.Attr = tui.AttrRegular + case "bold", "strong": + cattr.Attr |= tui.Bold + case "dim": + cattr.Attr |= tui.Dim + case "italic": + cattr.Attr |= tui.Italic + case "underline": + cattr.Attr |= tui.Underline + case "blink": + cattr.Attr |= tui.Blink + case "reverse": + cattr.Attr |= tui.Reverse + case "": + default: + if rrggbb.MatchString(component) { + cattr.Color = tui.HexToColor(component) + } else { + ansi32, err := strconv.Atoi(component) + if err != nil || ansi32 < -1 || ansi32 > 255 { + fail() + } + cattr.Color = tui.Color(ansi32) } - cattr.Color = tui.Color(ansi32) } } } switch components[0] { case "input": - theme.Input = cattr + mergeAttr(&theme.Input) case "fg": - theme.Fg = cattr + mergeAttr(&theme.Fg) case "bg": - theme.Bg = cattr + mergeAttr(&theme.Bg) case "preview-fg": - theme.PreviewFg = cattr + mergeAttr(&theme.PreviewFg) case "preview-bg": - theme.PreviewBg = cattr + mergeAttr(&theme.PreviewBg) case "fg+": - theme.Current = cattr + mergeAttr(&theme.Current) case "bg+": - theme.DarkBg = cattr + mergeAttr(&theme.DarkBg) case "gutter": - theme.Gutter = cattr + mergeAttr(&theme.Gutter) case "hl": - theme.Match = cattr + mergeAttr(&theme.Match) case "hl+": - theme.CurrentMatch = cattr + mergeAttr(&theme.CurrentMatch) case "border": - theme.Border = cattr + mergeAttr(&theme.Border) case "prompt": - theme.Prompt = cattr + mergeAttr(&theme.Prompt) case "spinner": - theme.Spinner = cattr + mergeAttr(&theme.Spinner) case "info": - theme.Info = cattr + mergeAttr(&theme.Info) case "pointer": - theme.Cursor = cattr + mergeAttr(&theme.Cursor) case "marker": - theme.Selected = cattr + mergeAttr(&theme.Selected) case "header": - theme.Header = cattr + mergeAttr(&theme.Header) default: fail() } |