diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2025-10-01 23:47:09 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2025-10-09 00:17:00 +0900 |
| commit | 91beacf0f4966e0e5ddbcdedae008d8a66f93ab9 (patch) | |
| tree | 978a5cdb30bcf2ce8f9faacda024a2baffa83af1 /src/result.go | |
| parent | e6ad01fb90df7e324068f61ae96e056f327959c7 (diff) | |
| download | fzf-91beacf0f4966e0e5ddbcdedae008d8a66f93ab9.tar.gz | |
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
Diffstat (limited to 'src/result.go')
| -rw-r--r-- | src/result.go | 15 |
1 files changed, 13 insertions, 2 deletions
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}) } |
