Skip to content
Myr

fix: renderer: keep a separate count of lines rendered in the alt screen

Before adoption: this commit came in with the history the project adopted, so no landing records it.

We need to keep a separate count of lines rendered in the alt screen and inline mode. This is because when we enter alt screen mode, the cursor position is saved and the alt screen is cleared. Now when we exit the alt screen mode, the cursor position is restored so we don't need to move the cursor to the beginning of the section that we rendered. To fix this, we keep a separate count of lines rendered in the alt screen mode and inline mode.

authored by Ayman Bagabas · committed by Ayman Bagabas · parent bc15c1e · Browse files · 1 file+19 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Related: https://github.com/charmbracelet/bubbletea/issues/1013
  • Fixes: https://github.com/charmbracelet/bubbletea/pull/1241
  • Fixes: https://github.com/charmbracelet/bubbletea/issues/1248

Diff stats

1 file+19 added−4 removed

  • other:+19 added−4 removed

1 file+19 added−4 removed

modified:standard_renderer.go+19 added-4 removed
34 unmodified lines
35 done chan struct{}36 lastRender string37 lastRenderedLines []string38 linesRendered int39 altLinesRendered int40 useANSICompressor bool41 once sync.Once4243 // cursor visibility state
126 unmodified lines
170 // Output buffer.171 buf := &bytes.Buffer{}172173 // Moving to the beginning of the section, that we rendered.174 if r.altScreenActive {175 buf.WriteString(ansi.HomeCursorPosition)173 if r.linesRendered > 1 {176 } else if r.linesRendered > 1 {177 buf.WriteString(ansi.CursorUp(r.linesRendered - 1))178 }179180 newLines := strings.Split(r.buf.String(), "\n")
76 unmodified lines
257 _, _ = buf.WriteString("\r\n")258 }259 }260261 lastLinesRendered := r.linesRendered262 if r.altScreenActive {263 lastLinesRendered = r.altLinesRendered264 }265266 // Clearing left over content from last render.259 if r.linesRendered > len(newLines) {267 if lastLinesRendered > len(newLines) {268 buf.WriteString(ansi.EraseScreenBelow)269 }270271 if r.altScreenActive {272 r.altLinesRendered = len(newLines)273 } else {263 r.linesRendered = len(newLines)274 r.linesRendered = len(newLines)275 }276277 // Make sure the cursor is at the start of the last line to keep rendering278 // behavior consistent.279 if r.altScreenActive {280 // This case fixes a bug in macOS terminal. In other terminals the281 // other case seems to do the job regardless of whether or not we're282 // using the full terminal window.271 buf.WriteString(ansi.SetCursorPosition(0, r.linesRendered))283 buf.WriteString(ansi.SetCursorPosition(0, len(newLines)))284 } else {285 buf.WriteString(ansi.CursorLeft(r.width))286 }287
75 unmodified lines
363 } else {364 r.execute(ansi.ShowCursor)365 }366367 // Entering the alt screen resets the lines rendered count.368 r.altLinesRendered = 0369370 r.repaint()371}372373func (r *standardRenderer) exitAltScreen() {
409 unmodified lines