Skip to content
Myr

Clear previous non-Sixel text before rendering Sixel image (#2544)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent d3a9a06 · Browse files · 1 file+14 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−8 removed

  • other:+14 added−8 removed

1 file+14 added−8 removed

modified:src/terminal.go+14 added-8 removed
123 unmodified lines
124 version int64125 numLines int126 offset int127 filled bool128 sixel bool129 wipe bool130 wireframe bool131}132
558 unmodified lines
691 reqBox: util.NewEventBox(),692 initialPreviewOpts: opts.Preview,693 previewOpts: opts.Preview,694 previewer: previewer{0, []string{}, 0, false, true, disabledState, "", []bool{}},694 previewed: previewed{0, 0, 0, false, false, false},695 previewed: previewed{0, 0, 0, false, false, false, false},696 previewBox: previewBox,697 eventBox: eventBox,698 mutex: sync.Mutex{},699 suppress: true,
1294 unmodified lines
1994func (t *Terminal) renderPreviewText(height int, lines []string, lineNo int, unchanged bool) {1995 maxWidth := t.pwindow.Width()1996 var ansi *ansiState1997 spinnerRedraw := t.pwindow.Y() == 01998 sixel := false1999 wireframe := false2000Loop:2001 for _, line := range lines {2002 var lbg tui.Color = -12003 if ansi != nil {
20 unmodified lines
2024 }2025 for _, passThrough := range passThroughs {2026 // Handling Sixel output2027 requiredLines := 02025 if strings.HasPrefix(passThrough, "\x1bP") {2028 isSixel := strings.HasPrefix(passThrough, "\x1bP")2029 if isSixel {2030 t.previewed.wipe = true2031 if t.termSize.PxHeight > 0 {2032 rows := util.Max(0, strings.Count(passThrough, "-")-1)2033 requiredLines = int(math.Ceil(float64(rows*6*t.termSize.Lines) / float64(t.termSize.PxHeight)))2034 }2035 }20362033 // Overflow2037 // Render wireframe when Sixel image cannot be displayed entirely2038 if requiredLines > 0 && y+requiredLines > height {2039 top := true2040 for ; y < height; y++ {2041 t.pwindow.MoveAndClear(y, 0)2042 t.pwindow.CFill(tui.ColPreview.Fg(), tui.ColPreview.Bg(), tui.AttrRegular, t.makeImageBorder(maxWidth, top))2043 top = false2044 }2041 t.previewed.wireframe = true2045 wireframe = true2046 t.previewed.filled = true2047 t.previewer.scrollable = true2044 continue2048 break Loop2049 }20502047 if t.previewed.wireframe {2048 t.previewed.wireframe = false2051 // Clear previous wireframe or any other text2052 if t.previewed.wireframe || isSixel && !t.previewed.sixel {2053 for i := y + 1; i < height; i++ {2054 t.pwindow.MoveAndClear(i, 0)2055 }2056 }2057 sixel = sixel || isSixel2058 t.pwindow.MoveAndClear(y, x)2059 t.tui.PassThrough(passThrough)20602061 if requiredLines > 0 {2062 if y+requiredLines == height {2063 t.pwindow.Move(y+requiredLines, 0)2064 t.previewed.filled = true2060 t.previewer.scrollable = true2065 break Loop2066 } else {2067 t.pwindow.MoveAndClear(y+requiredLines, 0)2068 }
43 unmodified lines
2112 }2113 }2114 lineNo++2115 }2116 t.previewed.sixel = sixel2117 t.previewed.wireframe = wireframe2118}21192120func (t *Terminal) renderPreviewScrollbar(yoff int, barLength int, barStart int) {2121 height := t.pwindow.Height()
1876 unmodified lines