diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-28 22:20:49 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:15 -0300 |
| commit | 33f62509fc515c767cbef8d329d7666697e54ae7 (patch) | |
| tree | f6ea7fa830b468a0409396acfb5bb6cd346a80c7 /src | |
| parent | fe9786bf845f844315221e08eba793ac1d27ae9d (diff) | |
| download | pardes-33f62509fc515c767cbef8d329d7666697e54ae7.tar.gz pardes-33f62509fc515c767cbef8d329d7666697e54ae7.zip | |
A Restore logs restored <old> <new> for each pane
A script holding serials from before a Restore could not find its panes: the
replacement numbers them afresh. The dump now keeps each pane's serial (0 in
older dumps), and the replacement's log says `restored <old> <new>` for each
after its `restore <path>`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/dump.zig | 17 | ||||
| -rw-r--r-- | src/ninep/events.zig | 7 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/dump.zig b/src/dump.zig index 54fd1da1..0aaea39d 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -168,6 +168,9 @@ pub const Pane = struct { rows: u16 = 0, vweight: f32 = 1, collapsed: bool = false, + /// Its serial when dumped (0 in older dumps): a Restore logs + /// `restored <old> <new>` for it. + serial: u32 = 0, /// Exact editable tail when the user touched it. Null retains the live /// default; a present empty slice deliberately restores an empty tail. tag_tail: ?[]const u8 = null, @@ -632,6 +635,7 @@ pub fn dumpState(p: *Pardes) !void { else try pardes.panes.Terminal.dumpPane(pane, arena, tag, body, scroll); dp.tag_tail = pane.tag.own; + dp.serial = pane.serial; dump_panes[panes_len] = dp; panes_len += 1; } @@ -684,16 +688,22 @@ pub fn restore(p: *Pardes, zon_bytes: []const u8, from: []const u8) !*Pardes { var opts = p.opts; opts.cols = p.screen_w; opts.rows = p.screen_h; - const replacement = try initDump(p.gpa, opts, zon_bytes, p); + var old: [MAX_PANES]u32 = @splat(0); + const replacement = try initDump(p.gpa, opts, zon_bytes, p, &old); pardes.ctlfs.events.notePath(replacement, "restore", from); + // Which serial each pane had, for a script that held the old ones. + for (replacement.panes, old) |slot, was| if (slot) |pane| if (was != 0) { + var rec: [32]u8 = undefined; + pardes.ctlfs.events.notePath(replacement, "restored", std.fmt.bufPrint(&rec, "{d} {d}", .{ was, pane.serial }) catch continue); + }; return replacement; } pub fn initFromDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8) !*Pardes { - return initDump(gpa, opts, zon_bytes, null); + return initDump(gpa, opts, zon_bytes, null, null); } -fn initDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8, previous: ?*const Pardes) !*Pardes { +fn initDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8, previous: ?*const Pardes, old_serials: ?*[MAX_PANES]u32) !*Pardes { const image_gpa = opts.image_allocator orelse gpa; const pdf_gpa = opts.pdf_allocator orelse gpa; const tree_sitter_gpa = opts.tree_sitter_allocator orelse gpa; @@ -743,6 +753,7 @@ fn initDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8, previo } for (st.panes, 0..) |src, i| { if (i >= MAX_PANES) break; + if (old_serials) |o| o[i] = src.serial; const pane: *pardes.panes.Pane = switch (src.kind) { .terminal => terminal: { const t = src.terminal.?; diff --git a/src/ninep/events.zig b/src/ninep/events.zig index 1c66c18f..0e489be7 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -934,8 +934,13 @@ test "a Dump written and a Restore made are in the log, with their files" { const log = try freezeLog(core); defer core.gpa.free(log.bytes); var want: [64]u8 = undefined; - try testing.expect(std.mem.endsWith(u8, log.bytes, try std.fmt.bufPrint(&want, "{s} /tmp/pardes.dump.zon\n", .{what}))); + try testing.expect(std.mem.indexOf(u8, log.bytes, try std.fmt.bufPrint(&want, "{s} /tmp/pardes.dump.zon\n", .{what})) != null); } + // The replacement's last says which serial each pane had. + const log = try freezeLog(restored); + defer restored.gpa.free(log.bytes); + var want: [64]u8 = undefined; + try testing.expect(std.mem.endsWith(u8, log.bytes, try std.fmt.bufPrint(&want, "restore /tmp/pardes.dump.zon\nrestored {d} {d}\n", .{ p.panes[0].?.serial, restored.panes[0].?.serial }))); } test "opens of the log share the open records, and a closed one frees its record" { |
