From 91beacf0f4966e0e5ddbcdedae008d8a66f93ab9 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 1 Oct 2025 23:47:09 +0900 Subject: Add special 'strip' style attribute for stripping colors Test cases: fd --color always | fzf --ansi --delimiter / fd --color always | fzf --ansi --delimiter / --nth -1 --color fg:dim,nth:regular fd --color always | fzf --ansi --delimiter / --nth -1 --color fg:dim:strip,nth:regular fd --color always | fzf --ansi --delimiter / --nth -1 --color fg:dim:strip,nth:regular --raw fd --color always | fzf --ansi --delimiter / --nth -1 --color fg:dim:strip,nth:regular,hidden:strikethrough --raw fd --color always | fzf --ansi --delimiter / --nth -1 --color fg:dim:strip,nth:regular,hidden:strip:strikethrough --raw fd --color always | fzf --ansi --delimiter / --nth -1 --color fg:dim:strip,nth:regular,hidden:strip:dim:strikethrough --raw --- src/result.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/result.go') diff --git a/src/result.go b/src/result.go index 36f56fb7..d6811dc8 100644 --- a/src/result.go +++ b/src/result.go @@ -123,7 +123,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) []colorOffset { +func (result *Result) colorOffsets(matchOffsets []Offset, nthOffsets []Offset, theme *tui.ColorTheme, colBase tui.ColorPair, colMatch tui.ColorPair, attrNth tui.Attr, hidden bool) []colorOffset { itemColors := result.item.Colors() // No ANSI codes @@ -194,6 +194,10 @@ func (result *Result) colorOffsets(matchOffsets []Offset, nthOffsets []Offset, t if !theme.Colored { return tui.NewColorPair(-1, -1, ansi.color.attr).MergeAttr(base) } + // fd --color always | fzf --ansi --delimiter / --nth -1 --color fg:dim:strip,nth:regular + if base.ShouldStripColors() { + return base + } fg := ansi.color.fg bg := ansi.color.bg if fg == -1 { @@ -251,6 +255,9 @@ func (result *Result) colorOffsets(matchOffsets []Offset, nthOffsets []Offset, t if curr.nth { base = base.WithAttr(attrNth) } + if hidden { + base = base.WithFg(theme.Hidden) + } color := ansiToColorPair(ansi, base) colors = append(colors, colorOffset{ offset: [2]int32{int32(start), int32(idx)}, @@ -258,9 +265,13 @@ func (result *Result) colorOffsets(matchOffsets []Offset, nthOffsets []Offset, t match: false, url: ansi.color.url}) } else { + color := colBase.WithAttr(attrNth) + if hidden { + color = color.WithFg(theme.Hidden) + } colors = append(colors, colorOffset{ offset: [2]int32{int32(start), int32(idx)}, - color: colBase.WithAttr(attrNth), + color: color, match: false, url: nil}) } -- cgit v1.2.3