feat(render): skipping lines from previous frame
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Konstantin Antonov · committed by Christian Rocha · parent 4f161cd · Browse files · 2 files·+30 added−27 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+30 added−27 removed
- other:+30 added−27 removed
Provenance
- Commit
3dfbcd9- Tree
c0cdb6d- Author
Konstantin Antonov <tino.ant.s@gmail.com>- Committer
Christian Rocha <christian@rocha.is>- Parent
4f161cd
2 files changed+30 added−27 removed
modified:examples/simple/testdata/TestApp.golden+1 added-3 removed
1 [?25l[?2004h
Hi. This program will exit in 10 seconds.[0K2 [0K3 To quit sooner press ctrl-c, or press ctrl-z to suspend...[0K4 [0K[70D[3AHi. This program will exit in 9 seconds.[0K5-[0K6-To quit sooner press ctrl-c, or press ctrl-z to suspend...[0K7-[0K[70D[2K
[?2004l[?25h[?1002l[?1003l[?1006l5+[B[B[70D[2K
[?2004l[?25h[?1002l[?1003l[?1006lmodified:standard_renderer.go+29 added-24 removed
172 unmodified lines173 buf.WriteString(ansi.CursorUp(r.linesRendered - 1))174 }175 176 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 scrollback20 unmodified lines202 }203 204 // Paint new lines.205 for i := 0; i < len(newLines); i++ {205- if _, skip := r.ignoreLines[i]; skip {206+ canSkip := !flushQueuedMessages && // Queuing messages triggers repaint -> we don't have access to previous frame content.207+ len(oldLines) > i && oldLines[i] == newLines[i] // Previously rendered line is the same.208+209+ if _, ignore := r.ignoreLines[i]; ignore || canSkip {210 // Unless this is the last line, move the cursor down.211 if i < len(newLines)-1 {212 buf.WriteString(ansi.CursorDown1)213 }210- } else {211- if i == 0 && r.lastRender == "" {212- // On first render, reset the cursor to the start of the line213- // before writing anything.214- buf.WriteByte('\r')215- }214+ continue215+ }216 217- line := newLines[i]217+ if i == 0 && r.lastRender == "" {218+ // On first render, reset the cursor to the start of the line219+ // before writing anything.220+ buf.WriteByte('\r')221+ }222 219- // Removing previousy rendered content at the end of line.220- line = line + ansi.EraseLineRight223+ line := newLines[i]224 222- // Truncate lines wider than the width of the window to avoid223- // wrapping, which will mess up rendering. If we don't have the224- // width of the window this will be ignored.225- //226- // Note that on Windows we only get the width of the window on227- // program initialization, so after a resize this won't perform228- // correctly (signal SIGWINCH is not supported on Windows).229- if r.width > 0 {230- line = ansi.Truncate(line, r.width, "")231- }225+ // Removing previousy rendered content at the end of line.226+ line = line + ansi.EraseLineRight227 233- _, _ = buf.WriteString(line)228+ // Truncate lines wider than the width of the window to avoid229+ // wrapping, which will mess up rendering. If we don't have the230+ // width of the window this will be ignored.231+ //232+ // Note that on Windows we only get the width of the window on233+ // program initialization, so after a resize this won't perform234+ // correctly (signal SIGWINCH is not supported on Windows).235+ if r.width > 0 {236+ line = ansi.Truncate(line, r.width, "")237+ }238 235- if i < len(newLines)-1 {236- _, _ = buf.WriteString("\r\n")237- }239+ _, _ = buf.WriteString(line)240+241+ if i < len(newLines)-1 {242+ _, _ = buf.WriteString("\r\n")243 }244 }245 246 // Clearing left over content from last render.503 unmodified lines