From 70be13948a65c6700a72668646b7260c7a6105d6 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 14 May 2021 19:53:22 -0400 Subject: [PATCH] Re-render all lines if the total number of lines increases If the number of lines increased there's a chance that the increase in lines caused the terminal to scroll (even in the altscreen). Because of this we must repaint everything, as skipping lines will mis-render. Thanks to @fiws for reporting this bug. --- standard_renderer.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/standard_renderer.go b/standard_renderer.go index eb6d25f8d4..0eda45b8e8 100644 --- a/standard_renderer.go +++ b/standard_renderer.go @@ -114,7 +114,14 @@ func (r *standardRenderer) flush() { // 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 || (len(newLines) > i && len(oldLines) > i && newLines[i] == oldLines[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])) { skipLines[i] = struct{}{} } else { clearLine(out) @@ -163,7 +170,7 @@ func (r *standardRenderer) flush() { _, _ = io.WriteString(out, line) - if i != len(newLines)-1 { + if i < len(newLines)-1 { _, _ = io.WriteString(out, "\r\n") } }