repos / zmx

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

commit
55084ff
parent
7fde464
author
Eric Bower
date
2025-10-13 14:03:56 -0400 EDT
fix: replace to device attribute queries within daemon
1 files changed,  +25, -1
M src/daemon.zig
+25, -1
 1@@ -30,10 +30,31 @@ const c = switch (builtin.os.tag) {
 2 // Handler for processing VT sequences
 3 const VTHandler = struct {
 4     terminal: *ghostty.Terminal,
 5+    pty_master_fd: std.posix.fd_t,
 6 
 7     pub fn print(self: *VTHandler, cp: u21) !void {
 8         try self.terminal.print(cp);
 9     }
10+
11+    pub fn deviceAttributes(
12+        self: *VTHandler,
13+        req: ghostty.DeviceAttributeReq,
14+        da_params: []const u16,
15+    ) !void {
16+        _ = da_params;
17+
18+        const response = switch (req) {
19+            .primary => "\x1b[?1;2c", // VT100 with AVO (matches screen/tmux)
20+            .secondary => "\x1b[>0;0;0c", // Conservative secondary DA
21+            .tertiary => return, // Ignore tertiary DA
22+        };
23+
24+        _ = posix.write(self.pty_master_fd, response) catch |err| {
25+            std.debug.print("Error writing DA response to PTY: {s}\n", .{@errorName(err)});
26+        };
27+
28+        std.debug.print("Responded to DA query ({s}) with {s}\n", .{ @tagName(req), response });
29+    }
30 };
31 
32 // Context for PTY read callbacks
33@@ -1076,7 +1097,10 @@ fn createSession(allocator: std.mem.Allocator, session_name: []const u8) !*Sessi
34         .pty_read_buffer = undefined,
35         .created_at = std.time.timestamp(),
36         .vt = vt,
37-        .vt_handler = VTHandler{ .terminal = &session.vt },
38+        .vt_handler = VTHandler{
39+            .terminal = &session.vt,
40+            .pty_master_fd = @intCast(master_fd),
41+        },
42         .vt_stream = undefined,
43         .attached_clients = std.AutoHashMap(std.posix.fd_t, void).init(allocator),
44         .utf8_partial = undefined,