diff options
| author | Gabriel Schneider <[email protected]> | 2026-09-29 00:50:45 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 00:12:15 -0300 |
| commit | 7aa057e29b729ad6d9ac53e3a06f99858fc449e4 (patch) | |
| tree | a0010efb342018f32f98d9e805680306feb88836 /src/dump.zig | |
| parent | e563be42a5b3e9243e2c01d34cf8e94d2047b753 (diff) | |
| download | pardes-7aa057e29b729ad6d9ac53e3a06f99858fc449e4.tar.gz pardes-7aa057e29b729ad6d9ac53e3a06f99858fc449e4.zip | |
A column has a ctl, an exec and an rmdir over 9P, and Restore maps its serial
A script could read and write a column's tag but not act on the column.
col/<serial>/ctl takes Delcol, Joincol, New and Tty, each acting on that
column as from its tag; col/<serial>/exec runs a word as a middle click in
the tag; rmdir col/<serial> closes an empty column and refuses one with
panes (ENOTEMPTY, an err record saying why). The root ctl's refusal of
Delcol and Joincol points at col/<serial>/ctl. A dump keeps each column's
serial and Restore logs restoredcol <old> <new>; the dump golden gains
them. Documented: Joincol's survivor, the column on the right, keeps its
serial and tag.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/dump.zig')
| -rw-r--r-- | src/dump.zig | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/dump.zig b/src/dump.zig index 61aeabbf..5b0983ad 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -180,6 +180,9 @@ pub const Pane = struct { }; pub const Column = struct { + /// Its serial when dumped (0 in older dumps): a Restore logs + /// `restoredcol <old> <new>` for it. + serial: u32 = 0, tag: ?[]const u8 = null, weight: f32 = 1, panes: []const usize = &.{}, @@ -665,6 +668,7 @@ pub fn dumpState(p: *Pardes) !void { ids_len += 1; }; columns[columns_len] = .{ + .serial = layout.columnSerial(p, c), .tag = p.col_tags[c].own, .weight = @as(f32, @floatFromInt(p.col_weight[c])) / @as(f32, @floatFromInt(column_weight_unit)), .panes = column_ids[c][0..ids_len], @@ -733,14 +737,18 @@ 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; - var old: [MAX_PANES]u32 = @splat(0); + var old: OldSerials = .{}; 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) { + // Which serial each pane and column had, for a script that held them. + for (replacement.panes, old.panes) |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); }; + for (old.cols[0..replacement.ncol], 0..) |was, c| if (was != 0) { + var rec: [32]u8 = undefined; + pardes.ctlfs.events.notePath(replacement, "restoredcol", std.fmt.bufPrint(&rec, "{d} {d}", .{ was, layout.columnSerial(replacement, c) }) catch continue); + }; return replacement; } @@ -748,7 +756,13 @@ pub fn initFromDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8 return initDump(gpa, opts, zon_bytes, null, null); } -fn initDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8, previous: ?*const Pardes, old_serials: ?*[MAX_PANES]u32) !*Pardes { +/// The serials a dump's panes and columns had, read as it is restored. +const OldSerials = struct { + panes: [MAX_PANES]u32 = @splat(0), + cols: [MAX_COLS]u32 = @splat(0), +}; + +fn initDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8, previous: ?*const Pardes, old_serials: ?*OldSerials) !*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; @@ -799,7 +813,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; + if (old_serials) |o| o.panes[i] = src.serial; const pane: *pardes.panes.Pane = switch (src.kind) { .terminal => terminal: { const t = src.terminal.?; @@ -869,6 +883,7 @@ fn initDump(gpa: std.mem.Allocator, opts: Options, zon_bytes: []const u8, previo p.col_serial = @splat(0); if (st.topbar_custom) |bar| p.global_tag.own = try p.gpa.dupe(u8, bar); for (st.columns[0..p.ncol], 0..) |col, c| { + if (old_serials) |o| o.cols[c] = col.serial; if (col.tag) |bar| p.col_tags[c].own = try p.gpa.dupe(u8, bar); const scaled = @as(f64, @floatCast(col.weight)) * @as(f64, @floatFromInt(column_weight_unit)); const bounded = @min(scaled, @as(f64, @floatFromInt(max_column_weight))); |
