Skip to content
Myr

fix: cursor position adjustment after exiting alt screen (#1241)

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

* fix cursor position handling after exiting alt screen mode * avoid moving cursor when lines rendered before alt screen is zero

authored by Semih Buyukgungor · committed by GitHub · parent 76b0f81 · Browse files · 1 file+19 added−0 removed
This commit

State

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

Diff stats

1 file+19 added−0 removed

  • other:+19 added−0 removed

1 file+19 added−0 removed

modified:standard_renderer.go+19 added
55 unmodified lines
56 height int5758 // lines explicitly set not to render59 ignoreLines map[int]struct{}6061 // lines rendered before entering alt screen mode62 linesRenderedBeforeAltScreen int63}6465// newRenderer creates a new renderer. Normally you'll want to initialize it66// with os.Stdout as the first argument.
269 unmodified lines
336337 r.altScreenActive = true338 r.execute(ansi.EnableAltScreenBuffer)339340 // Save the current line count before entering the alternate screen mode.341 // This allows us to compare and adjust the cursor position when exiting the alternate screen.342 r.linesRenderedBeforeAltScreen = r.linesRendered343344 // Ensure that the terminal is cleared, even when it doesn't support345 // alt screen (or alt screen support is disabled, like GNU screen by346 // default).347 //
24 unmodified lines
372373 r.altScreenActive = false374 r.execute(ansi.DisableAltScreenBuffer)375376 // Adjust cursor and screen377 if r.linesRendered < r.linesRenderedBeforeAltScreen {378 // If fewer lines were rendered in the alternate screen, move the cursor up379 // to align with the previous normal screen position and clear any remaining lines.380 r.execute(ansi.CursorUp(r.linesRenderedBeforeAltScreen - r.linesRendered))381 r.execute(ansi.EraseScreenBelow)382 } else if r.linesRendered > r.linesRenderedBeforeAltScreen && r.linesRenderedBeforeAltScreen > 0 {383 // If more lines were rendered in the alternate screen, move the cursor down384 // to align with the new position.385 r.execute(ansi.CursorDown(r.linesRendered - r.linesRenderedBeforeAltScreen))386 }387388 // cmd.exe and other terminals keep separate cursor states for the AltScreen389 // and the main buffer. We have to explicitly reset the cursor visibility390 // whenever we exit AltScreen.391 if r.cursorHidden {
395 unmodified lines