summaryrefslogtreecommitdiff
path: root/src/host/Sessions.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 01:57:33 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit41bdeb1b3fadc266823c43086de61913be8e60f6 (patch)
treebc042874c8c614b788e6f59d3e090144671fd90e /src/host/Sessions.zig
parentb1311b3d489a8054456cba7054160ed7fb7e70e1 (diff)
downloadsketchbook-41bdeb1b3fadc266823c43086de61913be8e60f6.tar.gz
sketchbook-41bdeb1b3fadc266823c43086de61913be8e60f6.zip
Dial by name, and fs in every sketch's binary, answering with the sketch closed
A run a person watches (not headless, a script or an export) posts its tree as $XDG_RUNTIME_DIR/9p/sketchbook/<name>, the sketch's Info.name; --9p NAME posts under another name, --9p /path listens at a socket path as before. A name a live run holds is refused, a stale one replaced; a default post that fails says so and the run goes on without one, an explicit --9p that fails ends it as before. (cloud9's post() takes names without a slash, so control.zig makes the sketchbook/ directory and binds there itself, with post.probe deciding live or stale.) `fs VERB [PATH [WORDS]]`, after the options, in the generic host (`sketchbook LIBRARY fs ...`) and in every executable built with sketchbook (`drat-meout fs read state/scene`), is cloud9.verbs.run on an Fsys: the running sketch's tree when one is posted (or at --9p), else the same tree served in this process over a socketpair, on a thread (Control.serveOffline, the same respond with `offline` set), from the save's newest State (--state's save, else the default one; read only: Sessions.openRead, no session started, restored into today's layout), else from the State's declared defaults (init is not run). README, commands, ctl's read and state/ answer; a write and status, log, screen.png and the traces answer in words, "drat-meout is not running: this is its save's newest State, frame 61 of <save>". No window, no SDL. sketchbook.init's modules gain cloud9, so an app's own tests can dial its executable with cloud9.Fsys. Tests: a new step, test-fs (in test): the replay fixture posted by name under a private runtime directory, driven with its own binary's fs: ls, a state write and read, a refused value in words, a live click, a screenshot read, help of state/dots and ctl, quit and the name gone; then closed: a state file read from the defaults, status refused in words. test-fs, test-control, test-paths, test-setup, test-sessions: 56/56 steps, 27/27 tests. drat-meout's copy builds unchanged and answers fs with the game closed: 94 leaves, 16,522 files, 17,608 values, 10,408 directories. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/host/Sessions.zig')
-rw-r--r--src/host/Sessions.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/host/Sessions.zig b/src/host/Sessions.zig
index cf0ab24..d6caf9c 100644
--- a/src/host/Sessions.zig
+++ b/src/host/Sessions.zig
@@ -191,6 +191,19 @@ pub fn open(gpa: std.mem.Allocator, io: std.Io, want: Mode, path: []const u8, fi
return s;
}
+/// The database at `path`, read only and no session started in it: for
+/// its `present` with no run of the sketch (`fs` with the sketch closed).
+pub fn openRead(gpa: std.mem.Allocator, io: std.Io, path: []const u8) !Sessions {
+ var s: Sessions = .{ .gpa = gpa, .io = io };
+ errdefer s.deinit();
+ s.file = try std.Io.Dir.cwd().openFile(io, path, .{});
+ s.buffer = try gpa.create(std.Io.Writer.Allocating);
+ s.buffer.?.* = .init(gpa);
+ s.db = .{ .file = try Disk.init(io, .{ .file = s.file.?, .buffer = s.buffer.?, .fsync = false }) };
+ s.session = try s.count(.sessions);
+ return s;
+}
+
pub fn deinit(s: *Sessions) void {
s.dropQueued();
s.queued.deinit(s.gpa);