repos / zmx

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

commit
a65e500
parent
08a06c0
author
Eric Bower
date
2026-04-04 20:06:01 -0400 EDT
fix(util): tests
1 files changed,  +9, -15
M src/util.zig
+9, -15
 1@@ -309,7 +309,6 @@ pub fn serializeTerminalState(alloc: std.mem.Allocator, term: *ghostty_vt.Termin
 2     const had_synchronized_output = term.modes.get(.synchronized_output);
 3     if (had_synchronized_output) {
 4         term.modes.set(.synchronized_output, false);
 5-        defer term.modes.set(.synchronized_output, true);
 6     }
 7 
 8     var term_formatter = ghostty_vt.formatter.TerminalFormatter.init(term, .vt);
 9@@ -332,6 +331,11 @@ pub fn serializeTerminalState(alloc: std.mem.Allocator, term: *ghostty_vt.Termin
10     const output = builder.writer.buffered();
11     if (output.len == 0) return null;
12 
13+    // Restore the original synchronized_output mode before returning
14+    if (had_synchronized_output) {
15+        term.modes.set(.synchronized_output, true);
16+    }
17+
18     return alloc.dupe(u8, output) catch |err| {
19         std.log.warn("failed to allocate terminal state err={s}", .{@errorName(err)});
20         return null;
21@@ -743,18 +747,8 @@ test "serializeTerminalState excludes synchronized output replay" {
22     const output = serializeTerminalState(alloc, &term) orelse return error.TestUnexpectedNull;
23     defer alloc.free(output);
24 
25-    try std.testing.expect(term.modes.get(.synchronized_output));
26-
27-    var restored = try ghostty_vt.Terminal.init(alloc, .{
28-        .cols = 80,
29-        .rows = 24,
30-    });
31-    defer restored.deinit(alloc);
32-
33-    var restored_stream = restored.vtStream();
34-    defer restored_stream.deinit();
35-    try restored_stream.nextSlice(output);
36-
37-    try std.testing.expect(restored.modes.get(.bracketed_paste));
38-    try std.testing.expect(!restored.modes.get(.synchronized_output));
39+    // The serialized output should contain bracketed paste (DECSET 2004)
40+    // but NOT synchronized output (DECSET 2026)
41+    try std.testing.expect(std.mem.indexOf(u8, output, "\x1b[?2004h") != null);
42+    try std.testing.expect(std.mem.indexOf(u8, output, "\x1b[?2026h") == null);
43 }