From 3d2376ab52f4eba1dce9783d93cf1c34d4559c52 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 9 Dec 2022 12:05:27 +0900 Subject: [PATCH] Add color name 'preview-label' (#3053) --- CHANGELOG.md | 2 ++ man/man1/fzf.1 | 41 +++++++++++++++++++++-------------------- src/options.go | 2 ++ src/terminal.go | 2 +- src/tui/tui.go | 28 ++++++++++++---------------- 5 files changed, 38 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 528b0e2..2b56575 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ CHANGELOG # No need to bind 'double-click' to the same action fzf --bind 'enter:execute:less {}' # --bind 'double-click:execute:less {}' ``` +- Added color name `preview-label` for `--preview-label` (defaults to `label` + for `--border-label`) - Minor bug fixes and improvements 0.35.1 diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 79e7291..5d4cad7 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -404,26 +404,27 @@ color mappings. \fBbw \fRNo colors (equivalent to \fB--no-color\fR) .B COLOR NAMES: - \fBfg \fRText - \fBbg \fRBackground - \fBpreview-fg \fRPreview window text - \fBpreview-bg \fRPreview window background - \fBhl \fRHighlighted substrings - \fBfg+ \fRText (current line) - \fBbg+ \fRBackground (current line) - \fBgutter \fRGutter on the left (defaults to \fBbg+\fR) - \fBhl+ \fRHighlighted substrings (current line) - \fBquery \fRQuery string - \fBdisabled \fRQuery string when search is disabled - \fBinfo \fRInfo line (match counters) - \fBseparator \fRHorizontal separator on info line (match counters) - \fBborder \fRBorder around the window (\fB--border\fR and \fB--preview\fR) - \fBlabel \fRBorder label (\fB--border-label\fR and \fB--preview-label\fR) - \fBprompt \fRPrompt - \fBpointer \fRPointer to the current line - \fBmarker \fRMulti-select marker - \fBspinner \fRStreaming input indicator - \fBheader \fRHeader + \fBfg \fRText + \fBbg \fRBackground + \fBpreview-fg \fRPreview window text + \fBpreview-bg \fRPreview window background + \fBhl \fRHighlighted substrings + \fBfg+ \fRText (current line) + \fBbg+ \fRBackground (current line) + \fBgutter \fRGutter on the left (defaults to \fBbg+\fR) + \fBhl+ \fRHighlighted substrings (current line) + \fBquery \fRQuery string + \fBdisabled \fRQuery string when search is disabled + \fBinfo \fRInfo line (match counters) + \fBseparator \fRHorizontal separator on info line (match counters) + \fBborder \fRBorder around the window (\fB--border\fR and \fB--preview\fR) + \fBlabel \fRBorder label (\fB--border-label\fR and \fB--preview-label\fR) + \fBpreview-label \fRBorder label of the preview window (\fB--preview-label\fR) + \fBprompt \fRPrompt + \fBpointer \fRPointer to the current line + \fBmarker \fRMulti-select marker + \fBspinner \fRStreaming input indicator + \fBheader \fRHeader .B ANSI COLORS: \fB-1 \fRDefault terminal foreground/background color diff --git a/src/options.go b/src/options.go index 31e96ec..b372466 100644 --- a/src/options.go +++ b/src/options.go @@ -845,6 +845,8 @@ func parseTheme(defaultTheme *tui.ColorTheme, str string) *tui.ColorTheme { mergeAttr(&theme.Separator) case "label": mergeAttr(&theme.BorderLabel) + case "preview-label": + mergeAttr(&theme.PreviewLabel) case "prompt": mergeAttr(&theme.Prompt) case "spinner": diff --git a/src/terminal.go b/src/terminal.go index 81df822..2b4d25e 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -602,7 +602,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal { t.pointerEmpty = strings.Repeat(" ", t.pointerLen) t.markerEmpty = strings.Repeat(" ", t.markerLen) t.borderLabel, t.borderLabelLen = t.ansiLabelPrinter(opts.BorderLabel.label, &tui.ColBorderLabel, false) - t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(opts.PreviewLabel.label, &tui.ColBorderLabel, false) + t.previewLabel, t.previewLabelLen = t.ansiLabelPrinter(opts.PreviewLabel.label, &tui.ColPreviewLabel, false) if opts.Separator == nil || len(*opts.Separator) > 0 { bar := "─" if opts.Separator != nil { diff --git a/src/tui/tui.go b/src/tui/tui.go index 31afa5b..eb62480 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -270,6 +270,7 @@ type ColorTheme struct { Separator ColorAttr Border ColorAttr BorderLabel ColorAttr + PreviewLabel ColorAttr } type Event struct { @@ -468,6 +469,7 @@ var ( ColPreview ColorPair ColPreviewBorder ColorPair ColBorderLabel ColorPair + ColPreviewLabel ColorPair ) func EmptyTheme() *ColorTheme { @@ -493,6 +495,7 @@ func EmptyTheme() *ColorTheme { Separator: ColorAttr{colUndefined, AttrUndefined}, Border: ColorAttr{colUndefined, AttrUndefined}, BorderLabel: ColorAttr{colUndefined, AttrUndefined}, + PreviewLabel: ColorAttr{colUndefined, AttrUndefined}, } } @@ -519,6 +522,7 @@ func NoColorTheme() *ColorTheme { Separator: ColorAttr{colDefault, AttrRegular}, Border: ColorAttr{colDefault, AttrRegular}, BorderLabel: ColorAttr{colDefault, AttrRegular}, + PreviewLabel: ColorAttr{colDefault, AttrRegular}, } } @@ -531,13 +535,9 @@ func init() { Default16 = &ColorTheme{ Colored: true, Input: ColorAttr{colDefault, AttrUndefined}, - Disabled: ColorAttr{colUndefined, AttrUndefined}, Fg: ColorAttr{colDefault, AttrUndefined}, Bg: ColorAttr{colDefault, AttrUndefined}, - PreviewFg: ColorAttr{colUndefined, AttrUndefined}, - PreviewBg: ColorAttr{colUndefined, AttrUndefined}, DarkBg: ColorAttr{colBlack, AttrUndefined}, - Gutter: ColorAttr{colUndefined, AttrUndefined}, Prompt: ColorAttr{colBlue, AttrUndefined}, Match: ColorAttr{colGreen, AttrUndefined}, Current: ColorAttr{colYellow, AttrUndefined}, @@ -554,13 +554,9 @@ func init() { Dark256 = &ColorTheme{ Colored: true, Input: ColorAttr{colDefault, AttrUndefined}, - Disabled: ColorAttr{colUndefined, AttrUndefined}, Fg: ColorAttr{colDefault, AttrUndefined}, Bg: ColorAttr{colDefault, AttrUndefined}, - PreviewFg: ColorAttr{colUndefined, AttrUndefined}, - PreviewBg: ColorAttr{colUndefined, AttrUndefined}, DarkBg: ColorAttr{236, AttrUndefined}, - Gutter: ColorAttr{colUndefined, AttrUndefined}, Prompt: ColorAttr{110, AttrUndefined}, Match: ColorAttr{108, AttrUndefined}, Current: ColorAttr{254, AttrUndefined}, @@ -577,13 +573,9 @@ func init() { Light256 = &ColorTheme{ Colored: true, Input: ColorAttr{colDefault, AttrUndefined}, - Disabled: ColorAttr{colUndefined, AttrUndefined}, Fg: ColorAttr{colDefault, AttrUndefined}, Bg: ColorAttr{colDefault, AttrUndefined}, - PreviewFg: ColorAttr{colUndefined, AttrUndefined}, - PreviewBg: ColorAttr{colUndefined, AttrUndefined}, DarkBg: ColorAttr{251, AttrUndefined}, - Gutter: ColorAttr{colUndefined, AttrUndefined}, Prompt: ColorAttr{25, AttrUndefined}, Match: ColorAttr{66, AttrUndefined}, Current: ColorAttr{237, AttrUndefined}, @@ -615,13 +607,9 @@ func initTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) { return c } theme.Input = o(baseTheme.Input, theme.Input) - theme.Disabled = o(theme.Input, o(baseTheme.Disabled, theme.Disabled)) theme.Fg = o(baseTheme.Fg, theme.Fg) theme.Bg = o(baseTheme.Bg, theme.Bg) - theme.PreviewFg = o(theme.Fg, o(baseTheme.PreviewFg, theme.PreviewFg)) - theme.PreviewBg = o(theme.Bg, o(baseTheme.PreviewBg, theme.PreviewBg)) theme.DarkBg = o(baseTheme.DarkBg, theme.DarkBg) - theme.Gutter = o(theme.DarkBg, o(baseTheme.Gutter, theme.Gutter)) theme.Prompt = o(baseTheme.Prompt, theme.Prompt) theme.Match = o(baseTheme.Match, theme.Match) theme.Current = o(baseTheme.Current, theme.Current) @@ -635,6 +623,13 @@ func initTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) { theme.Border = o(baseTheme.Border, theme.Border) theme.BorderLabel = o(baseTheme.BorderLabel, theme.BorderLabel) + // These colors are not defined in the base themes + theme.Disabled = o(theme.Input, theme.Disabled) + theme.Gutter = o(theme.DarkBg, theme.Gutter) + theme.PreviewFg = o(theme.Fg, theme.PreviewFg) + theme.PreviewBg = o(theme.Bg, theme.PreviewBg) + theme.PreviewLabel = o(theme.BorderLabel, theme.PreviewLabel) + initPalette(theme) } @@ -668,6 +663,7 @@ func initPalette(theme *ColorTheme) { ColSeparator = pair(theme.Separator, theme.Bg) ColBorder = pair(theme.Border, theme.Bg) ColBorderLabel = pair(theme.BorderLabel, theme.Bg) + ColPreviewLabel = pair(theme.PreviewLabel, theme.PreviewBg) ColPreview = pair(theme.PreviewFg, theme.PreviewBg) ColPreviewBorder = pair(theme.Border, theme.PreviewBg) }