Skip to content
Myr

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

2 files+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.23To quit sooner press ctrl-c, or press ctrl-z to suspend...4Hi. This program will exit in 9 seconds.56To quit sooner press ctrl-c, or press ctrl-z to suspend...7 [?2004l[?25h[?1002l[?1003l[?1006l5 [?2004l[?25h[?1002l[?1003l[?1006l
modified:standard_renderer.go+29 added-24 removed
172 unmodified lines
173 buf.WriteString(ansi.CursorUp(r.linesRendered - 1))174 }175176 newLines := strings.Split(r.buf.String(), "\n")177 oldLines := strings.Split(r.lastRender, "\n")178179 // 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 scrollback
20 unmodified lines
202 }203204 // 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.208209 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 }216217 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 }222219 // Removing previousy rendered content at the end of line.220 line = line + ansi.EraseLineRight223 line := newLines[i]224222 // 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.EraseLineRight227233 _, _ = 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 }238235 if i < len(newLines)-1 {236 _, _ = buf.WriteString("\r\n")237 }239 _, _ = buf.WriteString(line)240241 if i < len(newLines)-1 {242 _, _ = buf.WriteString("\r\n")243 }244 }245246 // Clearing left over content from last render.
503 unmodified lines