mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-17 07:43:39 -05:00
--no-color: Keep ANSI attributes in the list
Example: echo -e "\x1b[33;3mfoo \x1b[34;4mbar\x1b[m baz" | fzf --ansi --no-color
This commit is contained in:
11
src/core.go
11
src/core.go
@@ -74,21 +74,12 @@ func Run(opts *Options) (int, error) {
|
|||||||
|
|
||||||
var lineAnsiState, prevLineAnsiState *ansiState
|
var lineAnsiState, prevLineAnsiState *ansiState
|
||||||
if opts.Ansi {
|
if opts.Ansi {
|
||||||
if opts.Theme.Colored {
|
|
||||||
ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) {
|
ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) {
|
||||||
prevLineAnsiState = lineAnsiState
|
prevLineAnsiState = lineAnsiState
|
||||||
trimmed, offsets, newState := extractColor(byteString(data), lineAnsiState, nil)
|
trimmed, offsets, newState := extractColor(byteString(data), lineAnsiState, nil)
|
||||||
lineAnsiState = newState
|
lineAnsiState = newState
|
||||||
return util.ToChars(stringBytes(trimmed)), offsets
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chunk list
|
// Chunk list
|
||||||
@@ -112,7 +103,7 @@ func Run(opts *Options) (int, error) {
|
|||||||
nthTransformer := opts.WithNth(opts.Delimiter)
|
nthTransformer := opts.WithNth(opts.Delimiter)
|
||||||
chunkList = NewChunkList(cache, func(item *Item, data []byte) bool {
|
chunkList = NewChunkList(cache, func(item *Item, data []byte) bool {
|
||||||
tokens := Tokenize(byteString(data), opts.Delimiter)
|
tokens := Tokenize(byteString(data), opts.Delimiter)
|
||||||
if opts.Ansi && opts.Theme.Colored && len(tokens) > 1 {
|
if opts.Ansi && len(tokens) > 1 {
|
||||||
var ansiState *ansiState
|
var ansiState *ansiState
|
||||||
if prevLineAnsiState != nil {
|
if prevLineAnsiState != nil {
|
||||||
ansiStateDup := *prevLineAnsiState
|
ansiStateDup := *prevLineAnsiState
|
||||||
|
|||||||
@@ -179,6 +179,9 @@ func (result *Result) colorOffsets(matchOffsets []Offset, nthOffsets []Offset, t
|
|||||||
var curr cellInfo = cellInfo{0, false, false, false}
|
var curr cellInfo = cellInfo{0, false, false, false}
|
||||||
start := 0
|
start := 0
|
||||||
ansiToColorPair := func(ansi ansiOffset, base tui.ColorPair) tui.ColorPair {
|
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
|
fg := ansi.color.fg
|
||||||
bg := ansi.color.bg
|
bg := ansi.color.bg
|
||||||
if fg == -1 {
|
if fg == -1 {
|
||||||
@@ -200,7 +203,7 @@ func (result *Result) colorOffsets(matchOffsets []Offset, nthOffsets []Offset, t
|
|||||||
color = colBase.Merge(colMatch)
|
color = colBase.Merge(colMatch)
|
||||||
}
|
}
|
||||||
var url *url
|
var url *url
|
||||||
if curr.color && theme.Colored {
|
if curr.color {
|
||||||
ansi := itemColors[curr.index]
|
ansi := itemColors[curr.index]
|
||||||
url = ansi.color.url
|
url = ansi.color.url
|
||||||
origColor := ansiToColorPair(ansi, colMatch)
|
origColor := ansiToColorPair(ansi, colMatch)
|
||||||
|
|||||||
Reference in New Issue
Block a user