summaryrefslogtreecommitdiff
path: root/src/dump.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/dump.zig')
-rw-r--r--src/dump.zig25
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)));