Fix TUI rendering with wrong dimensions after suspend/resume

- Send SIGWINCH to self on terminal start to refresh stale dimensions (Unix only)
- Change requestRender(true) to set previousWidth = -1 to trigger widthChanged
- Update first render condition to skip when widthChanged is true

Fixes #599
This commit is contained in:
Mario Zechner 2026-01-11 02:47:28 +01:00
parent 019ad0ec11
commit d7394eb109
3 changed files with 13 additions and 3 deletions

View file

@ -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

View file

@ -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/

View file

@ -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";