diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2025-05-30 20:33:21 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2025-05-30 20:33:21 +0900 |
| commit | 54fd92b7ddb22647170110790391d39a1065a863 (patch) | |
| tree | eec53682d699d1417f73b2205ecce0fe61af0970 /src | |
| parent | 835906d392aa6a3c8596d2c81414f0d73eaf99aa (diff) | |
| download | fzf-54fd92b7ddb22647170110790391d39a1065a863.tar.gz | |
--no-color: Keep ANSI attributes in the list
Example:
echo -e "\x1b[33;3mfoo \x1b[34;4mbar\x1b[m baz" | fzf --ansi --no-color
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.go | 21 | ||||
| -rw-r--r-- | src/result.go | 5 |
2 files changed, 10 insertions, 16 deletions
diff --git a/src/core.go b/src/core.go index 961d0d37..dffc4f36 100644 --- a/src/core.go +++ b/src/core.go @@ -74,20 +74,11 @@ func Run(opts *Options) (int, error) { var lineAnsiState, prevLineAnsiState *ansiState if opts.Ansi { - if opts.Theme.Colored { - ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) { - prevLineAnsiState = lineAnsiState - trimmed, offsets, newState := extractColor(byteString(data), lineAnsiState, nil) - lineAnsiState = newState - return util.ToChars(stringBytes(trimmed)), offsets - } - } else { - // When color is disabled but ansi option is given, - // we simply strip out ANSI codes from the input - ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) { - trimmed, _, _ := extractColor(byteString(data), nil, nil) - return util.ToChars(stringBytes(trimmed)), nil - } + ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) { + prevLineAnsiState = lineAnsiState + trimmed, offsets, newState := extractColor(byteString(data), lineAnsiState, nil) + lineAnsiState = newState + return util.ToChars(stringBytes(trimmed)), offsets } } @@ -112,7 +103,7 @@ func Run(opts *Options) (int, error) { nthTransformer := opts.WithNth(opts.Delimiter) chunkList = NewChunkList(cache, func(item *Item, data []byte) bool { tokens := Tokenize(byteString(data), opts.Delimiter) - if opts.Ansi && opts.Theme.Colored && len(tokens) > 1 { + if opts.Ansi && len(tokens) > 1 { var ansiState *ansiState if prevLineAnsiState != nil { ansiStateDup := *prevLineAnsiState diff --git a/src/result.go b/src/result.go index 3e4a81c0..acd7bb06 100644 --- a/src/result.go +++ b/src/result.go @@ -179,6 +179,9 @@ func (result *Result) colorOffsets(matchOffsets []Offset, nthOffsets []Offset, t var curr cellInfo = cellInfo{0, false, false, false} start := 0 ansiToColorPair := func(ansi ansiOffset, base tui.ColorPair) tui.ColorPair { + if !theme.Colored { + return tui.NewColorPair(-1, -1, ansi.color.attr).MergeAttr(base) + } fg := ansi.color.fg bg := ansi.color.bg if fg == -1 { @@ -200,7 +203,7 @@ func (result *Result) colorOffsets(matchOffsets []Offset, nthOffsets []Offset, t color = colBase.Merge(colMatch) } var url *url - if curr.color && theme.Colored { + if curr.color { ansi := itemColors[curr.index] url = ansi.color.url origColor := ansiToColorPair(ansi, colMatch) |
