Skip to content

Commit

Permalink
fix: prevent renderer from overflowing available height
Browse files Browse the repository at this point in the history
Drops lines from the top when the render buffer is taller than the
available height.

Fixes #297.
  • Loading branch information
muesli committed Oct 13, 2022
1 parent b8ef6f8 commit 15f1bcf
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions standard_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ func (r *standardRenderer) flush() {
out := termenv.NewOutput(buf)

newLines := strings.Split(r.buf.String(), "\n")

// If we know the output's height, we can use it to determine how many
// lines we can render. We drop lines from the top of the render buffer if
// necessary, as we can't navigate the cursor into the terminal's scrollback
// buffer.
if r.height > 0 && len(newLines) > r.height {
newLines = newLines[len(newLines)-r.height:]
}

numLinesThisFlush := len(newLines)
oldLines := strings.Split(r.lastRender, "\n")
skipLines := make(map[int]struct{})
Expand Down

0 comments on commit 15f1bcf

Please sign in to comment.