summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index 16dd794e..b42bf643 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -19,6 +19,7 @@ pub const tagline = @import("tagline.zig");
pub const exec = @import("exec.zig");
const recent_files = @import("recent.zig");
const Store = @import("Store.zig");
+const Db = @import("Db.zig");
pub const mouse = @import("mouse.zig");
pub const normal = @import("normal.zig");
pub const edit = @import("edit.zig");
@@ -449,6 +450,7 @@ test {
_ = @import("upgrade.zig");
_ = @import("recent.zig");
_ = @import("Store.zig");
+ _ = @import("Db.zig");
_ = @import("pager.zig");
_ = @import("Places.zig");
_ = @import("FrameStats.zig");
@@ -3223,10 +3225,10 @@ pub const Options = struct {
ninep_tcp: ?[]const u8 = null,
mounts: []const filesystem.Mount = &.{},
config_dir: ?[]const u8 = null,
- /// Recent's file, which every session of the user's shares (Store.zig).
- /// Set by the host that has a state directory; none, Recent lasts as
- /// long as the session.
- recent_path: ?[]const u8 = null,
+ /// Where what outlives the session is kept (Db.zig): the user's state
+ /// file, set by a host that has one; none, Recent lasts as long as the
+ /// session; memory, the test host's.
+ state: Db.Kind = .off,
startup_config_path: ?[]const u8 = null,
image_allocator: ?std.mem.Allocator = null,
pdf_allocator: ?std.mem.Allocator = null,
@@ -3303,9 +3305,10 @@ 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 = .{},
- /// Recent's file, shared with every other session, and the panes this
- /// session closed, which Panes brings back (Store.zig).
+ /// The panes this session closed, which Panes brings back (Store.zig).
store: Store = .{},
+ /// The user's state file, which every session shares: Recent's (Db.zig).
+ db: Db = .{},
/// 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.
@@ -3602,11 +3605,11 @@ pub const Pardes = struct {
"opts", "dump_out",
},
.derived = .{ "shell_rows", "diff_output", "locations_cache", "retired_panes", "tty_filter_palette", "body_chrome" },
- // The host's handles, the 9P server's fids and log, Recent's file
- // every session of the user shares (and Recent read from it) with
- // this session's closed panes, and the files of a host with no file
+ // The host's handles, the 9P server's fids and log, the state file
+ // every session of the user shares (and Recent read from it), this
+ // session's closed panes, and the files of a host with no file
// system of its own.
- .authority = .{ "host", "fs", "store", "recent", "fallback" },
+ .authority = .{ "host", "fs", "store", "recent", "db", "fallback" },
.len = .{ .{ "jumps", "njumps" }, .{ "look_src", "n_look_src" }, .{ "leader_keys", "leader_n" }, .{ "col_x", "ncol" }, .{ "col_w", "ncol" }, .{ "session_dir", "session_dir_len" } },
};
@@ -3644,6 +3647,7 @@ pub const Pardes = struct {
.scratch = .init(gpa),
.frame_arena = .init(opts.frame_allocator orelse gpa),
.fallback = .{ .gpa = gpa },
+ .db = .{ .kind = opts.state },
};
errdefer p.deinit();
p.fs.started = ctlfs.events.now();
@@ -3759,7 +3763,6 @@ pub const Pardes = struct {
},
}
p.sync();
- p.loadRecent();
for (config.default_incl) |dir| {
const copy = try gpa.dupe(u8, dir);
p.incl.append(gpa, copy) catch |err| {
@@ -3768,6 +3771,8 @@ pub const Pardes = struct {
};
}
exec.applyStartupConfig(p);
+ // After the startup config, whose DumpDir says where the state file is.
+ p.loadRecent();
colors.finishThemeInitialization(p);
p.sync();
// A config init that opens a file with `Look …` armed the pulse before
@@ -3795,17 +3800,17 @@ pub const Pardes = struct {
return std.heap.smp_allocator;
}
- /// Recent's file read once at start: a new session's.
+ /// Recent read from the state file once at start: a new session's.
pub fn loadRecent(p: *Pardes) void {
- // A replica's store is its own, in memory: the recording session's
- // file is every session's of its user (src/tape.zig).
- p.store = .{ .path = if (tape.replaying()) null else p.opts.recent_path };
- p.store.load(p);
+ // A replica's Recent is its own, in memory: the recording session's
+ // state file is every session's of its user (src/tape.zig).
+ if (tape.replaying()) p.db.kind = .off;
+ p.db.readRecent(p);
}
/// What changed written out, at the end of a step and at the end.
pub fn saveRecent(p: *Pardes) void {
- p.store.flush(p, false);
+ p.db.writeRecent(p, false);
}
/// Whether `path` is one Recent keeps: a file on this host's disk, not
@@ -3817,7 +3822,7 @@ pub const Pardes = struct {
/// A file, PDF or image pane closing: its place noted in Recent, when
/// Recent keeps it.
- fn noteClosed(p: *Pardes, pane: *const Pane) void {
+ pub fn noteClosed(p: *Pardes, pane: *const Pane) void {
const d = recentPlace(pane) orelse return;
// The host asked first, always: what Recent holds is the
// authority's, and a step that asked only when it did not know the
@@ -3900,7 +3905,8 @@ pub const Pardes = struct {
if (std.c.getenv("PARDES_FRAMES")) |path| p.frames.dump(std.mem.span(path));
// Every file open now is closed with its dot, and the list kept.
for (p.panes) |slot| if (slot) |pane| p.noteClosed(pane);
- p.store.flush(p, true);
+ p.db.writeRecent(p, true);
+ p.db.deinit();
p.store.deinit(p.recentGpa());
p.recent.deinit(p.recentGpa());
for (p.incl.items) |dir| p.gpa.free(dir);