diff options
| -rw-r--r-- | src/dump.zig | 50 | ||||
| -rw-r--r-- | src/macos.zig | 2 | ||||
| -rw-r--r-- | src/main.zig | 2 | ||||
| -rw-r--r-- | src/walk.zig | 13 |
4 files changed, 47 insertions, 20 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)); +} diff --git a/src/macos.zig b/src/macos.zig index e07955a1..bc906dea 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -56,7 +56,7 @@ fn logFn( comptime format: []const u8, args: anytype, ) void { - if (scope != .macos and scope != .dump and std.c.getenv("PARDES_LOG") == null) return; + if (scope != .macos and std.c.getenv("PARDES_LOG") == null) return; std.log.defaultLog(level, scope, format, args); } diff --git a/src/main.zig b/src/main.zig index f310bf3c..0708e9d7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -37,7 +37,7 @@ fn logFn( comptime format: []const u8, args: anytype, ) void { - if (scope != .gui and scope != .dump and std.c.getenv("PARDES_LOG") == null) return; + if (scope != .gui and std.c.getenv("PARDES_LOG") == null) return; std.log.defaultLog(level, scope, format, args); } diff --git a/src/walk.zig b/src/walk.zig index ce097c0e..304fc5aa 100644 --- a/src/walk.zig +++ b/src/walk.zig @@ -1,7 +1,9 @@ //! The reflective walk over the core's state: one comptime `@typeInfo` walk //! that hashes a session into a digest (the replay harness compares two), -//! and that the complete dump and the rollback copy are to walk the same -//! way (docs/next-daemon.md). +//! encodes values for the tape, and dumps a session for another build to +//! load by name (`Dump`, `Load`: Restore, -l, the store, a handover, and +//! the join of phase 5). The rollback copy is to walk the same way +//! (docs/next-daemon.md). //! //! Values, never addresses: a pointer is followed to what it points at, a //! slice is its elements, an ArrayList its items, a hash map its entries in @@ -19,10 +21,13 @@ //! .authority = .{ "host" }, //! // A field written only as far as another says: hashed that far. //! .len = .{ .{ "jumps", "njumps" } }, +//! // What a field holds is made with another allocator on a load. +//! .alloc = .{ .{ "image", "image" } }, //! }; //! -//! None of the three kinds is in a digest. A type with a `pub fn -//! digest(*const T, *Hasher) void` of its own hashes itself. +//! None of the three kinds is in a digest or a dump. A type with a `pub fn +//! digest(*const T, *Hasher) void` of its own hashes itself; one with +//! `dumpWrite`, `dumpRead` (and `dumpFree`) dumps itself as bytes. const std = @import("std"); pub const Hasher = std.hash.Wyhash; |
