Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug where explicitly ignored lines weren't honored by the renderer #111

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions standard_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,33 +104,19 @@ func (r *standardRenderer) flush() {
// Clear any lines we painted in the last render.
if r.linesRendered > 0 {
for i := r.linesRendered - 1; i > 0; i-- {
// Determine if we should skip rendering for this line. We can skip
// for two reasons:
//
// 1. We've explicitly set this line to be ignored so we can render
// it elsewhere (for example, via the performance scroll methods
// like insertTop and insertBottom).
//
// 2. The new line is the same as the old line, in which case we
// can skip rendering for this line as a performance optimization.
_, ignoreLine := r.ignoreLines[i]

if ignoreLine ||
// Number of lines did not increase
(len(newLines) <= len(oldLines) &&
// Indexes available for lookup (guard against panics)
len(newLines) > i && len(oldLines) > i &&
// Lines are identical
(newLines[i] == oldLines[i])) {
// If the number of lines we want to render hasn't increased and
// new line is the same as the old line we can skip rendering for
// this line as a performance optimization.
if (len(newLines) <= len(oldLines)) && (len(newLines) > i && len(oldLines) > i) && (newLines[i] == oldLines[i]) {
skipLines[i] = struct{}{}
} else {
} else if _, exists := r.ignoreLines[i]; !exists {
clearLine(out)
}

cursorUp(out)
}

if _, exists := skipLines[0]; !exists {
if _, exists := r.ignoreLines[0]; !exists {
// We need to return to the start of the line here to properly
// erase it. Going back the entire width of the terminal will
// usually be farther than we need to go, but terminal emulators
Expand All @@ -145,6 +131,14 @@ func (r *standardRenderer) flush() {
}
}

// Merge the set of lines we're skipping as a rendering optimization with
// the set of lines we've explicitly asked the renderer to ignore.
if r.ignoreLines != nil {
for k, v := range r.ignoreLines {
skipLines[k] = v
}
}

r.linesRendered = 0

// Paint new lines
Expand Down