summaryrefslogtreecommitdiff
path: root/src/dump.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/dump.zig')
-rw-r--r--src/dump.zig50
1 files changed, 36 insertions, 14 deletions
diff --git a/src/dump.zig b/src/dump.zig
index 20299b79..abc52f5a 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -1,11 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
const limits = @import("memory.zig").limits;
-
-// scoped, not bare std.log: main.zig's logFn drops the unscoped .default scope
-// wholesale (ghostty and uucode log there too), and a corrupt dump's parse
-// diagnostic is the only thing that says WHICH field went bad.
-const log = std.log.scoped(.dump);
const pardes = @import("pardes.zig");
const walk = @import("walk.zig");
const Handover = @import("Handover.zig");
@@ -252,13 +247,25 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes:
}
if (l.notes.items.len > 0) {
// A pane another build could not give is left out: so is its
- // place in the layout.
+ // place in the layout. One whose terminal it could not give is a
+ // terminal still.
dropMissing(p);
+ for (p.panes) |slot| if (slot) |pane| try ensureKind(p, pane);
if (notes) |n| try n.appendSlice(gpa, l.notes.items);
}
return p;
}
+/// A pane that is none of its kinds (a terminal kept slim, or one another
+/// build's dump could not give): a terminal, a new emulator for its shell.
+fn ensureKind(p: *Pardes, pane: *pardes.panes.Pane) !void {
+ if (pane.terminal != null or pane.file != null or pane.image != null or pane.hasPdf()) return;
+ const fresh = try pardes.panes.terminal.create(p.gpa, @max(1, pane.cols), @max(1, pane.rows));
+ pane.terminal = fresh.terminal;
+ fresh.terminal = null;
+ p.gpa.destroy(fresh);
+}
+
/// The panes a column lists that are not there (another build's dump left
/// them out) taken out of it, and the keyboard on one that is.
fn dropMissing(p: *Pardes) void {
@@ -320,8 +327,9 @@ fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previ
errdefer p.deinit();
for (p.panes, on_disk, 0..) |slot, was_on_disk, i| if (slot) |pane| revivePane(p, i, pane, was_on_disk);
try reviveSession(p, previous);
+ // What another build's dump could not give, said where the user looks
+ // (stderr is a tty session's screen).
if (notes.items.len > 0) {
- log.warn("{s}", .{notes.items});
const first = notes.items[0 .. std.mem.indexOfScalar(u8, notes.items, '\n') orelse notes.items.len];
var buf: [320]u8 = undefined;
p.setMessage(p.active, std.fmt.bufPrint(&buf, "a dump of another build: {s}", .{first}) catch "a dump of another build: not all of it was read");
@@ -458,13 +466,7 @@ pub fn loadPane(p: *Pardes, id: usize, bytes: []const u8) !*pardes.panes.Pane {
f.content = text;
} else |_| {}
};
- if (pane.terminal == null and pane.file == null and pane.image == null and !pane.hasPdf()) {
- // A terminal kept slim: a new emulator, a new shell.
- const fresh = try pardes.panes.terminal.create(p.gpa, @max(1, pane.cols), @max(1, pane.rows));
- pane.terminal = fresh.terminal;
- fresh.terminal = null;
- p.gpa.destroy(fresh);
- }
+ try ensureKind(p, pane);
p.installPane(id, pane);
revivePane(p, id, pane, false);
return pane;
@@ -589,3 +591,23 @@ test "a loaded terminal's history stays above its banner, the cursor where it wa
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").?);
}
+
+test "a session read by name, field by field as another build reads it, is the same session" {
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\ntwo\n");
+ _ = ctlfs.pane.spliceBody(p, pane, 0, 0, "unsaved ").?;
+ try std.testing.expect(p.executeBuiltinLine(p.active, "Zerox"));
+ const bytes = try dumpBytes(p);
+ defer gpa.free(bytes);
+ const q = try Pardes.create(gpa, p.opts);
+ defer q.deinit();
+ var l = try SessionLoad.init(gpa, bytes);
+ defer l.deinit();
+ try std.testing.expect(l.same);
+ l.same = false;
+ try l.into(Pardes, q);
+ try std.testing.expectEqualStrings("", l.notes.items);
+ try std.testing.expectEqual(walk.digest(Pardes, p), walk.digest(Pardes, q));
+}