--no-color: Keep ANSI attributes in preview window

Example:
  fzf --preview 'echo -e "\x1b[33;3mfoo \x1b[34;4mbar\x1b[m baz"' --no-color
This commit is contained in:
Junegunn Choi
2025-05-30 20:26:07 +09:00
parent 1721e6a1ed
commit 835906d392

View File

@@ -3559,10 +3559,15 @@ Loop:
str, width := t.processTabs(trimmed, prefixWidth)
if width > prefixWidth {
prefixWidth = width
if t.theme.Colored && ansi != nil && ansi.colored() {
colored := ansi != nil && ansi.colored()
if t.theme.Colored && colored {
fillRet = t.pwindow.CFill(ansi.fg, ansi.bg, ansi.attr, str)
} else {
fillRet = t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), tui.AttrRegular, str)
attr := tui.AttrRegular
if colored {
attr = ansi.attr
}
fillRet = t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), attr, str)
}
}
return !isTrimmed &&