Skip to content

fix: detect terminal resize on Windows via console buffer polling#119

Merged
meszmate merged 1 commit into
mainfrom
issue-114
Jun 27, 2026
Merged

fix: detect terminal resize on Windows via console buffer polling#119
meszmate merged 1 commit into
mainfrom
issue-114

Conversation

@meszmate

Copy link
Copy Markdown
Owner

Problem

Fixes #114. On Windows, checkResize() was a stub that always returned false, so Program.tick() never entered the resize branch — context.width/context.height stayed frozen at startup values and the window_size message was never dispatched. zigzag TUIs on Windows never adapted to a resized terminal window.

Fix

Detect resize by polling GetConsoleScreenBufferInfo and comparing the srWindow dimensions against the last observed size.

WINDOW_BUFFER_SIZE_EVENT is intentionally not used: per the Windows Console docs, those records are only queued when ENABLE_WINDOW_INPUT is set on the input mode, which enableRawMode deliberately avoids (it wakes the stdin wait-handle without producing ReadFile bytes). Polling is the only viable mechanism under the current input mode, and it works under the classic console host. Under ConPTY/Windows Terminal a transiently stale reading self-corrects because the size is re-polled every frame; it degrades gracefully (returns false) when stdout isn't a console.

Notes:

  • A first-read guard establishes the baseline so startup doesn't report a spurious resize.
  • checkResize now takes the same stdout handle getSize uses (state.stdout_handle), so detection and measurement agree when a custom Config.output handle is set.

Verification

  • Compiles clean for Windows (x86_64-windows-gnu), POSIX (native), and WASM.
  • zig build test passes.

checkResize() was a stub that always returned false on Windows, so
Program.tick() never entered the resize branch — context.width/height
stayed frozen at startup and no window_size message was ever dispatched.

Detect resize by polling GetConsoleScreenBufferInfo and comparing the
srWindow dimensions against the last observed size. WINDOW_BUFFER_SIZE_EVENT
is not used because those records are only queued when ENABLE_WINDOW_INPUT
is set, which enableRawMode deliberately avoids. A first-read guard
establishes the baseline without reporting a spurious startup resize.

checkResize now takes the same stdout handle getSize uses
(state.stdout_handle) so detection and measurement agree when a custom
Config.output handle is set.
@meszmate meszmate merged commit 0b3ab67 into main Jun 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue: checkResize() always returns false on Windows — terminal resize never detected

1 participant