summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-12-04 19:27:43 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-12-04 19:27:43 +0900
commitd2af3ff98d427d797be809505661aeb84e65e4c7 (patch)
tree7154e7826e163012c2b6ad1132922eb72e389686
parent052d17e66a3e6f9e9e61cec246d20a4dfdee6f71 (diff)
Change how hl:-1 or hl+:-1 is applied to text with background color
-rw-r--r--src/result.go14
-rw-r--r--src/tui/tui.go9
2 files changed, 22 insertions, 1 deletions
diff --git a/src/result.go b/src/result.go
index b3971f44..77b4e3b0 100644
--- a/src/result.go
+++ b/src/result.go
@@ -160,7 +160,19 @@ func (result *Result) colorOffsets(matchOffsets []Offset, theme *tui.ColorTheme,
color := colMatch
if curr < -1 && theme.Colored {
origColor := ansiToColorPair(itemColors[-curr-2], colMatch)
- color = origColor.MergeNonDefault(color)
+ // hl or hl+ only sets the foreground color, so colMatch is the
+ // combination of either [hl and bg] or [hl+ and bg+].
+ //
+ // If the original text already has background color, and the
+ // forground color of colMatch is -1, we shouldn't only apply the
+ // background color of colMatch.
+ // e.g. echo -e "\x1b[32;7mfoo\x1b[mbar" | fzf --ansi --color bg+:1,hl+:-1:underline
+ // echo -e "\x1b[42mfoo\x1b[mbar" | fzf --ansi --color bg+:1,hl+:-1:underline
+ if color.Fg().IsDefault() && origColor.HasBg() {
+ color = origColor
+ } else {
+ color = origColor.MergeNonDefault(color)
+ }
}
colors = append(colors, colorOffset{
offset: [2]int32{int32(start), int32(idx)}, color: color})
diff --git a/src/tui/tui.go b/src/tui/tui.go
index e07e6618..edbc9a14 100644
--- a/src/tui/tui.go
+++ b/src/tui/tui.go
@@ -124,6 +124,10 @@ const (
type Color int32
+func (c Color) IsDefault() bool {
+ return c == colDefault
+}
+
func (c Color) is24() bool {
return c > 0 && (c&(1<<24)) > 0
}
@@ -190,6 +194,11 @@ func (p ColorPair) Attr() Attr {
return p.attr
}
+func (p ColorPair) HasBg() bool {
+ return p.attr&Reverse == 0 && p.bg != colDefault ||
+ p.attr&Reverse > 0 && p.fg != colDefault
+}
+
func (p ColorPair) merge(other ColorPair, except Color) ColorPair {
dup := p
dup.attr = dup.attr.Merge(other.attr)