diff options
| -rw-r--r-- | src/gui/gui.zig | 18 | ||||
| -rw-r--r-- | src/host_io.zig | 24 | ||||
| -rw-r--r-- | src/tui/tui.zig | 19 |
3 files changed, 28 insertions, 33 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 95df9fac..ecd9026f 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -2524,28 +2524,14 @@ fn localSession( daemon.watch(&shell, deliverNote); if (core.quit) break; // a session that ended does not restore into one if (core.takeRestore()) |rp| blk: { - // ponytail: a Restore replaces the core its clients replicate; - // they are let go, and attach again (as the tty's). - shell.peers.dropAll(core); - const bytes = filesystem.readRestore(gpa, rp, core.settings.dump_dir.get()) catch |err| { - core.reportError(core.active, "Restore", err); - break :blk; - }; - defer gpa.free(bytes); - const nc = dump.restore(core, bytes, rp) catch |err| { - core.reportError(core.active, "Restore", err); - break :blk; - }; + const nc = host_io.restoreCore(gpa, core, rp, &shell.peers, inotify_fd, &watches) orelse break :blk; pipe_tasks.cancelAll(io); queue.discardCompletions(); - // ponytail: a restored session is one view, the live window's: - // the others close. + // One view, the live window (host_io.restoreCore). shell.closeOtherWindows(); shell.gview = 0; shell.windowed = 1; shell.stopPtys(); - file_watch.unwatchAll(inotify_fd, &watches); - _ = file_watch.applyThemeEffect(core, gpa, inotify_fd, &watches, 0, false, false); clearNativeImages(g); g.presented_images.clearRetainingCapacity(); g.prepared_images.clearRetainingCapacity(); diff --git a/src/host_io.zig b/src/host_io.zig index d6b9b72e..3a9a73fd 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -7,6 +7,7 @@ const selection_pipe = @import("selection_pipe.zig"); const ninep_io = @import("9p_io.zig"); const filesystem = @import("fs.zig"); const file_watch = @import("file_watch.zig"); +const replica = @import("replica.zig"); pub const Host = struct { ctx: ?*anyopaque = null, @@ -96,6 +97,29 @@ pub fn stopWorkers() void { pardes.syntax.stop(); } +/// A Restore's new core, from the dump at `path` (core.takeRestore), or +/// null once why it is not is said. ponytail: a Restore replaces the core +/// its clients replicate; they are let go, and attach again. The old +/// core's panes and theme are no longer watched; the frontend lets go of +/// its ptys and pipes and swaps the new core in. ponytail: a restored +/// session is one view, the live one's (the tty's terminal, the window's +/// window): the others are let go, as a detach of each. +pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u8, peers: *replica.Peers, inotify_fd: c_int, watches: *file_watch.Table) ?*pardes.Pardes { + peers.dropAll(core); + const bytes = filesystem.readRestore(gpa, path, core.settings.dump_dir.get()) catch |err| { + core.reportError(core.active, "Restore", err); + return null; + }; + defer gpa.free(bytes); + const nc = pardes.dump.restore(core, bytes, path) catch |err| { + core.reportError(core.active, "Restore", err); + return null; + }; + file_watch.unwatchAll(inotify_fd, watches); + _ = file_watch.applyThemeEffect(core, gpa, inotify_fd, watches, 0, false, false); + return nc; +} + pub const Fallback = struct { pub const dump_path = "pardes.dump"; diff --git a/src/tui/tui.zig b/src/tui/tui.zig index 3a5c277e..5c16f1be 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -6,7 +6,6 @@ const libc = std.c; const vaxis = @import("vaxis"); const pardes = @import("../pardes.zig"); const vaxis_input = @import("../vaxis_input.zig"); -const dump = @import("../dump.zig"); const tracy = @import("../tracy.zig"); const look = @import("../look.zig"); const message = pardes.Messages.Message; @@ -1749,18 +1748,7 @@ fn localSession( // off a startup's way. daemon.watch(loop, deliverNote); if (core.takeRestore()) |rp| blk: { - // ponytail: a Restore replaces the core its clients replicate; - // they are let go, and attach again. - sh.peers.dropAll(core); - const bytes = filesystem.readRestore(gpa, rp, core.settings.dump_dir.get()) catch |err| { - core.reportError(core.active, "Restore", err); - break :blk; - }; - defer gpa.free(bytes); - const nc = dump.restore(core, bytes, rp) catch |err| { - core.reportError(core.active, "Restore", err); - break :blk; - }; + const nc = host_io.restoreCore(gpa, core, rp, &sh.peers, sh.inotify_fd, &sh.watches) orelse break :blk; if (sh.lsp_task) |*task| { task.future.cancel(io); sh.lsp_task = null; @@ -1768,10 +1756,7 @@ fn localSession( sh.pipe_tasks.cancelAll(io); for (&sh.gens) |*generation| generation.* +%= 1; for (0..pardes.MAX_PANES) |pane| Shell.closePty(&sh, @intCast(pane)); - file_watch.unwatchAll(sh.inotify_fd, &sh.watches); - _ = file_watch.applyThemeEffect(core, gpa, sh.inotify_fd, &sh.watches, 0, false, false); - // ponytail: a restored session is one view, the live one's - // terminal: the others are let go, as a detach of each. + // One view, the live one's terminal (host_io.restoreCore). const live = sh.term().?; for (&sh.terms) |*slot| if (slot.*) |sc| if (sc != live) { stopInput(io, &sc.thread); |
