From cd9517b67964ec281605d4375f5b4a37f8a77282 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 4 May 2025 14:32:06 +0900 Subject: Add 'alt-bg' color for striped lines (#4370) Test cases: 1. 'jump' should show alternating background colors even when 'alt-bg' is not defined as before. go run main.go --bind load:jump Two differences: * The alternating lines will not be in bold (was a bug) * The marker column will not be rendered with alternating background color 2. Use alternating background color when 'alt-bg' is set go run main.go --color bg:238,alt-bg:237 go run main.go --color bg:238,alt-bg:237 --highlight-line 3. 'selected-bg' should take precedence go run main.go --color bg:238,alt-bg:237,selected-bg:232 \ --highlight-line --multi --bind 'load:select+up+select+up' 4. Should work with text with ANSI colors declare -f | perl -0777 -pe 's/^}\n/}\0/gm' | bat --plain --language bash --color always | go run main.go --read0 --ansi --reverse --multi \ --color bg:237,alt-bg:238,current-bg:236 --highlight-line --- Close #4354 Fix #4372 --- src/result.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'src/result.go') diff --git a/src/result.go b/src/result.go index 28d42e7d..3e4a81c0 100644 --- a/src/result.go +++ b/src/result.go @@ -119,7 +119,7 @@ func minRank() Result { return Result{item: &minItem, points: [4]uint16{math.MaxUint16, 0, 0, 0}} } -func (result *Result) colorOffsets(matchOffsets []Offset, nthOffsets []Offset, theme *tui.ColorTheme, colBase tui.ColorPair, colMatch tui.ColorPair, attrNth tui.Attr, current bool) []colorOffset { +func (result *Result) colorOffsets(matchOffsets []Offset, nthOffsets []Offset, theme *tui.ColorTheme, colBase tui.ColorPair, colMatch tui.ColorPair, attrNth tui.Attr) []colorOffset { itemColors := result.item.Colors() // No ANSI codes @@ -182,18 +182,10 @@ func (result *Result) colorOffsets(matchOffsets []Offset, nthOffsets []Offset, t fg := ansi.color.fg bg := ansi.color.bg if fg == -1 { - if current { - fg = theme.Current.Color - } else { - fg = theme.Fg.Color - } + fg = colBase.Fg() } if bg == -1 { - if current { - bg = theme.DarkBg.Color - } else { - bg = theme.Bg.Color - } + bg = colBase.Bg() } return tui.NewColorPair(fg, bg, ansi.color.attr).MergeAttr(base) } -- cgit v1.2.3