From 771e35b97269618d2f6661ba657f7d9c1c7860df Mon Sep 17 00:00:00 2001 From: RT Date: Fri, 28 Nov 2025 20:43:13 -0500 Subject: [PATCH] feat: add alt-gutter color option (#4602) * Add alt-gutter color option * Simplify the code --------- Co-authored-by: Junegunn Choi --- man/man1/fzf.1 | 1 + src/options.go | 2 ++ src/terminal.go | 20 ++++++++++++++------ src/tui/tui.go | 11 +++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index a9e4cb96..d0214942 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -272,6 +272,7 @@ color mappings. Each entry is separated by a comma and/or whitespaces. \fBgutter \fRGutter on the left \fBcurrent\-hl (hl+) \fRHighlighted substrings (current line) \fBalt\-bg \fRAlternate background color to create striped lines + \fBalt\-gutter \fRAlternate gutter color to create the striped pattern \fBquery (input\-fg) \fRQuery string \fBghost \fRGhost text (\fB\-\-ghost\fR, \fBdim\fR applied by default) \fBdisabled \fRQuery string when search is disabled (\fB\-\-disabled\fR) diff --git a/src/options.go b/src/options.go index 637f1d99..9faa7a92 100644 --- a/src/options.go +++ b/src/options.go @@ -1476,6 +1476,8 @@ func parseTheme(defaultTheme *tui.ColorTheme, str string) (*tui.ColorTheme, *tui mergeAttr(&theme.Nomatch) case "gutter": mergeAttr(&theme.Gutter) + case "alt-gutter": + mergeAttr(&theme.AltGutter) case "hl": mergeAttr(&theme.Match) case "current-hl", "hl+": diff --git a/src/terminal.go b/src/terminal.go index 71e7ed2c..ae4ab14f 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -3202,14 +3202,22 @@ func (t *Terminal) renderEmptyLine(line int, barRange [2]int) { t.renderBar(line, barRange) } -func (t *Terminal) gutter(current bool) { +func (t *Terminal) gutter(current bool, alt bool) { var color tui.ColorPair if current { color = tui.ColCurrentCursorEmpty } else if !t.raw && t.gutterReverse || t.raw && t.gutterRawReverse { - color = tui.ColCursorEmpty + if alt { + color = tui.ColAltCursorEmpty + } else { + color = tui.ColCursorEmpty + } } else { - color = tui.ColCursorEmptyChar + if alt { + color = tui.ColAltCursorEmptyChar + } else { + color = tui.ColCursorEmptyChar + } } gutter := t.pointerEmpty if t.raw { @@ -3220,7 +3228,7 @@ func (t *Terminal) gutter(current bool) { func (t *Terminal) renderGapLine(line int, barRange [2]int, drawLine bool) { t.move(line, 0, false) - t.gutter(false) + t.gutter(false, false) t.window.Print(t.markerEmpty) x := t.pointerLen + t.markerLen @@ -3394,7 +3402,7 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu return indentSize } if len(label) == 0 { - t.gutter(true) + t.gutter(true, false) } else { t.window.CPrint(tui.ColCurrentCursor, label) } @@ -3416,7 +3424,7 @@ func (t *Terminal) printItem(result Result, line int, maxLine int, index int, cu return indentSize } if len(label) == 0 { - t.gutter(false) + t.gutter(false, index%2 == 1) } else { t.window.CPrint(tui.ColCursor, label) } diff --git a/src/tui/tui.go b/src/tui/tui.go index 2de49f06..c29c4181 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -456,6 +456,7 @@ type ColorTheme struct { PreviewBg ColorAttr DarkBg ColorAttr Gutter ColorAttr + AltGutter ColorAttr Prompt ColorAttr InputBg ColorAttr InputBorder ColorAttr @@ -826,6 +827,8 @@ var ( ColCursor ColorPair ColCursorEmpty ColorPair ColCursorEmptyChar ColorPair + ColAltCursorEmpty ColorPair + ColAltCursorEmptyChar ColorPair ColMarker ColorPair ColSelected ColorPair ColSelectedMatch ColorPair @@ -891,6 +894,7 @@ func init() { PreviewFg: defaultColor, PreviewBg: defaultColor, Gutter: undefined, + AltGutter: undefined, PreviewBorder: defaultColor, PreviewScrollbar: defaultColor, PreviewLabel: defaultColor, @@ -943,6 +947,7 @@ func init() { PreviewFg: undefined, PreviewBg: undefined, Gutter: undefined, + AltGutter: undefined, PreviewBorder: undefined, PreviewScrollbar: undefined, PreviewLabel: undefined, @@ -991,6 +996,7 @@ func init() { PreviewFg: undefined, PreviewBg: undefined, Gutter: undefined, + AltGutter: undefined, PreviewBorder: undefined, PreviewScrollbar: undefined, PreviewLabel: undefined, @@ -1041,6 +1047,7 @@ func init() { PreviewFg: undefined, PreviewBg: undefined, Gutter: undefined, + AltGutter: undefined, PreviewBorder: undefined, PreviewScrollbar: undefined, PreviewLabel: undefined, @@ -1091,6 +1098,7 @@ func init() { PreviewFg: undefined, PreviewBg: undefined, Gutter: undefined, + AltGutter: undefined, PreviewBorder: undefined, PreviewScrollbar: undefined, PreviewLabel: undefined, @@ -1208,6 +1216,7 @@ func InitTheme(theme *ColorTheme, baseTheme *ColorTheme, boldify bool, forceBlac gutter.Attr = Dim } theme.Gutter = o(theme.DarkBg, gutter) + theme.AltGutter = o(theme.Gutter, theme.AltGutter) theme.PreviewFg = o(theme.Fg, theme.PreviewFg) theme.PreviewBg = o(theme.Bg, theme.PreviewBg) theme.PreviewLabel = o(theme.BorderLabel, theme.PreviewLabel) @@ -1277,6 +1286,8 @@ func initPalette(theme *ColorTheme) { ColCursor = pair(theme.Cursor, theme.Gutter) ColCursorEmpty = pair(blank, theme.Gutter) ColCursorEmptyChar = pair(theme.Gutter, theme.ListBg) + ColAltCursorEmpty = pair(blank, theme.AltGutter) + ColAltCursorEmptyChar = pair(theme.AltGutter, theme.ListBg) if theme.SelectedBg.Color != theme.ListBg.Color { ColMarker = pair(theme.Marker, theme.SelectedBg) } else {