diff options
Diffstat (limited to 'core/Core.zig')
| -rw-r--r-- | core/Core.zig | 236 |
1 files changed, 111 insertions, 125 deletions
diff --git a/core/Core.zig b/core/Core.zig index 0e37f945..b4745b24 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -78,7 +78,6 @@ const recent_files = @import("recent.zig"); const sel_slot = pardes.sel_slot; const syntax = pardes.syntax; const tagline = pardes.tagline; -const tape = pardes.tape; const test_api = pardes.test_api; const themes = pardes.themes; const turn = &pardes.turn; @@ -195,6 +194,13 @@ image_gpa: std.mem.Allocator, kinds: pardes.Kind.Registry = .{}, tree_sitter_gpa: std.mem.Allocator, opts: Options, +/// The tape this core's steps record on, replay from or go through (a +/// session nobody records: `tape.none`), as `gpa` is its allocator: this +/// process's own, in no digest, dump or rollback copy (`replica.local`, +/// rollback.zig's `unsaved`). Set when the core is made (`Options.tape`; +/// `tape.adoptCore` for a client's join, `tape.adopt` for a Restore) and +/// by the session's clients (replica.zig `Peers`). +tape: *pardes.tape.Tape, resize_count: usize = 0, panes: [MAX_PANES]?*Pane = @splat(null), @@ -446,6 +452,7 @@ pub const replica = .{ // How this process was started, and the last dump it made for // its host to write: a session loaded elsewhere has its own. "opts", "dump_out", "dump_export", + "tape", }, .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, the state file @@ -514,6 +521,9 @@ pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes { .kinds = .started(opts.addons), .tree_sitter_gpa = opts.tree_sitter_allocator orelse gpa, .opts = opts, + // The global still set beside the field (P20): a core made while + // a tape records (PARDES_RECORD, a replica's step) is its. + .tape = opts.tape orelse pardes.tape.on orelse &pardes.tape.none, .tty_toggle = opts.tty_toggle, .views = .{ View{ .frontend = .{ .windowed = opts.windowed }, @@ -538,14 +548,14 @@ pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes { /// A new session, its tape written from here when PARDES_RECORD asks. pub fn init(gpa: std.mem.Allocator, opts: Options) !*Pardes { - tape.startFromEnv(); - const taped = tape.enter(null, .{ .init = opts }); - const p = initSession(gpa, opts) catch |err| { - tape.leave(null, taped); - return err; - }; - tape.leave(p, taped); - return p; + // By hand, not `taped`: no core yet to enter on; the tape adopts the one made. + pardes.tape.startFromEnv(); + const taped = pardes.tape.enter(null, .{ .init = opts }); + // The tape adopts the core made, none on a failure. + var made: ?*Pardes = null; + defer pardes.tape.leave(made, taped); + made = try initSession(gpa, opts); + return made.?; } fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { @@ -700,15 +710,15 @@ pub fn recentGpa(_: *const Pardes) std.mem.Allocator { pub fn loadRecent(p: *Pardes) void { // A replica's Recent is its own, in memory: the recording session's // state file is every session's of its user (core/tape.zig). - if (tape.replaying()) p.db.kind = .off; + if (pardes.tape.replaying()) p.db.kind = .off; p.db.readRecent(p); } /// Whether `path` is one Recent keeps: a file on this host's disk, not /// the served tree's (`/virtual/`) nor a name never saved. -pub fn recentKeeps(path: []const u8) bool { +pub fn recentKeeps(tape: *pardes.tape.Tape, path: []const u8) bool { const local = filesystem.localPath(path) orelse return false; - return exec.kindOf(local) == .file; + return exec.kindOf(tape, local) == .file; } /// A file pane or a kind's (a PDF, a picture) closing: its place noted in Recent, when @@ -763,11 +773,11 @@ pub fn recentDot(pane: *const Pane) ?struct { path: []const u8, line: u32, col: /// reads them: its process's options, so the authority's /// (`tape.authority`); a replica's are its own process's. pub fn configDir(p: *Pardes) ?[]const u8 { - return tape.authority(optsConfigDir, .{p}); + return pardes.tape.authority(optsConfigDir, .{p}); } pub fn startupPath(p: *Pardes) ?[]const u8 { - return tape.authority(optsStartupPath, .{p}); + return pardes.tape.authority(optsStartupPath, .{p}); } fn optsConfigDir(p: *Pardes) ?[]const u8 { @@ -782,7 +792,7 @@ fn optsStartupPath(p: *Pardes) ?[]const u8 { /// in scratch. Recent is the authority's (every window of its user /// writes it): a replica has its answer (`tape.authority`). pub fn recentByHash(p: *Pardes, hash: u64) ?recent_files.Entry { - return tape.authority(recentFound, .{ p, hash }); + return pardes.tape.authority(recentFound, .{ p, hash }); } fn recentFound(p: *Pardes, hash: u64) ?recent_files.Entry { @@ -795,9 +805,10 @@ fn recentFound(p: *Pardes, hash: u64) ?recent_files.Entry { } pub fn deinit(p: *Pardes) void { - const taped = tape.enter(p, .{ .deinit = tape.current(p) }); - tape.forget(p); - defer tape.leave(null, taped); + // By hand, not `taped`: what it records is no argument (`current`), and it leaves on no core. + const taped = pardes.tape.enter(p, .{ .deinit = pardes.tape.current(p) }); + pardes.tape.forget(p); + defer pardes.tape.leave(null, taped); 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); @@ -862,9 +873,8 @@ pub fn endSession(p: *Pardes) void { /// shell feedback after write_dump: remember where the dump landed (the /// topbar grows a `Restore <path>` word pointing at it) -pub fn setLastDump(p: *Pardes, path: []const u8) void { - const taped = tape.enter(p, .{ .set_last_dump = path }); - defer tape.leave(p, taped); +pub const setLastDump = pardes.tape.taped(setLastDumpInner); +fn setLastDumpInner(p: *Pardes, path: []const u8) void { p.pointRestoreAt(path); ctlfs.events.notePath(p, "dump", path); } @@ -891,9 +901,8 @@ pub fn pointRestoreAt(p: *Pardes, path: []const u8) void { } /// the shell polls this each frame: a pending Restore's dump path, or null -pub fn takeRestore(p: *Pardes) ?[]const u8 { - const taped = tape.enter(p, .take_restore); - defer tape.leave(p, taped); +pub const takeRestore = pardes.tape.taped(takeRestoreInner); +fn takeRestoreInner(p: *Pardes) ?[]const u8 { const r = p.restore_req; p.restore_req = null; return r; @@ -917,7 +926,7 @@ fn reportFocus(p: *Pardes) void { // session's step makes the write, off the tape on both sides // (tape.hostCall's pty_write), so the switch shows at once and the // program hears of it a round trip later. - if (tape.speculating() and tape.screenState()) return; + if (pardes.tape.speculating() and pardes.tape.screenState()) return; if (v.focus_told) |old| if (p.panes[old.id]) |pane| { if (pane.serial == old.serial and pardes.Term.modes(pane.terminal).focus) p.emitWrite(old.id, "\x1b[O"); }; @@ -968,9 +977,8 @@ pub fn parkPendingWrite(p: *Pardes, id: usize, bytes: []const u8) void { /// The shell reports the spawned pane's working directory (and later cwd /// changes it observes, e.g. via /proc/<pid>/cwd before each frame). -pub fn setCwd(p: *Pardes, id: usize, cwd: []const u8) void { - const taped = tape.enter(p, .{ .set_cwd = .{ .id = id, .cwd = cwd } }); - defer tape.leave(p, taped); +pub const setCwd = pardes.tape.taped(setCwdInner); +fn setCwdInner(p: *Pardes, id: usize, cwd: []const u8) void { const pane = p.panes[id] orelse return; // A command pane stays the directory's it was run for (newCommand). if (pane.command != null) return; @@ -1004,9 +1012,8 @@ pub fn shellBin(p: *const Pardes) []const u8 { /// already), whose spawn the host answers with that shell's pty. Its id, /// or null with no room. An input, as every host write into the core /// is: a replica of the session makes the same pane. -pub fn adoptShell(p: *Pardes) ?u8 { - const taped = tape.enter(p, .adopt_shell); - defer tape.leave(p, taped); +pub const adoptShell = pardes.tape.taped(adoptShellInner); +fn adoptShellInner(p: *Pardes) ?u8 { var newest: u32 = 0; for (p.panes) |slot| if (slot) |pn| { newest = @max(newest, pn.serial); @@ -1021,17 +1028,15 @@ pub fn adoptShell(p: *Pardes) ?u8 { /// A terminal's reader failed (no end of file: the host closed its pty): /// its pane takes keys again, and why is said. -pub fn readerFailed(p: *Pardes, id: u8, err: anyerror) void { - const taped = tape.enter(p, .{ .reader_failed = .{ .id = id, .err = err } }); - defer tape.leave(p, taped); +pub const readerFailed = pardes.tape.taped(readerFailedInner); +fn readerFailedInner(p: *Pardes, id: u8, err: anyerror) void { const pane = p.panes[id] orelse return; pane.body.mode = .normal; p.reportError(id, "terminal reader", err); } -pub fn acknowledgeShell(p: *Pardes, id: usize, executable: []const u8, prompt_marks: bool) void { - const taped = tape.enter(p, .{ .acknowledge_shell = .{ .id = id, .executable = executable, .prompt_marks = prompt_marks } }); - defer tape.leave(p, taped); +pub const acknowledgeShell = pardes.tape.taped(acknowledgeShellInner); +fn acknowledgeShellInner(p: *Pardes, id: usize, executable: []const u8, prompt_marks: bool) void { if (id < MAX_PANES) if (p.panes[id]) |pane| { ctlfs.pty.shellGone(p, pane, true); // a respawn replaced whatever ran pane.shell_failed = false; @@ -1067,9 +1072,8 @@ pub fn acknowledgeShell(p: *Pardes, id: usize, executable: []const u8, prompt_ma /// build, not only a window's, as only a window's host calls /// them and a terminal's replica of a window's session must step as /// the window does. -pub fn takeFontRequest(p: *Pardes) ?[]const u8 { - const taped = tape.enter(p, .take_font_request); - defer tape.leave(p, taped); +pub const takeFontRequest = pardes.tape.taped(takeFontRequestInner); +fn takeFontRequestInner(p: *Pardes) ?[]const u8 { if (!p.settings.font.pending or p.font_request_taken) return null; const path = p.settings.font.requested_path.get(); if (path.len == 0) return null; @@ -1077,14 +1081,13 @@ pub fn takeFontRequest(p: *Pardes) ?[]const u8 { return path; } -pub fn observeFont( +pub const observeFont = pardes.tape.taped(observeFontInner); +fn observeFontInner( p: *Pardes, effective_name: []const u8, effective_size_hundredths: u16, unit: config.Runtime.FontSizeUnit, ) bool { - const taped = tape.enter(p, .{ .observe_font = .{ .name = effective_name, .size = effective_size_hundredths, .unit = unit } }); - defer tape.leave(p, taped); if (!p.settings.font.effective_name.set(effective_name)) return false; p.settings.font.effective_size_hundredths = effective_size_hundredths; p.settings.font.effective_size_unit = unit; @@ -1093,14 +1096,13 @@ pub fn observeFont( /// Resolve the request already handed to the GUI host. Requested and /// effective tuples deliberately remain separate so DumpConfig can show both. -pub fn acknowledgeFont( +pub const acknowledgeFont = pardes.tape.taped(acknowledgeFontInner); +fn acknowledgeFontInner( p: *Pardes, effective_name: []const u8, effective_size_hundredths: u16, unit: config.Runtime.FontSizeUnit, ) bool { - const taped = tape.enter(p, .{ .acknowledge_font = .{ .name = effective_name, .size = effective_size_hundredths, .unit = unit } }); - defer tape.leave(p, taped); if (!p.settings.font.pending or !p.font_request_taken) return false; const changed = !std.mem.eql( u8, @@ -1115,9 +1117,8 @@ pub fn acknowledgeFont( return true; } -pub fn rejectFont(p: *Pardes) void { - const taped = tape.enter(p, .reject_font); - defer tape.leave(p, taped); +pub const rejectFont = pardes.tape.taped(rejectFontInner); +fn rejectFontInner(p: *Pardes) void { if (!p.settings.font.pending or !p.font_request_taken) return; p.settings.font.pending = false; p.font_request_taken = false; @@ -1143,9 +1144,8 @@ pub inline fn view(p: anytype) if (@typeInfo(@TypeOf(p)).pointer.attrs.@"const") /// A view of its own for a new client (a second window, a terminal /// `pardes --attach`ed), as the live one is laid out; null at /// Views.max. Not live until `toView`. -pub fn openView(p: *Pardes) ?u8 { - const taped = tape.enter(p, .open_view); - defer tape.leave(p, taped); +pub const openView = pardes.tape.taped(openViewInner); +fn openViewInner(p: *Pardes) ?u8 { // Every view taken: one kept for a client that has not come back // for it (Views.away) goes first. ponytail: no timer lets one go; // until its place is wanted it costs a parked slot, and a terminal @@ -1165,9 +1165,8 @@ pub fn openView(p: *Pardes) ?u8 { /// The client of view `k` gone: its view goes, the others stay. The /// last one stays the session's own. -pub fn closeView(p: *Pardes, k: u8) void { - const taped = tape.enter(p, .{ .close_view = k }); - defer tape.leave(p, taped); +pub const closeView = pardes.tape.taped(closeViewInner); +fn closeViewInner(p: *Pardes, k: u8) void { Views.close(p, k); p.sync(); // What its sync queued (a terminal it sized, sized again) done here, @@ -1180,9 +1179,8 @@ pub fn closeView(p: *Pardes, k: u8) void { /// The last client of a session no one else watches gone: its view /// goes, and the session's own is laid out as it was (Views.closeKeeping), /// which the client's rejoin copies. Settled as `closeView` is. -pub fn leaveView(p: *Pardes, k: u8) void { - const taped = tape.enter(p, .{ .leave_view = k }); - defer tape.leave(p, taped); +pub const leaveView = pardes.tape.taped(leaveViewInner); +fn leaveViewInner(p: *Pardes, k: u8) void { Views.closeKeeping(p, k); p.sync(); p.settle(); @@ -1190,18 +1188,16 @@ pub fn leaveView(p: *Pardes, k: u8) void { /// The client of view `k` gone, to join again for it (an Upgrade's /// rejoin, a divergence's): its view kept as it is (Views.away). -pub fn awayView(p: *Pardes, k: u8) void { - const taped = tape.enter(p, .{ .away_view = k }); - defer tape.leave(p, taped); +pub const awayView = pardes.tape.taped(awayViewInner); +fn awayViewInner(p: *Pardes, k: u8) void { Views.away(p, k); } /// A client back for view `k`, kept for it (`awayView`): its own again, /// as it left it; false when it was let go meanwhile. Settled as /// `openView` is, for the join's dump next. -pub fn rejoinView(p: *Pardes, k: u8) bool { - const taped = tape.enter(p, .{ .rejoin_view = k }); - defer tape.leave(p, taped); +pub const rejoinView = pardes.tape.taped(rejoinViewInner); +fn rejoinViewInner(p: *Pardes, k: u8) bool { if (!Views.isAway(p, k)) return false; p.views_away &= ~(@as(u8, 1) << @intCast(k)); p.settle(); @@ -1211,24 +1207,23 @@ pub fn rejoinView(p: *Pardes, k: u8) bool { /// Into view `k`, before the input its client sent. pub fn toView(p: *Pardes, k: u8) void { + // By hand, not `taped`: the live view asked again records nothing (a frontend asks before every input). if (k == p.live) return; - const taped = tape.enter(p, .{ .to_view = k }); - defer tape.leave(p, taped); + const taped = pardes.tape.enter(p, .{ .to_view = k }); + defer pardes.tape.leave(p, taped); Views.to(p, k); } /// Something changed the core without going through `update` -- a watched /// file reloading under it, a theme file rewritten on disk. `pump` draws /// only when it has a reason to, and this is the reason. -pub fn invalidate(p: *Pardes) void { - const taped = tape.enter(p, .invalidate); - defer tape.leave(p, taped); +pub const invalidate = pardes.tape.taped(invalidateInner); +fn invalidateInner(p: *Pardes) void { p.needs_frame = true; } -pub fn reloadWatchedFile(p: *Pardes, id: u8, bytes: []const u8) bool { - const taped = tape.enter(p, .{ .reload_watched_file = .{ .id = id, .bytes = bytes } }); - defer tape.leave(p, taped); +pub const reloadWatchedFile = pardes.tape.taped(reloadWatchedFileInner); +fn reloadWatchedFileInner(p: *Pardes, id: u8, bytes: []const u8) bool { p.invalidate(); look.invalidateLookHover(p, id); const applied = p.applyWatchedFileChanged(id, bytes); @@ -1244,9 +1239,8 @@ pub fn emit(p: *Pardes, e: Effect) void { p.effects_len += 1; } -pub fn nextEffect(p: *Pardes) ?Effect { - const taped = tape.enter(p, .next_effect); - defer tape.leave(p, taped); +pub const nextEffect = pardes.tape.taped(nextEffectInner); +fn nextEffectInner(p: *Pardes) ?Effect { p.refillPendingWrites(); if (p.effects_len == 0) { p.effects_head = 0; @@ -1330,9 +1324,8 @@ pub fn hostKillJob(p: *const Pardes, id: usize) bool { /// A terminal whose shell could not be started: said, and a run waiting /// on it, or written to it from now on, hears `error shell gone` /// rather than wait for a prompt that never comes. -pub fn shellFailed(p: *Pardes, id: u8, err: anyerror) void { - const taped = tape.enter(p, .{ .shell_failed = .{ .id = id, .err = err } }); - defer tape.leave(p, taped); +pub const shellFailed = pardes.tape.taped(shellFailedInner); +fn shellFailedInner(p: *Pardes, id: u8, err: anyerror) void { const pane = p.panes[id] orelse return; pane.shell_failed = true; ctlfs.pty.shellGone(p, pane, false); @@ -1353,9 +1346,8 @@ pub fn shellFailed(p: *Pardes, id: u8, err: anyerror) void { /// A shell started again in a terminal whose shell runs (pty/ctl's /// exec) did not start: the host kept the running one, so only said. -pub fn restartFailed(p: *Pardes, id: u8, err: anyerror) void { - const taped = tape.enter(p, .{ .restart_failed = .{ .id = id, .err = err } }); - defer tape.leave(p, taped); +pub const restartFailed = pardes.tape.taped(restartFailedInner); +fn restartFailedInner(p: *Pardes, id: u8, err: anyerror) void { if (p.panes[id] == null) return; p.sayShellFailure(id, err); } @@ -1368,7 +1360,7 @@ fn sayShellFailure(p: *Pardes, id: u8, err: anyerror) void { // The script is there; the program its `#!` names is not. var said: pardes.Kind.Buf(320) = .{}; var interp: [256]u8 = undefined; - const name = tape.value(.interpreter, missingInterpreter, .{ pane.shell orelse p.shellBin(), &interp }); + const name = pardes.tape.value(.interpreter, missingInterpreter, .{ pane.shell orelse p.shellBin(), &interp }); p.reportFailure(id, if (name) |n| said.print("shell: interpreter {s} not found", .{n}) else "shell: interpreter not found"); } else { p.reportError(id, "shell", err); @@ -1388,18 +1380,17 @@ fn missingInterpreter(bin: []const u8, out: []u8) ?[]const u8 { /// The directory a write of `path` that failed with `err` went into: /// what is there (a directory when it is no local path), whether it is /// missing, and whether that is because one above refuses (EACCES). -fn parentTrouble(path: []const u8, err: anyerror) struct { dir: []const u8, kind: ?std.Io.File.Kind, missing: bool, denied: bool } { +fn parentTrouble(tape: *pardes.tape.Tape, path: []const u8, err: anyerror) struct { dir: []const u8, kind: ?std.Io.File.Kind, missing: bool, denied: bool } { const dir = std.Io.Dir.path.dirname(path) orelse "/"; const local = filesystem.localPath(dir); - const kind: ?std.Io.File.Kind = if (local) |l| exec.kindOf(l) else .directory; + const kind: ?std.Io.File.Kind = if (local) |l| exec.kindOf(tape, l) else .directory; const missing = err == error.FileNotFound or err == error.NotDir or kind != .directory; const denied = missing and (if (local) |l| tape.value(.denied, filesystem.deniedAbove, .{l}) else false); return .{ .dir = dir, .kind = kind, .missing = missing, .denied = denied }; } -pub fn saveFailed(p: *Pardes, id: u8, path: []const u8, err: anyerror) void { - const taped = tape.enter(p, .{ .save_failed = .{ .id = id, .path = path, .err = err } }); - defer tape.leave(p, taped); +pub const saveFailed = pardes.tape.taped(saveFailedInner); +fn saveFailedInner(p: *Pardes, id: u8, path: []const u8, err: anyerror) void { if (p.panes[id]) |pane| if (pane.file) |*f| { // The `-%` spelling fs.zig already uses for "make this dirty". f.saved_revision = f.revision -% 1; @@ -1407,7 +1398,7 @@ pub fn saveFailed(p: *Pardes, id: u8, path: []const u8, err: anyerror) void { var what: pardes.Kind.Buf(limits.host_path_cap + 32) = .{}; // A write into a directory that is not there: said so, in the words // a mount reads as ENOENT; EACCES when one above refuses. - const parent = parentTrouble(path, err); + const parent = parentTrouble(p.tape, path, err); if (parent.denied) p.reportFailure(id, what.print("Save {s}: permission denied", .{path[0..@min(path.len, limits.host_path_cap)]})) else if (parent.missing) @@ -1420,15 +1411,14 @@ pub fn saveFailed(p: *Pardes, id: u8, path: []const u8, err: anyerror) void { /// A Dump the host could not write: said on the message row and in the /// log, and the 9P write that asked for it fails with it, as a failed /// Save's does. -pub fn dumpFailed(p: *Pardes, path: []const u8, err: anyerror) void { +pub const dumpFailed = pardes.tape.taped(dumpFailedInner); +fn dumpFailedInner(p: *Pardes, path: []const u8, err: anyerror) void { const v = p.view(); - const taped = tape.enter(p, .{ .dump_failed = .{ .path = path, .err = err } }); - defer tape.leave(p, taped); var what: [limits.host_path_cap + 8]u8 = undefined; const operation = std.fmt.bufPrint(&what, "Dump {s}", .{path[0..@min(path.len, limits.host_path_cap)]}) catch unreachable; // cap + 5 fits cap + 8 // Into a DumpDir that is not there: said so, ENOENT, as a Save is; // one that is there but no directory (`/dev/null`) says that. - const parent = parentTrouble(path, err); + const parent = parentTrouble(p.tape, path, err); var said: pardes.Kind.Buf(limits.host_path_cap + 48) = .{}; if (parent.denied and parent.kind == null) p.reportFailure(v.active, said.print("{s}: permission denied", .{operation})) @@ -1464,9 +1454,10 @@ pub fn animationActive(p: *const Pardes) bool { } pub fn pump(p: *Pardes, host: Host) !void { + // By hand, not `taped`: the host is set before the enter, which wraps it, and is no input. p.host = host; - const taped = tape.enter(p, .pump); - defer tape.leave(p, taped); + const taped = pardes.tape.enter(p, .pump); + defer pardes.tape.leave(p, taped); // The host as the tape sees it, while it records. const h = p.host; const v = h.vtable; @@ -1549,9 +1540,8 @@ pub fn settle(p: *Pardes) void { /// the client's own core can apply the same at once and expect the /// authority's tape of it to read the same. The session's own pump /// draws it after. -pub fn step(p: *Pardes) void { - const taped = tape.enter(p, .step); - defer tape.leave(p, taped); +pub const step = pardes.tape.taped(stepInner); +fn stepInner(p: *Pardes) void { p.settle(); } @@ -1561,9 +1551,8 @@ pub fn step(p: *Pardes) void { /// can be answered while that step is out in a syscall. Only a request /// that changes a pane costs a frame, which is why a round trip on a /// local socket costs microseconds and not a vsync. -pub fn serveFs(p: *Pardes, req: ctlfs.Req) ctlfs.Reply { - const taped = tape.enter(p, .{ .serve_fs = req }); - defer tape.leave(p, taped); +pub const serveFs = pardes.tape.taped(serveFsInner); +fn serveFsInner(p: *Pardes, req: ctlfs.Req) ctlfs.Reply { // The held write of an Edit whose commands run, asked again by a // retry of its park: still waiting, or its answer, never run twice. if (p.fs.edit_hold) |*h| if (h.names(req)) { @@ -1602,10 +1591,9 @@ pub fn serveFs(p: *Pardes, req: ctlfs.Req) ctlfs.Reply { return reply; } -pub fn update(p: *Pardes, ev: Event) void { +pub const update = pardes.tape.taped(updateInner); +fn updateInner(p: *Pardes, ev: Event) void { const v = p.view(); - const taped = tape.enter(p, .{ .update = ev }); - defer tape.leave(p, taped); defer pardes.panes.File.syncTwins(p); defer p.reportFocus(); // A tick with no deadline due is the one event that cannot change @@ -1756,15 +1744,15 @@ fn fsReport(p: *Pardes) void { pub fn readSessionFacts(p: *Pardes) void { // A dump made since carries them all: its shell is never empty. if (p.session_shell_len != 0) return; - if (p.session_dir_len == null) if (tape.value(.env, processDir, .{&p.session_dir})) |dir| { + if (p.session_dir_len == null) if (pardes.tape.value(.env, processDir, .{&p.session_dir})) |dir| { std.mem.copyForwards(u8, &p.session_dir, dir); p.session_dir_len = @intCast(dir.len); }; - if (tape.value(.env, filesystem.processHome, .{})) |home| if (home.len <= p.session_home.len) { + if (pardes.tape.value(.env, filesystem.processHome, .{})) |home| if (home.len <= p.session_home.len) { @memcpy(p.session_home[0..home.len], home); p.session_home_len = @intCast(home.len); }; - const shell = tape.value(.env, config.defaultShell, .{}); + const shell = pardes.tape.value(.env, config.defaultShell, .{}); const kept = shell[0..@min(shell.len, p.session_shell.len)]; @memcpy(p.session_shell[0..kept.len], kept); p.session_shell_len = @intCast(kept.len); @@ -1783,7 +1771,7 @@ pub fn sessionShell(p: *const Pardes) []const u8 { /// A path's leading `~` (alone, or before `/` or `:`) as the session's home; /// `~user` that user's (fs.expandHomeFrom). pub fn expandHome(p: *const Pardes, path: []const u8, out: *[4096]u8) []const u8 { - return filesystem.expandHomeFrom(path, out, p.sessionHome()); + return filesystem.expandHomeFrom(p.tape, path, out, p.sessionHome()); } /// The session's home, null for none. @@ -1807,9 +1795,8 @@ pub const SavePath = Effect.Buf(effect_path_cap); /// What was said of a failure just now on pane `id` is also the waiting /// 9P write's (9p_io, `fs.late_failure`). -pub fn noteLateFailure(p: *Pardes, id: usize) void { - const taped = tape.enter(p, .{ .note_late_failure = id }); - defer tape.leave(p, taped); +pub const noteLateFailure = pardes.tape.taped(noteLateFailureInner); +fn noteLateFailureInner(p: *Pardes, id: usize) void { // Said by reportFailure just now: its words fitted whole, the // reason kept; else what the message row has. const said = if (p.fs.said_at == p.fs.failures and p.fs.said_len > 0) @@ -1822,10 +1809,9 @@ pub fn noteLateFailure(p: *Pardes, id: usize) void { /// The frontend drew a frame: a pointer resting on it follows what is /// under it now, a drag's moving end and a look-hover's word. -pub fn presented(p: *Pardes) void { +pub const presented = pardes.tape.taped(presentedInner); +fn presentedInner(p: *Pardes) void { const v = p.view(); - const taped = tape.enter(p, .presented); - defer tape.leave(p, taped); if (v.pointer_inside and v.drag != .none) { v.hover_col = v.pointer_raw_col; v.hover_row = v.pointer_raw_row; @@ -1836,9 +1822,8 @@ pub fn presented(p: *Pardes) void { /// The window's answer to a WindowOpacity: done, or `failure` says why /// not, `applied` the opacity it keeps. -pub fn windowOpacityDone(p: *Pardes, applied: u8, failure: ?[]const u8) void { - const taped = tape.enter(p, .{ .window_opacity_done = .{ .applied = applied, .failure = failure } }); - defer tape.leave(p, taped); +pub const windowOpacityDone = pardes.tape.taped(windowOpacityDoneInner); +fn windowOpacityDoneInner(p: *Pardes, applied: u8, failure: ?[]const u8) void { p.settings.window_opacity_pending = false; const reason = failure orelse return; // Do not claim a value the compositor refused; an explicit retry of @@ -1970,7 +1955,7 @@ pub fn sync(p: *Pardes) void { // A directory pane's entries follow its width, as acme's // columns do (Dir.fit). if (pane.file) |file| if (file.listing != null and r.h > pane.tag_rows) pardes.panes.Dir.fit(p, pane, pane.cols); - if (pane.pending_command.wait == .input) pane.releasePendingCommand(p, id, tape.value(.prompt, struct { + if (pane.pending_command.wait == .input) pane.releasePendingCommand(p, id, pardes.tape.value(.prompt, struct { fn ready(at: *const Pane) bool { return pardes.Term.prompt(at.terminal).input_ready; } @@ -1982,7 +1967,7 @@ pub fn sync(p: *Pardes) void { // its shell's FIRST prompt, or never: typed later it would land // in whatever runs then, or in the middle of a line someone // typed (Pane.greeting). - if (pane.greet and pane.isTerminal() and p.resize_count > 0) switch (tape.value(.prompt, Pane.greeting, .{pane})) { + if (pane.greet and pane.isTerminal() and p.resize_count > 0) switch (pardes.tape.value(.prompt, Pane.greeting, .{pane})) { .wait => {}, .never => pane.greet = false, .now => { @@ -2106,9 +2091,8 @@ pub fn nextWake(p: *const Pardes) ?u64 { /// after a slow frame as it does anywhere. A wait (a message lingering, /// the look-hover delay) is jumped to its end in one step and drawn /// once. Idle, time is not banked: the next wait starts from now. -pub fn advance(p: *Pardes, now_ns: u64) void { - const taped = tape.enter(p, .{ .advance = now_ns }); - defer tape.leave(p, taped); +pub const advance = pardes.tape.taped(advanceInner); +fn advanceInner(p: *Pardes, now_ns: u64) void { // The first time a shell's clock is seen, core time starts there. const started = p.clock.started; p.clock.started = true; @@ -2119,7 +2103,7 @@ pub fn advance(p: *Pardes, now_ns: u64) void { // The session's ticks are the recording session's: a picture still // decoding or a fade still moving asks for frames the way a message // waiting to go does, and a replica that draws nothing has none. - while (tape.value(.wake, nextWake, .{p})) |due| { + while (pardes.tape.value(.wake, nextWake, .{p})) |due| { if (due > now_ns) break; // Only waiting until `due`: its counters move there at once. const held = (due - p.clock.stepped_ns) / frame; @@ -2241,9 +2225,9 @@ pub const Boot = enum { }; pub const Options = struct { - /// Not taped: the client's list of distrusted kinds, and where its - /// runner keeps its frame statistics. - pub const replica = .{ .local = .{ "distrusted", "frames" } }; + /// Not taped: the client's list of distrusted kinds, where its runner + /// keeps its frame statistics, and the core's tape. + pub const replica = .{ .local = .{ "distrusted", "frames", "tape" } }; tty_only: bool = false, /// The first view's frontend is a window (`Pardes.frontend`), as a /// window's build says: an option, taped with the rest, so that a @@ -2288,6 +2272,8 @@ pub const Options = struct { /// A client's: the kinds it caught breaking PA_PLAIN, its frontend's /// list, which outlives each core it joins with. In no tape and no dump. distrusted: ?*pardes.Addon.Distrusted = null, + /// The core's tape (`Pardes.tape`); null: `tape.on`'s, or `tape.none`. + tape: ?*pardes.tape.Tape = null, /// What the host's scan of the addon directories found (Addon.scan). addons: []const pardes.Kind.Loaded = &.{}, tree_sitter_allocator: ?std.mem.Allocator = null, |
