diff --git a/standard_renderer.go b/standard_renderer.go index c6a1b61017..282c82f231 100644 --- a/standard_renderer.go +++ b/standard_renderer.go @@ -170,19 +170,18 @@ func (r *standardRenderer) flush() { skipLines := make(map[int]struct{}) flushQueuedMessages := len(r.queuedMessageLines) > 0 && !r.altScreenActive - // Add any queued messages to this render - if flushQueuedMessages { - newLines = append(r.queuedMessageLines, newLines...) - r.queuedMessageLines = []string{} - } - // Clear any lines we painted in the last render. if r.linesRendered > 0 { for i := r.linesRendered - 1; i > 0; 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]) { + // if we are clearing queued messages, we want to clear all lines, since + // printing messages allows for native terminal word-wrap, we + // don't have control over the queued lines + if flushQueuedMessages { + out.ClearLine() + } else if (len(newLines) <= len(oldLines)) && (len(newLines) > i && len(oldLines) > i) && (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. skipLines[i] = struct{}{} } else if _, exists := r.ignoreLines[i]; !exists { out.ClearLine() @@ -214,6 +213,16 @@ func (r *standardRenderer) flush() { } } + if flushQueuedMessages { + // Dump the lines we've queued up for printing + for _, line := range r.queuedMessageLines { + _, _ = out.WriteString(line) + _, _ = out.WriteString("\r\n") + } + // clear the queued message lines + r.queuedMessageLines = []string{} + } + // Paint new lines for i := 0; i < len(newLines); i++ { if _, skip := skipLines[i]; skip { @@ -633,6 +642,7 @@ func ScrollDown(newLines []string, topBoundary, bottomBoundary int) Cmd { type printLineMessage struct { messageBody string + // if true, skips truncation of the message } // Println prints above the Program. This output is unmanaged by the program and