Skip to content

Redraw cleanly when the terminal is resized - #4

Merged
lperrin merged 1 commit into
mainfrom
redraw-on-resize
Nov 9, 2026
Merged

lperrin merged 1 commit into
mainfrom
redraw-on-resize

Conversation

@lperrin

@lperrin lperrin commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Resizing the terminal while wt was open left the display mangled: each resize stacked another copy of the header above the picker.

Why

The picker already redrew on SIGWINCH. Before redrawing, it moved up one row per line drawn above the prompt, which is one row for the header. Terminals rewrap their lines when the window gets narrower, so the full-width header now took two or more rows. The redraw started partway through it, and the old header stayed on screen above.

What changed

  • The picker records the width of each line it draws. On a resize, resize() works out how many rows the header and the start of the prompt line take at the new width (rowsAbove), then redraws from the real top of the picker. A wider window changes nothing.
  • The list height is recalculated on every resize, so the picker fits a shorter window and fills a taller one. Before, it was measured once at startup.
  • Version 0.2.2.

Limits

  • The fix assumes the terminal rewraps lines when the window gets narrower. iTerm2, Terminal.app, Ghostty, kitty, WezTerm, Alacritty, tmux and the VS Code terminal all do. A terminal that cuts lines off instead would lose a line or two of shell output above the picker.
  • If the window gets so short that the picker's top line scrolls off the screen, one stale line can stay up there.

Testing

  • New unit tests for visibleLen and rowsAbove. Lint, the tests and the smoke test pass.
  • Not yet checked by resizing a real terminal: open wt, drag the window narrower and wider, shorter and taller.

🤖 Generated with Claude Code

The picker redrew on SIGWINCH, but it moved back up as many rows as it had
drawn lines above the prompt: one. Terminals rewrap their lines when
narrowed, so the full-width header now took two rows or more, the redraw
started in the middle of it, and every resize left a stale header above
the picker.

The picker now keeps the widths of the lines it drew, and on a resize finds
its top again from how they rewrap at the new width. The list's height is
also recomputed, so it fits a terminal made shorter and uses one made
taller. Version 0.2.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lperrin
lperrin merged commit d0b9b7d into main Nov 9, 2026
7 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.

1 participant