diff options
Diffstat (limited to 'src/dump.zig')
| -rw-r--r-- | src/dump.zig | 93 |
1 files changed, 57 insertions, 36 deletions
diff --git a/src/dump.zig b/src/dump.zig index 3c31c805..38fdbb7d 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -101,10 +101,10 @@ pub var terminal_gpa: ?std.mem.Allocator = null; /// its panes' files were on disk when it was made (one gone by its load is /// said deleted: its text is nowhere else now), its theme's name (the /// setting is a place in this build's ring of themes, another build's -/// ring is another), and the views not live (views.zig: the core holds -/// the live one's). -const Session = walk.Dump(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8, []const views.Dumped }); -const SessionLoad = walk.Load(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8, []const views.Dumped }); +/// ring is another), and the panes' shares of the views not live +/// (views.zig: the panes hold the live one's). +const Session = walk.Dump(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8, []const views.Shares }); +const SessionLoad = walk.Load(&.{ Pardes, []const filesystem.Mount, OnDisk, []const u8, []const views.Shares }); const OnDisk = [MAX_PANES]bool; fn onDisk(pane: *const pardes.panes.Pane) bool { @@ -187,21 +187,21 @@ pub fn image(p: *Pardes, name: []const u8) ![]u8 { for (others) |o| gpa.free(o.panes); gpa.free(others); } - const kept: []const views.Dumped = others; + const kept: []const views.Shares = others; try db.runContext(struct { w: *walk.Put, p: *Pardes, mounts: *const []const filesystem.Mount, on_disk: *const OnDisk, theme: *const []const u8, - others: *const []const views.Dumped, + others: *const []const views.Shares, pub fn run(ctx: @This(), cursor: *walk.Mem.Cursor(.read_write)) !void { const root = try walk.Mem.HashMap(.read_write).init(cursor.*); try ctx.w.member(root, "core", Pardes, ctx.p); try ctx.w.member(root, "mounts", []const filesystem.Mount, ctx.mounts); try ctx.w.member(root, "on_disk", OnDisk, ctx.on_disk); try ctx.w.member(root, "theme", []const u8, ctx.theme); - try ctx.w.member(root, "views", []const views.Dumped, ctx.others); + try ctx.w.member(root, "shares", []const views.Shares, ctx.others); } }{ .w = &w, .p = p, .mounts = &mounts, .on_disk = &on_disk, .theme = &theme, .others = &kept }); return pardes.Db.image(gpa, name, buf.written(), w.blobs.items, panes); @@ -240,8 +240,8 @@ fn dumpWith(p: *Pardes, deferred: ?*std.ArrayListUnmanaged(walk.Deferred)) ![]u8 for (others) |o| p.gpa.free(o.panes); p.gpa.free(others); } - const kept: []const views.Dumped = others; - try d.put([]const views.Dumped, &kept); + const kept: []const views.Shares = others; + try d.put([]const views.Shares, &kept); return d.finish(); } @@ -342,12 +342,12 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: // The views not live, last: what it moves into the core is never // rolled back from under it, nothing after it failing. const at = l.shared.items.len; - const others = l.get([]const views.Dumped) catch |err| switch (err) { + const others = l.get([]const views.Shares) catch |err| switch (err) { // A dump made before views were in it. error.EndOfDump => &.{}, else => return err, }; - try views.undumped(p, others); + views.undumped(p, others); for (others) |o| gpa.free(o.panes); gpa.free(others); l.shared.shrinkRetainingCapacity(at); @@ -374,6 +374,15 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?* } l.allocs = .{ .image = p.image_gpa, .pdf = p.pdf_gpa, .terminal = terminal_gpa }; try l.into(Pardes, core_at, p); + if (try walk.Get.member(core_at, "views") == null) { + // From before `Pardes.views`: the live view's share is the core's + // own fields, by the same names, and its index `view`. + var old: struct { view: u8 = 0 } = .{}; + try l.into(@TypeOf(old), core_at, &old); + p.live = if (old.view < views.max) old.view else 0; + if (p.live != 0) std.mem.swap(?Pardes.View, &p.views[0], &p.views[p.live]); + try l.into(Pardes.View, core_at, p.view()); + } const read = l.made.items.len; const mounts: []const filesystem.Mount = if (try walk.Get.member(root, "mounts")) |c| try l.get([]const filesystem.Mount, c) else &.{}; defer { @@ -410,10 +419,21 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?* // The views not live, last: what it moves into the core is never // rolled back from under it, nothing after it failing. const at = l.made.items.len; - const others: []const views.Dumped = if (try walk.Get.member(root, "views")) |c| try l.get([]const views.Dumped, c) else &.{}; - try views.undumped(p, others); - for (others) |o| gpa.free(o.panes); - gpa.free(others); + if (try walk.Get.member(root, "shares")) |c| { + const others = try l.get([]const views.Shares, c); + views.undumped(p, others); + for (others) |o| gpa.free(o.panes); + gpa.free(others); + } else { + // A dump from before `Pardes.views`: the live view's share was + // the core's own fields, each other view's in `views`. + const others: []const views.OldDumped = if (try walk.Get.member(root, "views")) |c| try l.get([]const views.OldDumped, c) else &.{}; + defer { + for (others) |o| gpa.free(o.panes); + gpa.free(others); + } + try views.undumpedOld(p, others, gpa); + } l.made.shrinkRetainingCapacity(at); return p; } @@ -431,15 +451,16 @@ fn ensureKind(p: *Pardes, pane: *pardes.panes.Pane) !void { /// 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 { - for (0..p.ncol) |c| { + const v = p.view(); + for (0..p.view().ncol) |c| { var n: usize = 0; - for (p.cols[c].panes[0..p.cols[c].n]) |id| if (id < MAX_PANES and p.panes[id] != null) { - p.cols[c].panes[n] = id; + for (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (id < MAX_PANES and p.panes[id] != null) { + v.cols[c].panes[n] = id; n += 1; }; - p.cols[c].n = n; + v.cols[c].n = n; } - if (p.active >= MAX_PANES or p.panes[p.active] == null) p.active = for (p.panes, 0..) |slot, i| { + if (v.active >= MAX_PANES or p.panes[v.active] == null) v.active = for (p.panes, 0..) |slot, i| { if (slot != null) break i; } else 0; } @@ -450,8 +471,8 @@ pub fn restore(p: *Pardes, bytes: []const u8, from: []const u8) !*Pardes { const taped = pardes.tape.enter(p, .{ .restore = .{ .bytes = bytes, .from = from } }); defer pardes.tape.leave(p, taped); var opts = p.opts; - opts.cols = p.screen_w; - opts.rows = p.screen_h; + opts.cols = p.view().screen_w; + opts.rows = p.view().screen_h; const replacement = try loadAndRevive(p.gpa, opts, bytes, p, null); replacement.pointRestoreAt(from); // The tape follows the replacement from here (it is the session). @@ -508,7 +529,7 @@ fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previ if (notes.items.len > 0) { 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"); + p.setMessage(p.view().active, std.fmt.bufPrint(&buf, "a dump of another build: {s}", .{first}) catch "a dump of another build: not all of it was read"); } return p; } @@ -529,9 +550,9 @@ fn reviveSession(p: *Pardes, previous: ?*Pardes, resumed: bool) !void { p.lsp_ask.seq = @max(p.lsp_ask.seq, old.lsp_ask.seq); p.pipe.seq = @max(p.pipe.seq, old.pipe.seq); // The host's facts, as this host told them. - p.cell_pixels = old.cell_pixels; - p.row_metrics = old.row_metrics; - p.frontend.native_images = old.frontend.native_images; + p.view().cell_pixels = old.view().cell_pixels; + p.view().row_metrics = old.view().row_metrics; + p.view().frontend.native_images = old.view().frontend.native_images; // Its panes close here, each noted where it was, as at its end. for (old.panes) |slot| if (slot) |pane| old.noteClosed(pane); p.recent = old.recent.clone(p.recentGpa()); @@ -659,7 +680,7 @@ pub fn loadPane(p: *Pardes, id: usize, bytes: []const u8) !*pardes.panes.Pane { pane.command_from = 0; pane.places.from = 0; pane.collapsed = false; - pane.prompt_view = p.view; + pane.prompt_view = p.live; if (pane.file) |*f| if (f.content.len == 0 and (f.saved_len orelse 0) > 0) { // A clean file kept slim: its text is its file's. if (filesystem.read(p, f.path)) |text| { @@ -676,8 +697,8 @@ test "a dump keeps the session's settings, and a restore applies them" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true }); defer p.deinit(); - try std.testing.expect(p.executeBuiltinLine(p.active, "Verbose off")); - try std.testing.expect(p.executeBuiltinLine(p.active, "Wrap off")); + try std.testing.expect(p.executeBuiltinLine(p.view().active, "Verbose off")); + try std.testing.expect(p.executeBuiltinLine(p.view().active, "Wrap off")); try dumpState(p); const restored = try initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?); defer restored.deinit(); @@ -689,10 +710,10 @@ test "a session with every column it may hold dumps and restores them all" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 1200, .rows = 24 }); defer p.deinit(); - while (p.ncol < MAX_COLS) { + while (p.view().ncol < MAX_COLS) { layout.compute(p); var widest: usize = 0; - for (0..p.ncol) |c| if (p.col_w[c] > p.col_w[widest]) { + for (0..p.view().ncol) |c| if (p.view().col_w[c] > p.view().col_w[widest]) { widest = c; }; _ = layout.insertColumn(p, widest, false) orelse return error.NoColumn; @@ -700,7 +721,7 @@ test "a session with every column it may hold dumps and restores them all" { try dumpState(p); const restored = try initFromDump(gpa, .{ .tty_only = true, .cols = 1200, .rows = 24 }, p.dump_out.?); defer restored.deinit(); - try std.testing.expectEqual(@as(usize, MAX_COLS), restored.ncol); + try std.testing.expectEqual(@as(usize, MAX_COLS), restored.view().ncol); } test "a restored session's column and workspace tags take more than one selection, and its 9P files have a time" { @@ -711,7 +732,7 @@ test "a restored session's column and workspace tags take more than one selectio try dumpState(p); const restored = try initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?); defer restored.deinit(); - try std.testing.expect(restored.col_tags[0].reserveSels()); + try std.testing.expect(restored.view().col_tags[0].reserveSels()); try std.testing.expect(restored.global_tag.reserveSels()); try std.testing.expect(restored.fs.started != 0); const stat = th.call(restored, .{ .tag = 1, .op = .getattr, .node = @backingInt(pardes.ctlfs.TopFile.index) }); @@ -798,7 +819,7 @@ test "an upgraded session's dump keeps its views and its running terminal as the defer p.deinit(); while (p.nextEffect()) |_| {} term.feedOutput(p, p.panes[0].?, "one\r\n\x1b[?1049h$ vim"); - try std.testing.expect(p.executeBuiltinLine(p.active, "Verbose on")); + try std.testing.expect(p.executeBuiltinLine(p.view().active, "Verbose on")); _ = p.openView().?; const bytes = try dumpBytes(p); defer gpa.free(bytes); @@ -825,7 +846,7 @@ test "a session's image, read by name as every load reads it, is the same sessio 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")); + try std.testing.expect(p.executeBuiltinLine(p.view().active, "Zerox")); const bytes = try dumpBytes(p); defer gpa.free(bytes); var notes: std.ArrayList(u8) = .empty; @@ -845,7 +866,7 @@ test "a session's byte dump read by name, field by field as another build reads 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")); + try std.testing.expect(p.executeBuiltinLine(p.view().active, "Zerox")); const bytes = try byteDump(p); defer gpa.free(bytes); const q = try Pardes.create(gpa, p.opts); |
