mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
fix: prevent renderer from overflowing available height
Drops lines from the top when the render buffer is taller than the available height. Fixes #297.
This commit is contained in:
@@ -136,6 +136,15 @@ func (r *standardRenderer) flush() {
|
|||||||
out := termenv.NewOutput(buf)
|
out := termenv.NewOutput(buf)
|
||||||
|
|
||||||
newLines := strings.Split(r.buf.String(), "\n")
|
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)
|
numLinesThisFlush := len(newLines)
|
||||||
oldLines := strings.Split(r.lastRender, "\n")
|
oldLines := strings.Split(r.lastRender, "\n")
|
||||||
skipLines := make(map[int]struct{})
|
skipLines := make(map[int]struct{})
|
||||||
|
|||||||
Reference in New Issue
Block a user