From 7ba57610929544bf3d1b3d0bf65dbb039d97942b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 29 Oct 2026 18:04:38 -0300 Subject: snapshots: dump, load, restore, tagnav and headersweep-restored show the session as it was dumped: a terminal's view, its prompts hidden in text mode, a pane's message, typed text over its history Co-Authored-By: Claude Opus 5.5 --- src/dump.zig | 28 ++++++++++++++++++++++++---- src/tape.zig | 2 ++ src/terminal.zig | 7 +++++-- 3 files changed, 31 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/dump.zig b/src/dump.zig index ccbcd158..20299b79 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -331,7 +331,7 @@ fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previ /// A loaded core given to this host (with `revivePane` for each of its /// panes): the store and Recent read (a Restore's carried from the session -/// it replaces), its ThemeFile asked for again, and the screen this host's. +/// it replaces) and its ThemeFile asked for again. fn reviveSession(p: *Pardes, previous: ?*const Pardes) !void { if (previous) |old| { // Never a serial or a request number the old session gave out. @@ -358,9 +358,8 @@ fn reviveSession(p: *Pardes, previous: ?*const Pardes) !void { for (p.panes) |slot| if (slot) |pane| { pane.fs.unannounced = true; }; - // This host's screen; the next sync lays the panes out on it. - p.screen_w = p.opts.cols; - p.screen_h = p.opts.rows; + // The dump's screen until this host says its own (a resize): two + // reflows would lose where a terminal's view was. p.sync(); exec.applyStartupConfig(p); colors.finishThemeInitialization(p); @@ -569,3 +568,24 @@ test "a pane restored with unsaved text is asked about by Exit, Restore, Del and try std.testing.expect(!restored.quit and restored.panes[id] != null); } } + +test "a loaded terminal's history stays above its banner, the cursor where it was" { + if (comptime !pardes.panes.terminal.enabled or isolated) return error.SkipZigTest; + const gpa = std.testing.allocator; + const term = pardes.panes.terminal; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }); + defer p.deinit(); + while (p.nextEffect()) |_| {} + term.feedOutput(p, p.panes[0].?, "one\r\ntwo\r\n$ "); + const before = term.gridCursor(p.panes[0].?); + try dumpState(p); + const loaded = try load(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }, p.dump_out.?, null); + defer loaded.deinit(); + try std.testing.expectEqual(before, term.gridCursor(loaded.panes[0].?)); + const q = try initFromDump(gpa, .{ .tty_only = true, .cols = 40, .rows = 12 }, p.dump_out.?); + defer q.deinit(); + const text = try term.screenTextAlloc(q.panes[0].?, gpa); + defer gpa.free(text); + try std.testing.expect(std.mem.indexOf(u8, text, "one\ntwo\n") != null); + try std.testing.expect(std.mem.indexOf(u8, text, "two") .? < std.mem.indexOf(u8, text, "restored history").?); +} diff --git a/src/tape.zig b/src/tape.zig index 3573d887..d4fb7756 100644 --- a/src/tape.zig +++ b/src/tape.zig @@ -983,6 +983,8 @@ pub fn replayMain(io: std.Io, path: []const u8) u8 { if (t.diverged) |why| if (std.mem.startsWith(u8, why, "the tape ends")) { t.diverged = null; }; + // One killed (as the harnesses end theirs) has its end state here. + if (t.dump_check and t.diverged == null) if (t.core) |core| t.dumpRoundTrip(core); if (t.diverged) |why| { failed = true; std.debug.print("replay {s}: {s} replica diverged after {d} digests: {s}\n", .{ path, run.name, t.digests, why }); diff --git a/src/terminal.zig b/src/terminal.zig index 6fdd46f0..ad35784f 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -835,8 +835,11 @@ pub const restored_banner = "\x1b[0m\r\n\x1b[2m\u{2500}\u{2500} restored history pub fn reviveShell(pane: *Pane) void { if (comptime !enabled) return; if (pane.terminal == null) return; - // The primary screen, modes and mouse as a shell starts with them. - ingest(pane, "\x1b[?1049l\x1b[!p\x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1006l\x1b[?2004l\x1b[\x1b[?25h\x1b[?7h\x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1006l\x1b[?2004l\x1b[