repos / zmx

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

commit
c539ebc
parent
0639e71
author
Eric Bower
date
2025-10-10 21:26:21 -0400 EDT
fix: initial attach clear terminal
1 files changed,  +21, -0
M src/daemon.zig
+21, -0
 1@@ -518,6 +518,27 @@ fn handleAttachSession(ctx: *ServerContext, client: *Client, session_name: []con
 2     // Start reading from PTY if not already started (first client)
 3     if (session.attached_clients.count() == 1) {
 4         try readFromPty(ctx, client, session);
 5+
 6+        // For first attach to new session, clear the client's terminal
 7+        if (!is_reattach) {
 8+            var out: std.io.Writer.Allocating = .init(ctx.allocator);
 9+            defer out.deinit();
10+            var json_writer: std.json.Stringify = .{ .writer = &out.writer };
11+
12+            try json_writer.beginObject();
13+            try json_writer.objectField("type");
14+            try json_writer.write("pty_out");
15+            try json_writer.objectField("payload");
16+            try json_writer.beginObject();
17+            try json_writer.objectField("text");
18+            try json_writer.write("\x1b[2J\x1b[H"); // Clear screen and move cursor to home
19+            try json_writer.endObject();
20+            try json_writer.endObject();
21+
22+            const response = try std.fmt.allocPrint(ctx.allocator, "{s}\n", .{out.written()});
23+            defer ctx.allocator.free(response);
24+            _ = try posix.write(client.fd, response);
25+        }
26     } else {
27         // Send attach success response for additional clients
28         const response = try std.fmt.allocPrint(