fix: incorrect line skipping in renderer flush (#1233)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* fix line skip in flush * mod tidy in examples dir * reset lastRenderedLines on repaint * docs: add note * fix: simplify line skip logic ---------
authored by Semih Buyukgungor · committed by GitHub · parent 1feb60b · Browse files · 3 files·+19 added−14 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Diff stats
3 files+19 added−14 removed
- other:+19 added−14 removed
Provenance
- Commit
97fc4fa- Tree
a5418bd- Author
Semih Buyukgungor <buyukgungorsemih@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
1feb60b
3 files changed+19 added−14 removed
modified:examples/go.mod+3 added-3 removed
22 unmodified lines23 github.com/aymanbagabas/go-udiff v0.2.0 // indirect24 github.com/aymerick/douceur v0.2.0 // indirect25 github.com/charmbracelet/x/ansi v0.4.5 // indirect26 github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b // indirect27- github.com/charmbracelet/x/term v0.2.0 // indirect27+ github.com/charmbracelet/x/term v0.2.1 // indirect28 github.com/dlclark/regexp2 v1.11.0 // indirect29 github.com/dustin/go-humanize v1.0.1 // indirect30 github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect31 github.com/gorilla/css v1.0.1 // indirect8 unmodified lines40 github.com/sahilm/fuzzy v0.1.1 // indirect41 github.com/yuin/goldmark v1.7.4 // indirect42 github.com/yuin/goldmark-emoji v1.0.3 // indirect43 golang.org/x/net v0.27.0 // indirect44- golang.org/x/sync v0.8.0 // indirect45- golang.org/x/sys v0.26.0 // indirect44+ golang.org/x/sync v0.9.0 // indirect45+ golang.org/x/sys v0.27.0 // indirect46 golang.org/x/term v0.22.0 // indirect47 golang.org/x/text v0.19.0 // indirect48 )49 1 unmodified linemodified:examples/go.sum+6 added-6 removed
26 unmodified lines27 github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b h1:MnAMdlwSltxJyULnrYbkZpp4k58Co7Tah3ciKhSNo0Q=28 github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=29 github.com/charmbracelet/x/exp/teatest v0.0.0-20240521184646-23081fb03b28 h1:sOWKNRjt8uOEVgPiJVIJCse1+mUDM2F/vYY6W0Go640=30 github.com/charmbracelet/x/exp/teatest v0.0.0-20240521184646-23081fb03b28/go.mod h1:l1w+LTJZCCozeGzMEWGxRw6Mo2DfcZUvupz8HGubdes=31-github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=32-github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=31+github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=32+github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=33 github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=34 github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=35 github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=36 github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=38 unmodified lines75 github.com/yuin/goldmark-emoji v1.0.3 h1:aLRkLHOuBR2czCY4R8olwMjID+tENfhyFDMCRhbIQY4=76 github.com/yuin/goldmark-emoji v1.0.3/go.mod h1:tTkZEbwu5wkPmgTcitqddVxY9osFZiavD+r4AzQrh1U=77 golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=78 golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=79-golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=80-golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=79+golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=80+golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=81 golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=82 golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=83-golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=84-golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=83+golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=84+golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=85 golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=86 golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=87 golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=88 golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=modified:standard_renderer.go+10 added-5 removed
32 unmodified lines33 framerate time.Duration34 ticker *time.Ticker35 done chan struct{}36 lastRender string37+ lastRenderedLines []string38 linesRendered int39 useANSICompressor bool40 once sync.Once41 132 unmodified lines174 buf.WriteString(ansi.CursorUp(r.linesRendered - 1))175 }176 177 newLines := strings.Split(r.buf.String(), "\n")177- oldLines := strings.Split(r.lastRender, "\n")178 179 // If we know the output's height, we can use it to determine how many180 // lines we can render. We drop lines from the top of the render buffer if181 // necessary, as we can't navigate the cursor into the terminal's scrollback1 unmodified line183 if r.height > 0 && len(newLines) > r.height {184 newLines = newLines[len(newLines)-r.height:]185 }186 187- numLinesThisFlush := len(newLines)187 flushQueuedMessages := len(r.queuedMessageLines) > 0 && !r.altScreenActive188 189 if flushQueuedMessages {190 // Dump the lines we've queued up for printing.17 unmodified lines208 209 // Paint new lines.210 for i := 0; i < len(newLines); i++ {211 canSkip := !flushQueuedMessages && // Queuing messages triggers repaint -> we don't have access to previous frame content.213- len(oldLines) > i && oldLines[i] == newLines[i] // Previously rendered line is the same.212+ len(r.lastRenderedLines) > i && r.lastRenderedLines[i] == newLines[i] // Previously rendered line is the same.213 214 if _, ignore := r.ignoreLines[i]; ignore || canSkip {215 // Unless this is the last line, move the cursor down.216 if i < len(newLines)-1 {38 unmodified lines255 }256 }257 258 // Clearing left over content from last render.260- if r.linesRendered > numLinesThisFlush {259+ if r.linesRendered > len(newLines) {260 buf.WriteString(ansi.EraseScreenBelow)261 }262 264- r.linesRendered = numLinesThisFlush263+ r.linesRendered = len(newLines)264 265 // Make sure the cursor is at the start of the last line to keep rendering266 // behavior consistent.267 if r.altScreenActive {6 unmodified lines274 }275 276 _, _ = r.out.Write(buf.Bytes())277 r.lastRender = r.buf.String()278+279+ // Save previously rendered lines for comparison in the next render. If we280+ // don't do this, we can't skip rendering lines that haven't changed.281+ // See https://github.com/charmbracelet/bubbletea/pull/1233282+ r.lastRenderedLines = newLines283 r.buf.Reset()284 }285 286 // write writes to the internal buffer. The buffer will be outputted via the15 unmodified lines302 }303 304 func (r *standardRenderer) repaint() {305 r.lastRender = ""306+ r.lastRenderedLines = nil307 }308 309 func (r *standardRenderer) clearScreen() {310 r.mtx.Lock()457 unmodified lines