renderer: reflow preview re-wraps off the terminal lock (port of #83 to main)

Merged
LA
1d ago
+562-32

Summary

Port of manaflow-ai/ghostty-next#83 to main. cmux moved its pin to main at 383b27d73 (cmux #35478, the upstream sync) while #83 merged into release/cmux-9ce9b7d0-e2 (510ca45ff). main does not contain 510ca45ff, so cmux cannot pin it; this PR puts the same change on main.

The same commits, cherry-picked onto 383b27d73. src/renderer/ReflowPreview.zig, src/renderer.zig and src/benchmark/ReflowPreview.zig are byte-identical to the reviewed head 79d62f7c5 (git diff 79d62f7c5 HEAD on them is empty). The only conflicts were the bench registries (src/benchmark/cli.zig, main.zig): main added shaper-rows; both entries are kept. The RenderState fields the fix reads (dirty, cursor.{active, visual_style, password_input, visible, blinking}, colors.{background, foreground, cursor}) exist unchanged on main.

What the change does (see #83): a reflow preview frame whose only change is the grid (each frame of a key resize or a divider drag) re-wraps a kept copy of the terminal with no terminal lock held; the live terminal is copied under the lock only when it changed. Also fixes the watch's dirty state never being reset (every preview frame copied under the lock). No C API change.

Testing

  • #83's evidence (release line): reds 42018811302 and 42024684069, green 42025379357 (84/84), PR build 42025383877 (220/220, lib-vt 475/475). Independent review SHIP at 79d62f7c5 (#83 comment 6657739529).
  • On main (Zig 0.17): this PR's build, and a scratch run of the reflow preview: tests plus ghostty-bench +reflow-preview (ReleaseFast). Results replace this line.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Ports #83 to main: a reflow preview frame whose only change is the grid now re-wraps a kept copy of the terminal outside the terminal lock, instead of copying the live terminal under the lock on every frame of a resize gesture. Also fixes the preview's watch dirty state never being reset, which forced a copy every frame even when only the grid changed. No C API change.

Testing

  • Adds ghostty-bench +reflow-preview and unit tests covering grid-only frames, live changes (output, cursor, colors, resize), and the committed grid.
  • New tests run in the next-xcframework CI workflow.

Summary by CodeRabbit

  • Bug Fixes
    • Improved terminal reflow previews during resizing. Previews now better reflect current terminal output, cursor position, and colors, and return to the live view when resizing is complete.