m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-14 14:23:47 -05:00

Do not process ANSI codes in --preview output at once

Close #598
This commit is contained in:
Junegunn Choi
2016-06-14 21:52:47 +09:00
parent c39c039e15
commit 24e1fabf2e
5 changed files with 19 additions and 24 deletions

View File

@@ -556,7 +556,7 @@ func (t *Terminal) printHeader() {
if line >= max {
continue
}
trimmed, colors, newState := extractColor(lineStr, state)
trimmed, colors, newState := extractColor(lineStr, state, nil)
state = newState
item := &Item{
text: []rune(trimmed),
@@ -730,25 +730,13 @@ func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, c
}
func (t *Terminal) printPreview() {
trimmed, ansiOffsets, _ := extractColor(t.previewTxt, nil)
var index int32
t.pwindow.Erase()
for _, o := range ansiOffsets {
b := o.offset[0]
e := o.offset[1]
if b > index {
if !t.pwindow.Fill(trimmed[index:b]) {
return
}
extractColor(t.previewTxt, nil, func(str string, ansi *ansiState) bool {
if ansi != nil && ansi.colored() {
return t.pwindow.CFill(str, ansi.fg, ansi.bg, ansi.bold)
}
if !t.pwindow.CFill(trimmed[b:e], o.color.fg, o.color.bg, o.color.bold) {
return
}
index = e
}
if int(index) < len(trimmed) {
t.pwindow.Fill(trimmed[index:])
}
return t.pwindow.Fill(str)
})
}
func processTabs(runes []rune, prefixWidth int) (string, int) {