diff options
Diffstat (limited to 'src/dump.zig')
| -rw-r--r-- | src/dump.zig | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/src/dump.zig b/src/dump.zig index 38fdbb7d..1d4ee2c2 100644 --- a/src/dump.zig +++ b/src/dump.zig @@ -10,7 +10,6 @@ const ctlfs = @import("ninep/tree.zig"); const exec = @import("exec.zig"); const colors = @import("colors.zig"); const config = @import("config.zig"); -const pdf_enabled = pardes.pdf_enabled; const platform = pardes.platform; const isolated = pardes.isolated; const MAX_PANES = pardes.MAX_PANES; @@ -93,7 +92,7 @@ pub var terminal_gpa: ?std.mem.Allocator = null; // // Loading is two halves. `load` makes the core the dump was and nothing // else (a replica joining a session takes that, phase 5); `revivePane` and -// `reviveSession` give it to this host: new shells, watches, PDFs opened. +// `reviveSession` give it to this host: new shells, watches, kinds' panes opened. /// A session's dump: its core, everything it is but what is the host's, /// the frame's or worked out again (`replica` in each type, src/walk.zig), @@ -298,7 +297,7 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: p.fs.deinit(gpa); gpa.destroy(p); } - l.allocs = .{ .image = p.image_gpa, .pdf = p.pdf_gpa, .terminal = terminal_gpa }; + l.allocs = .{ .image = p.image_gpa, .terminal = terminal_gpa }; try l.into(Pardes, p); const read = l.shared.items.len; const mounts = try l.get([]const filesystem.Mount); @@ -372,7 +371,7 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?* p.fs.deinit(gpa); gpa.destroy(p); } - l.allocs = .{ .image = p.image_gpa, .pdf = p.pdf_gpa, .terminal = terminal_gpa }; + l.allocs = .{ .image = p.image_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 @@ -441,7 +440,7 @@ fn loadImage(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: ?* /// 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.addon != null or pane.hasPdf()) return; + if (pane.terminal != null or pane.file != null or pane.addon != null or pane.pdf != null) 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; @@ -588,7 +587,8 @@ fn reviveSession(p: *Pardes, previous: ?*Pardes, resumed: bool) !void { /// A loaded pane given to this host: a terminal a new shell in its old /// one's directory under its history, a file watched again (one changed on /// disk since comes back as it is now, one unsaved is marked changed), a -/// PDF opened again. +/// kind's pane opened again (a PDF a build before the pdf addon dumped, as +/// the addon's). fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool) void { if (pane.addon) |slot| return reviveSlot(p, id, slot); if (pane.terminal != null) { @@ -606,13 +606,7 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool p.emitSpawn(id, pane.serial, pane.cwdSlice()); return; } - if (comptime pdf_enabled) if (pane.pdf != null) { - pardes.panes.Pdf.reopen(p, pane) catch |err| { - p.reportError(id, "Restore", err); - p.removePane(id, null) catch {}; - }; - return; - }; + if (pane.pdf) |old| return revivePdf(p, id, pane, old); const f = if (pane.file) |*file| file else return; if (f.output != null or filesystem.localPath(f.path) == null) return; p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); @@ -667,7 +661,7 @@ pub fn savePane(gpa: std.mem.Allocator, pane: *pardes.panes.Pane, slim: bool) ![ pub fn loadPane(p: *Pardes, id: usize, bytes: []const u8) !*pardes.panes.Pane { var l = try walk.Load(&.{pardes.panes.Pane}).init(p.gpa, bytes); defer l.deinit(); - l.allocs = .{ .image = p.image_gpa, .pdf = p.pdf_gpa, .terminal = pardes.panes.terminal.emulatorGpa(p.gpa) }; + l.allocs = .{ .image = p.image_gpa, .terminal = pardes.panes.terminal.emulatorGpa(p.gpa) }; const pane = try p.gpa.create(pardes.panes.Pane); errdefer { l.rollback(); @@ -925,11 +919,17 @@ const SlotRecord = struct { record: ?[]const u8 = null, values: []const u8 = "", live: bool = false, + /// What decides its next calls (Kind.step): a replica joining keeps + /// them, its Shadow calling where the authority's kind does. + next_tick: u64 = 0, + view: u64 = 0, + focused: bool = false, + told: []const u8 = "", }; pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer) !void { var place: [32]u8 = undefined; - var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live }; + var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live, .next_tick = s.next_tick, .view = s.view, .focused = s.focused, .told = s.told.slice() }; var owned: ?[]u8 = null; defer if (owned) |o| s.gpa.free(o); if (s.ops != null) { @@ -966,11 +966,12 @@ pub fn slotRead(out: *Kind.Slot, gpa: std.mem.Allocator, bytes: []const u8) !voi var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); const r = try walk.load(SlotRecord, arena.allocator(), bytes, null); - out.* = .{ .gpa = gpa, .arena = .init(gpa), .version = r.version, .art = r.art, .live = r.live }; + out.* = .{ .gpa = gpa, .arena = .init(gpa), .version = r.version, .art = r.art, .live = r.live, .next_tick = r.next_tick, .view = r.view, .focused = r.focused }; errdefer out.free(); @memcpy(out.name[0..@min(15, r.name.len)], r.name[0..@min(15, r.name.len)]); out.path = try gpa.dupe(u8, r.path); out.where_text.set(r.where); + out.told.set(r.told); out.values.set(r.values); if (r.record) |rec| out.record = try gpa.dupe(u8, rec); } @@ -981,7 +982,8 @@ pub fn slotFree(s: *Kind.Slot, gpa: std.mem.Allocator) void { } /// A loaded pane of a kind opened by its kind, if this core has it, else -/// a placeholder saying what it waits for. +/// a placeholder saying what it waits for. One with no record reopens from +/// its file, its place and its words. pub fn reviveSlot(p: *Pardes, id: usize, s: *Kind.Slot) void { const k = p.kinds.byName(s.nameOf()) orelse { s.live = false; @@ -989,5 +991,34 @@ pub fn reviveSlot(p: *Pardes, id: usize, s: *Kind.Slot) void { }; s.ops = p.kinds.ops[k]; s.gen = p.kinds.kinds[k].gen; - _ = Kind.reopen(p, id, s, null); + const bytes: ?[]u8 = if (s.record == null and s.path.len > 0) filesystem.read(p, s.path) catch null else null; + defer if (bytes) |b| p.gpa.free(b); + const kept = .{ s.next_tick, s.view, s.focused }; + _ = Kind.reopen(p, id, s, bytes); + // A replica's Shadow is the authority's pane as it is: it ticks when + // that one does, not because it was loaded (a kind opened here ticks + // to lay itself out). + if (s.ops == null) s.next_tick, s.view, s.focused = kept; +} + +/// A PDF pane of a dump from before the pdf addon: a pane of the addon's +/// kind `pdf` on its file, at its page, its fit and tint given again as +/// its words; a placeholder until the addon is loaded. +fn revivePdf(p: *Pardes, id: usize, pane: *pardes.panes.Pane, old: *pardes.panes.Pane.LegacyPdf) void { + defer { + p.image_gpa.free(old.path); + p.image_gpa.destroy(old); + pane.pdf = null; + } + const s = p.image_gpa.create(Kind.Slot) catch return; + s.* = .{ .gpa = p.image_gpa, .arena = .init(p.image_gpa), .version = 1, .live = true }; + @memcpy(s.name[0..3], "pdf"); + s.path = p.image_gpa.dupe(u8, old.path) catch { + s.free(); + return p.image_gpa.destroy(s); + }; + _ = s.where_text.print("{d}", .{old.page + 1}); + _ = s.values.print("PdfFit {t}\nPdfTint {t}\n", .{ old.fit, old.tint }); + pane.addon = s; + reviveSlot(p, id, s); } |
