diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-24 13:47:11 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-24 15:43:44 -0300 |
| commit | f3405aaef8db79094b2741a9caaeaa5328ab6288 (patch) | |
| tree | 5130b95da1d545a5f669710feca9bfa4dfba1a98 /src/pardes.zig | |
| parent | 9db48c4c8a9b2d239680a59d451cd8c1e290ff56 (diff) | |
| download | pardes-f3405aaef8db79094b2741a9caaeaa5328ab6288.tar.gz pardes-f3405aaef8db79094b2741a9caaeaa5328ab6288.zip | |
Store 2/3: one bounded store every window shares (Store.zig): Recent as records read on use, the panes a session closes kept as one-pane dumps; Panes lists them (closed), Enter or a look at @pN brings one back beside the pane that took its rows
An append-only log under $XDG_STATE_HOME/pardes/store, framed records with
a CRC, flock on store.lock (never blocking a step), a stat on use, garbage
passed over and compacted away by the next writer, compaction by rename,
100 MiB cap. dump.dumpPane/restorePane lifted out of dumpState/initDump;
layout.giveBack; Options.recent_path is store_path. Host calls yield one at
a time; /recent refreshes only when no step is out. Tests: two windows and a
busy lock, the cap, garbage/torn/partial records, a closed pane's reopen
with the layout invariant; fs.py: two live sessions over 9P.
Diffstat (limited to 'src/pardes.zig')
| -rw-r--r-- | src/pardes.zig | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index 3c5cf6a7..7f79f094 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -16,6 +16,7 @@ const locations = @import("locations.zig"); pub const tagline = @import("tagline.zig"); pub const exec = @import("exec.zig"); const recent_files = @import("recent.zig"); +const Store = @import("Store.zig"); pub const mouse = @import("mouse.zig"); pub const normal = @import("normal.zig"); pub const edit = @import("edit.zig"); @@ -484,6 +485,7 @@ test { _ = @import("draw.zig"); _ = @import("dump.zig"); // its tests ran nowhere before _ = @import("recent.zig"); + _ = @import("Store.zig"); _ = @import("Presentation.zig"); _ = @import("animation.zig"); _ = @import("pager.zig"); @@ -4326,10 +4328,10 @@ pub const Options = struct { ninep_quic: ?[]const u8 = null, mounts: []const filesystem.Mount = &.{}, config_dir: ?[]const u8 = null, - /// Where the list of files opened lately is kept across sessions - /// (recent.zig), set by the host that has a state directory; none, it - /// lives as long as the session. - recent_path: ?[]const u8 = null, + /// The store every window shares (Store.zig): the files opened lately, + /// the panes closed. Set by the host that has a state directory; none, + /// they last as long as the session. + store_path: ?[]const u8 = null, startup_config_path: ?[]const u8 = null, image_allocator: ?std.mem.Allocator = null, pdf_allocator: ?std.mem.Allocator = null, @@ -4402,6 +4404,9 @@ pub const Pardes = struct { /// The files opened lately, closed ones too (recent.zig): `Recent`, /// /recent, and the jumplist's way back to a closed pane. recent: recent_files.List = .{}, + /// Where Recent is kept, shared with every other window, and the panes + /// this session closed, which Panes brings back (Store.zig). + store: Store = .{}, /// acme's Incl: the directories a look at a name that is nowhere else /// (`stdio.h`, `<foo.h>`) is tried in, in order. The session's, seeded /// with C's (/usr/include, /usr/local/include), kept in a dump. @@ -4410,9 +4415,6 @@ pub const Pardes = struct { /// the next takes. twin_groups: std.ArrayList(panes.File.TwinGroup) = .empty, next_twin: u32 = 1, - /// The kept list was read (or there was none): only then is it written, - /// so a session never writes over one it did not read. - recent_loaded: bool = false, jumps: [MAX_JUMPS]Loc = undefined, njumps: usize = 0, jcur: usize = 0, @@ -4852,29 +4854,15 @@ pub const Pardes = struct { return if (comptime hosted) std.heap.smp_allocator else p.gpa; } - /// The kept list of files opened lately, read once at start. + /// The store read once at start: a new session's, Recent from it. pub fn loadRecent(p: *Pardes) void { - const path = p.opts.recent_path orelse return; - if (comptime !hosted) return; - defer p.recent_loaded = true; - const bytes = filesystem.readFile(p.gpa, path) catch return; - defer p.gpa.free(bytes); - p.recent.read(p.recentGpa(), bytes); + p.store = Store.init(p.opts.store_path); + p.store.load(p); } - /// Written out when it changed, at the end of a step and at the end. + /// What changed written out, at the end of a step and at the end. pub fn saveRecent(p: *Pardes) void { - if (!p.recent.dirty) return; - p.recent.dirty = false; - const path = p.opts.recent_path orelse return; - if (comptime !hosted) return; - if (!p.recent_loaded) return; - var out: std.Io.Writer.Allocating = .init(p.gpa); - defer out.deinit(); - p.recent.write(&out.writer) catch return; - turn.yield(); - defer turn.back(); - std.Io.Dir.cwd().writeFile(std.Io.Threaded.global_single_threaded.io(), .{ .sub_path = path, .data = out.written() }) catch {}; + p.store.flush(p, false); } /// A file pane's path and dot, for the recent list (0 when none). @@ -4928,7 +4916,8 @@ pub const Pardes = struct { pub fn deinit(p: *Pardes) void { // Every file open now is closed with its dot, and the list kept. for (p.panes) |slot| if (slot) |pane| p.noteClosed(pane); - p.saveRecent(); + p.store.flush(p, true); + p.store.deinit(p.recentGpa()); p.recent.deinit(p.recentGpa()); for (p.incl.items) |dir| p.gpa.free(dir); p.incl.deinit(p.gpa); @@ -7230,12 +7219,16 @@ pub const Pardes = struct { const owner = layout.ownerOf(p, id); const place = layout.findPane(p, id); const emptied = if (place) |f| (if (p.col_n[f.col] == 1) f.col else null) else null; + // What it was and where, for Panes to bring back (Store.zig). + const kept = p.store.keep(p, id); + errdefer if (kept) |k| k.free(p.recentGpa()); // Before anything is torn down, so a failure here changes nothing. try p.deinitPane(pane); const gainer = layout.absorbVWeight(p, id, owner orelse to); const beside = if (emptied) |c| p.besideColumn(c, p.rects[id]) else null; layout.removePane(p, id); p.panes[id] = null; + if (kept) |k| p.store.close(p, k, gainer); // The finder's last pane takes the column with it. const finder_gone = if (emptied) |c| p.finder.emptied(p, c) else false; if (p.active != id) return; @@ -7257,6 +7250,8 @@ pub const Pardes = struct { } try p.detachCwds(parents[0..count]); for (ids[0..count], parents[0..count]) |closed, pane| { + // Kept for Panes; its column goes, so it comes back as a new pane. + if (p.store.keep(p, closed)) |k| p.store.close(p, k, null); p.retirePane(pane); layout.removePane(p, closed); p.panes[closed] = null; |
