From abd0dab0cb1985355a8687c393ed61813e4c6d86 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 4 May 2025 09:55:41 +0900 Subject: [PATCH] Fix alt-bg for colored text segments --- CHANGELOG.md | 18 ++++++++++++++++++ src/result.go | 14 +++----------- src/result_test.go | 4 ++-- src/terminal.go | 4 ++-- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b426e74..66c42be8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,24 @@ CHANGELOG ========= +0.62.0 +------ + +- Added `alt-bg` color to create striped lines to visually separate rows + ```sh + fzf --color bg:237,alt-bg:238,current-bg:236 --highlight-line + + declare -f | perl -0777 -pe 's/^}\n/}\0/gm' | + bat --plain --language bash --color always | + fzf --read0 --ansi --reverse --multi \ + --color bg:237,alt-bg:238,current-bg:236 --highlight-line + ``` +- [fish] Improvements in CTRL-R binding (@bitraid) + - You can trigger CTRL-R in the middle of a command to insert the selected item + - You can delete history items with SHIFT-DEL +- Bug fixes and improvements + - Fixed unnecessary 100ms delay after `reload` + 0.61.3 ------ - Reverted #4351 as it caused `tmux run-shell 'fzf --tmux'` to fail (#4559 #4560) 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) } diff --git a/src/result_test.go b/src/result_test.go index 520ee4b1..79cc1ee2 100644 --- a/src/result_test.go +++ b/src/result_test.go @@ -131,7 +131,7 @@ func TestColorOffset(t *testing.T) { colBase := tui.NewColorPair(89, 189, tui.AttrUndefined) colMatch := tui.NewColorPair(99, 199, tui.AttrUndefined) - colors := item.colorOffsets(offsets, nil, tui.Dark256, colBase, colMatch, tui.AttrUndefined, true) + colors := item.colorOffsets(offsets, nil, tui.Dark256, colBase, colMatch, tui.AttrUndefined) assert := func(idx int, b int32, e int32, c tui.ColorPair) { o := colors[idx] if o.offset[0] != b || o.offset[1] != e || o.color != c { @@ -158,7 +158,7 @@ func TestColorOffset(t *testing.T) { nthOffsets := []Offset{{37, 39}, {42, 45}} for _, attr := range []tui.Attr{tui.AttrRegular, tui.StrikeThrough} { - colors = item.colorOffsets(offsets, nthOffsets, tui.Dark256, colRegular, colUnderline, attr, true) + colors = item.colorOffsets(offsets, nthOffsets, tui.Dark256, colRegular, colUnderline, attr) // [{[0 5] {1 5 0}} {[5 15] {1 5 8}} {[15 20] {1 5 0}} // {[22 25] {2 6 1}} {[25 27] {2 6 9}} {[27 30] {-1 -1 8}} diff --git a/src/terminal.go b/src/terminal.go index 760a8a73..a79d166f 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1258,7 +1258,7 @@ func (t *Terminal) ansiLabelPrinter(str string, color *tui.ColorPair, fill bool) printFn := func(window tui.Window, limit int) { if offsets == nil { // tui.Col* are not initialized until renderer.Init() - offsets = result.colorOffsets(nil, nil, t.theme, *color, *color, t.nthAttr, false) + offsets = result.colorOffsets(nil, nil, t.theme, *color, *color, t.nthAttr) } for limit > 0 { if length > limit { @@ -3044,7 +3044,7 @@ func (t *Terminal) printHighlighted(result Result, colBase tui.ColorPair, colMat sort.Sort(ByOrder(nthOffsets)) } } - allOffsets := result.colorOffsets(charOffsets, nthOffsets, t.theme, colBase, colMatch, t.nthAttr, current) + allOffsets := result.colorOffsets(charOffsets, nthOffsets, t.theme, colBase, colMatch, t.nthAttr) maxLines := 1 if t.canSpanMultiLines() {