diff --git a/packages/tui/CHANGELOG.md b/packages/tui/CHANGELOG.md index 702f67d9..1ce7dc71 100644 --- a/packages/tui/CHANGELOG.md +++ b/packages/tui/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- TUI renders with wrong dimensions after suspend/resume if terminal was resized while suspended ([#599](https://github.com/badlogic/pi-mono/issues/599)) + ## [0.42.4] - 2026-01-10 ## [0.42.3] - 2026-01-10 diff --git a/packages/tui/src/terminal.ts b/packages/tui/src/terminal.ts index 557d54b6..772668e3 100644 --- a/packages/tui/src/terminal.ts +++ b/packages/tui/src/terminal.ts @@ -70,6 +70,12 @@ export class ProcessTerminal implements Terminal { // Set up resize handler immediately process.stdout.on("resize", this.resizeHandler); + // Refresh terminal dimensions - they may be stale after suspend/resume + // (SIGWINCH is lost while process is stopped). Unix only. + if (process.platform !== "win32") { + process.kill(process.pid, "SIGWINCH"); + } + // Query and enable Kitty keyboard protocol // The query handler intercepts input temporarily, then installs the user's handler // See: https://sw.kovidgoyal.net/kitty/keyboard-protocol/ diff --git a/packages/tui/src/tui.ts b/packages/tui/src/tui.ts index 7f767c98..ca5c8efe 100644 --- a/packages/tui/src/tui.ts +++ b/packages/tui/src/tui.ts @@ -164,7 +164,7 @@ export class TUI extends Container { requestRender(force = false): void { if (force) { this.previousLines = []; - this.previousWidth = 0; + this.previousWidth = -1; // -1 triggers widthChanged, forcing a full clear this.cursorRow = 0; } if (this.renderRequested) return; @@ -334,8 +334,8 @@ export class TUI extends Container { // Width changed - need full re-render const widthChanged = this.previousWidth !== 0 && this.previousWidth !== width; - // First render - just output everything without clearing - if (this.previousLines.length === 0) { + // First render - just output everything without clearing (assumes clean screen) + if (this.previousLines.length === 0 && !widthChanged) { let buffer = "\x1b[?2026h"; // Begin synchronized output for (let i = 0; i < newLines.length; i++) { if (i > 0) buffer += "\r\n";