repos / zmx

session persistence for terminal processes
git clone https://github.com/neurosnap/zmx.git

commit
4a6604b
parent
76cec40
author
Ian Tay
date
2026-03-08 12:57:02 -0400 EDT
fix(attach): serialize terminal state before resize, as the comment says

The existing comment correctly explains why serialize must happen before
resize (reflow moves the cursor), but the code did the opposite. Reattaching
with a different terminal size could leave the cursor misplaced.
1 files changed,  +9, -9
M src/main.zig
+9, -9
 1@@ -488,15 +488,6 @@ const Daemon = struct {
 2 
 3         const resize = std.mem.bytesToValue(ipc.Resize, payload);
 4 
 5-        var ws: cross.c.struct_winsize = .{
 6-            .ws_row = resize.rows,
 7-            .ws_col = resize.cols,
 8-            .ws_xpixel = 0,
 9-            .ws_ypixel = 0,
10-        };
11-        _ = cross.c.ioctl(pty_fd, cross.c.TIOCSWINSZ, &ws);
12-        try term.resize(self.alloc, resize.cols, resize.rows);
13-
14         // Serialize terminal state BEFORE resize to capture correct cursor position.
15         // Resizing triggers reflow which can move the cursor, and the shell's
16         // SIGWINCH-triggered redraw will run after our snapshot is sent.
17@@ -515,6 +506,15 @@ const Daemon = struct {
18             }
19         }
20 
21+        var ws: cross.c.struct_winsize = .{
22+            .ws_row = resize.rows,
23+            .ws_col = resize.cols,
24+            .ws_xpixel = 0,
25+            .ws_ypixel = 0,
26+        };
27+        _ = cross.c.ioctl(pty_fd, cross.c.TIOCSWINSZ, &ws);
28+        try term.resize(self.alloc, resize.cols, resize.rows);
29+
30         // Mark that we've had a client init, so subsequent clients get terminal state
31         self.has_had_client = true;
32