Skip to content

Commit 6c67f5e

Browse files
committed
fix(inquirerer): fix cursor positioning for viewport rendering
On first render, cursor is at bottom after printing newlines, so move up viewportHeight. On subsequent renders, cursor is on last viewport row (no trailing newline), so move up viewportHeight-1. This prevents the 'filling screen upward' bug where each render landed one row higher.
1 parent fe56bad commit 6c67f5e

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

packages/inquirerer/src/ui/viewport.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,16 +234,20 @@ export class ViewportRenderer {
234234
}
235235

236236
// On first render, reserve space by printing empty lines
237-
// This establishes the viewport region
237+
// This establishes the viewport region at the bottom of the terminal
238238
if (!this.hasRenderedOnce) {
239+
// Print viewportHeight newlines to reserve space
239240
for (let i = 0; i < this.viewportHeight; i++) {
240241
this.write('\n');
241242
}
242243
this.hasRenderedOnce = true;
244+
// After first render, cursor is at bottom. Move up viewportHeight to get to top.
245+
this.write(ANSI.cursorUp(this.viewportHeight));
246+
} else {
247+
// On subsequent renders, cursor is on the last viewport row (since we don't emit trailing newline)
248+
// Move up (viewportHeight - 1) to get back to the first viewport row
249+
this.write(ANSI.cursorUp(this.viewportHeight - 1));
243250
}
244-
245-
// Move cursor back to start of viewport
246-
this.write(ANSI.cursorUp(this.viewportHeight));
247251
this.write(ANSI.cursorToStart);
248252

249253
// Clear and redraw each line

0 commit comments

Comments
 (0)