sixel: Better handling of animated GIFs (#2544)

This commit is contained in:
Junegunn Choi 2023-11-02 00:15:02 +09:00
parent 69176fc5f4
commit a0145cebf2
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
2 changed files with 10 additions and 5 deletions

View File

@ -66,7 +66,7 @@ func init() {
// * https://github.com/tmux/tmux/wiki/FAQ#what-is-the-passthrough-escape-sequence-and-how-do-i-use-it
// * https://sw.kovidgoyal.net/kitty/graphics-protocol
// * https://en.wikipedia.org/wiki/Sixel
passThroughRegex = regexp.MustCompile(`\x1bPtmux;\x1b\x1b.*?[^\x1b]\x1b\\|\x1b(_G|P[0-9;]*q).*?\x1b\\`)
passThroughRegex = regexp.MustCompile(`\x1bPtmux;\x1b\x1b.*?[^\x1b]\x1b\\|\x1b(_G|P[0-9;]*q).*?\x1b\\\r?`)
}
type jumpMode int
@ -1996,6 +1996,7 @@ func (t *Terminal) renderPreviewText(height int, lines []string, lineNo int, unc
maxWidth := t.pwindow.Width()
var ansi *ansiState
spinnerRedraw := t.pwindow.Y() == 0
wiped := false
sixel := false
wireframe := false
Loop:
@ -2023,7 +2024,7 @@ Loop:
t.renderPreviewSpinner()
t.pwindow.Move(y, x)
}
for _, passThrough := range passThroughs {
for idx, passThrough := range passThroughs {
// Handling Sixel output
requiredLines := 0
isSixel := strings.HasPrefix(passThrough, "\x1bP")
@ -2050,13 +2051,18 @@ Loop:
}
// Clear previous wireframe or any other text
if t.previewed.wireframe || isSixel && !t.previewed.sixel {
if (t.previewed.wireframe || isSixel && !t.previewed.sixel) && !wiped {
wiped = true
for i := y + 1; i < height; i++ {
t.pwindow.MoveAndClear(i, 0)
}
}
sixel = sixel || isSixel
t.pwindow.MoveAndClear(y, x)
if idx == 0 {
t.pwindow.MoveAndClear(y, x)
} else {
t.pwindow.Move(y, x)
}
t.tui.PassThrough(passThrough)
if requiredLines > 0 {

View File

@ -33,7 +33,6 @@ var offsetRegexpBegin *regexp.Regexp = regexp.MustCompile("^\x1b\\[[0-9]+;[0-9]+
func (r *LightRenderer) PassThrough(str string) {
r.queued.WriteString("\x1b7" + str + "\x1b8")
r.flush()
}
func (r *LightRenderer) stderr(str string) {