repos / zmx

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

commit
c2e856c
parent
15dfe33
author
Eric Bower
date
2025-11-26 14:37:04 -0500 EST
feat: on re-attach send SIGWINCH and in-band resize event
1 files changed,  +11, -1
M src/main.zig
+11, -1
 1@@ -3,7 +3,6 @@ const posix = std.posix;
 2 const builtin = @import("builtin");
 3 const ipc = @import("ipc.zig");
 4 const log = @import("log.zig");
 5-const RingBuffer = @import("ring_buffer.zig").RingBuffer;
 6 
 7 var log_system = log.LogSystem{};
 8 
 9@@ -578,6 +577,17 @@ fn daemonLoop(daemon: *Daemon, server_sock_fd: i32, pty_fd: i32) !void {
10             };
11             client.write_buf = try std.ArrayList(u8).initCapacity(client.alloc, 4096);
12             try daemon.clients.append(daemon.alloc, client);
13+
14+            // TODO: Replace this SIGWINCH hack with proper terminal state restoration
15+            // using ghostty-vt to maintain a virtual terminal buffer and replay it
16+            // to new clients on re-attach.
17+            // For now, trigger a SIGWINCH and in-band resize to force applications to redraw.
18+            var ws: c.struct_winsize = undefined;
19+            if (c.ioctl(pty_fd, c.TIOCGWINSZ, &ws) == 0) {
20+                _ = c.ioctl(pty_fd, c.TIOCSWINSZ, &ws);
21+            }
22+            // Send in-band resize notification
23+            _ = posix.write(pty_fd, "\x1b[?2048h") catch {};
24         }
25 
26         if (poll_fds.items[1].revents & (posix.POLL.IN | posix.POLL.HUP | posix.POLL.ERR | posix.POLL.NVAL) != 0) {