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/tui/tui.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/tui') diff --git a/src/tui/tui.go b/src/tui/tui.go index e181deaa..4a8ffbed 100644 --- a/src/tui/tui.go +++ b/src/tui/tui.go @@ -308,6 +308,12 @@ func (p ColorPair) WithAttr(attr Attr) ColorPair { return dup } +func (p ColorPair) WithBg(bg ColorAttr) ColorPair { + dup := p + bgPair := ColorPair{colUndefined, bg.Color, bg.Attr} + return dup.Merge(bgPair) +} + func (p ColorPair) MergeAttr(other ColorPair) ColorPair { return p.WithAttr(other.attr) } @@ -328,6 +334,7 @@ type ColorTheme struct { Bg ColorAttr ListFg ColorAttr ListBg ColorAttr + AltBg ColorAttr Nth ColorAttr SelectedFg ColorAttr SelectedBg ColorAttr @@ -735,6 +742,7 @@ func EmptyTheme() *ColorTheme { Bg: ColorAttr{colUndefined, AttrUndefined}, ListFg: ColorAttr{colUndefined, AttrUndefined}, ListBg: ColorAttr{colUndefined, AttrUndefined}, + AltBg: ColorAttr{colUndefined, AttrUndefined}, SelectedFg: ColorAttr{colUndefined, AttrUndefined}, SelectedBg: ColorAttr{colUndefined, AttrUndefined}, SelectedMatch: ColorAttr{colUndefined, AttrUndefined}, @@ -780,6 +788,7 @@ func NoColorTheme() *ColorTheme { Bg: ColorAttr{colDefault, AttrUndefined}, ListFg: ColorAttr{colDefault, AttrUndefined}, ListBg: ColorAttr{colDefault, AttrUndefined}, + AltBg: ColorAttr{colUndefined, AttrUndefined}, SelectedFg: ColorAttr{colDefault, AttrUndefined}, SelectedBg: ColorAttr{colDefault, AttrUndefined}, SelectedMatch: ColorAttr{colDefault, AttrUndefined}, @@ -825,6 +834,7 @@ func init() { Bg: ColorAttr{colDefault, AttrUndefined}, ListFg: ColorAttr{colUndefined, AttrUndefined}, ListBg: ColorAttr{colUndefined, AttrUndefined}, + AltBg: ColorAttr{colUndefined, AttrUndefined}, SelectedFg: ColorAttr{colUndefined, AttrUndefined}, SelectedBg: ColorAttr{colUndefined, AttrUndefined}, SelectedMatch: ColorAttr{colUndefined, AttrUndefined}, @@ -864,6 +874,7 @@ func init() { Bg: ColorAttr{colDefault, AttrUndefined}, ListFg: ColorAttr{colUndefined, AttrUndefined}, ListBg: ColorAttr{colUndefined, AttrUndefined}, + AltBg: ColorAttr{colUndefined, AttrUndefined}, SelectedFg: ColorAttr{colUndefined, AttrUndefined}, SelectedBg: ColorAttr{colUndefined, AttrUndefined}, SelectedMatch: ColorAttr{colUndefined, AttrUndefined}, @@ -903,6 +914,7 @@ func init() { Bg: ColorAttr{colDefault, AttrUndefined}, ListFg: ColorAttr{colUndefined, AttrUndefined}, ListBg: ColorAttr{colUndefined, AttrUndefined}, + AltBg: ColorAttr{colUndefined, AttrUndefined}, SelectedFg: ColorAttr{colUndefined, AttrUndefined}, SelectedBg: ColorAttr{colUndefined, AttrUndefined}, SelectedMatch: ColorAttr{colUndefined, AttrUndefined}, -- cgit v1.2.3