diff options
Diffstat (limited to 'src/gui.zig')
| -rw-r--r-- | src/gui.zig | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/gui.zig b/src/gui.zig index 2653a056..15631efa 100644 --- a/src/gui.zig +++ b/src/gui.zig @@ -614,7 +614,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options) !void { opts.cols = @intCast(@max(1, @divTrunc(@as(u32, @intCast(@max(pw, 1))), cell_w))); opts.rows = @intCast(@max(1, @divTrunc(@as(u32, @intCast(@max(ph, 1))), cell_h))); } - const core = if (opts.load_path) |lp| blk: { + var core = if (opts.load_path) |lp| blk: { const bytes = try @import("look.zig").readFile(gpa, lp); defer gpa.free(bytes); break :blk try pardes.Pardes.initFromDump(gpa, opts, bytes); @@ -684,6 +684,24 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options) !void { // 4. effects drainEffects(core, &ptys, &gens, gpa, &queue, &g, true); if (core.quit) break; + // Restore builtin: swap in a core rebuilt from the dump; kill the live + // shells (their detached readers wake on child death; gens bumped so + // the stale eofs close the old fds without touching the replay panes) + if (core.takeRestore()) |rp| blk: { + const bytes = look.readFile(gpa, rp) catch break :blk; + defer gpa.free(bytes); + var o = core.opts; + o.cols = core.screen_w; + o.rows = core.screen_h; // pre-size: dump panes never greet + const nc = pardes.Pardes.initFromDump(gpa, o, bytes) catch break :blk; + for (&ptys) |*slot| if (slot.*) |pt| { + _ = libc.kill(pt.pid, libc.SIG.KILL); + slot.* = null; + }; + for (&gens) |*g2| g2.* +%= 1; + core.deinit(); + core = nc; + } // 5. live cwd for tags/look: cheap /proc readlink per pane, per frame pollCwds(core, &ptys); // 6. the grid follows the window (covers WINDOW_RESIZED and test resizes) @@ -1482,9 +1500,12 @@ fn drainEffects( }, .write_dump => { const out = core.dump_out orelse continue; - const fd = libc.open(pardes.dump.default_path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, @as(libc.mode_t, 0o644)); + var pbuf: [1024:0]u8 = undefined; + const path = pardes.dump.outPath(&pbuf) orelse continue; + const fd = libc.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, @as(libc.mode_t, 0o644)); if (fd < 0) continue; writeFd(fd, out); + core.setLastDump(path); _ = libc.close(fd); }, .set_clipboard => { |
