Respect ANSI color state from the previous line in preview output

This commit is contained in:
Junegunn Choi 2017-05-28 02:26:42 +09:00
parent cf4711d878
commit 5d6eb5bfd6
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -954,6 +954,7 @@ func (t *Terminal) printPreview() {
} }
reader := bufio.NewReader(strings.NewReader(t.previewer.text)) reader := bufio.NewReader(strings.NewReader(t.previewer.text))
lineNo := -t.previewer.offset lineNo := -t.previewer.offset
var ansi *ansiState
for { for {
line, err := reader.ReadString('\n') line, err := reader.ReadString('\n')
eof := err == io.EOF eof := err == io.EOF
@ -965,7 +966,7 @@ func (t *Terminal) printPreview() {
break break
} else if lineNo > 0 { } else if lineNo > 0 {
var fillRet tui.FillReturn var fillRet tui.FillReturn
extractColor(line, nil, func(str string, ansi *ansiState) bool { _, _, ansi = extractColor(line, ansi, func(str string, ansi *ansiState) bool {
trimmed := []rune(str) trimmed := []rune(str)
if !t.preview.wrap { if !t.preview.wrap {
trimmed, _ = t.trimRight(trimmed, maxWidth-t.pwindow.X()) trimmed, _ = t.trimRight(trimmed, maxWidth-t.pwindow.X())