summaryrefslogtreecommitdiff
path: root/src/pardes.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 15:15:01 -0300
committerGabriel Schneider <[email protected]>2026-10-30 16:49:16 -0300
commit5af775e9817395af39792cc609b832394d4a4fb8 (patch)
treed1aad3579b8b16ebd74c80567ae386fa7d3825d8 /src/pardes.zig
parent3f62f4e2a0f40e9d92f79665c2e87804c2d55357 (diff)
downloadpardes-5af775e9817395af39792cc609b832394d4a4fb8.tar.gz
pardes-5af775e9817395af39792cc609b832394d4a4fb8.zip
replica: what only the authority holds, a step reads off the tape (tape.authority): the store's closed panes and Recent, a script's hold on a pane's events, the 9P socket, the session's config directory and startup file; a replica's own are never read, and never put back by a rollback
The Panes picker's closed rows, Recent's rows, a closed pane brought back (a Look at @pN, a Panes row), a jump to a closed file and the +Jumps rows read `p.store` and `p.recent`, `.authority` state a replica keeps on its own: its store has no file, its Recent only what it replayed since it joined. The rows made of them went into digested state, so every client of a session diverged together after a Del (H4), every client that joined after one diverged at its first unit forever (H11: trackJump dropped a closed file's jumps at every step when Recent did not know the file), a client's Del of a file the session's Recent knew made the stat the session skipped (H12: noteClosed looked in Recent first), and a client on another machine read its own store (H13). - tape.authority: poison, then a value read: the authority's answer is taped, a replay takes it, a speculation waits for it. One site, `.authority`. - Readers through it: Query's Recent and closed-pane rows, Store.reopen's record, Pardes.recentByHash (jumps, +Jumps), mouse.reportRange's readers check (a script reading a pane's events takes a look or exec: `pane.fs.readers`, the 9P server's), Tty9p's socket check, Pardes.configDir and startupPath (ThemeFile, DumpThemes, Config, DumpConfig, an init file saved), DumpConfig's dump directory. - trackJump no longer reads Recent at every step: a closed file's jump stays; the jump to it drops that file's entries when Recent has forgotten it, as when the file is gone. - noteClosed asks the host (recentKeeps, a taped stat) before it looks in Recent: the same syscall on every side. - The tty toggle, read on every key, is session state: Pardes.tty_toggle, from the options when the core is made, dumped. - The rollback copy no longer saves `store` and `recent` (rollback.zig `unsaved`): their bytes put back pointed at lists the host's heap (recentGpa) had freed, which the epoch never holds. A speculated Del then a Panes listing read a freed name (H8, the segfault). Tests, each failing before: a rollback leaves the store and Recent as a speculation left them; a replica joined after a pane closed has the session's jump to it, its Panes and Recent rows, asked by either (and the variant hunt's Recent written by another window); a replica's Del of a file its session's Recent knows asks the host what the session asked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/pardes.zig')
-rw-r--r--src/pardes.zig75
1 files changed, 58 insertions, 17 deletions
diff --git a/src/pardes.zig b/src/pardes.zig
index f0d2cd0c..36ce6bdb 100644
--- a/src/pardes.zig
+++ b/src/pardes.zig
@@ -857,7 +857,7 @@ test "Togglettymode builtin and keyboard chord share mode transitions including
try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
try std.testing.expect(p.executeBuiltinLine(0, "Togglettymode"));
try std.testing.expectEqual(Text.Mode.normal, pane.body.mode);
- p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } });
+ p.update(.{ .key = .{ .cp = p.tty_toggle, .ctrl = true } });
try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
// The tag has its own mode: the body keeps tty while the tag is typed into.
tagline.enterTag(p, pane);
@@ -867,7 +867,7 @@ test "Togglettymode builtin and keyboard chord share mode transitions including
try std.testing.expectEqual(Text.Mode.normal, pane.body.mode);
try std.testing.expect(pane.focus == .body);
tagline.enterTag(p, pane);
- p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } });
+ p.update(.{ .key = .{ .cp = p.tty_toggle, .ctrl = true } });
try std.testing.expectEqual(Text.Mode.tty, pane.body.mode);
try std.testing.expect(pane.focus == .body);
@@ -4732,6 +4732,10 @@ pub const Pardes = struct {
/// The views no frontend here draws: a replica client's, which its own
/// process draws (src/replica.zig). A pump skips them.
undrawn: u8 = 0,
+ /// The Ctrl key into a terminal's tty mode and out (`--tty-toggle`): the
+ /// session's, taken from its options when it is made, so a dump carries
+ /// it to a replica, whose own options are its process's.
+ tty_toggle: u21 = config.tty_toggle_default,
/// per-update scratch (paneCursorLines, selection text); reset each update
scratch: std.heap.ArenaAllocator,
/// The arena each frame's Surface text is built in, reset by `pump`. Hosts
@@ -4797,6 +4801,7 @@ pub const Pardes = struct {
.tree_sitter_gpa = opts.tree_sitter_allocator orelse gpa,
.opts = opts,
.windowed = opts.windowed,
+ .tty_toggle = opts.tty_toggle,
.col_tags = @splat(.{ .what = .column, .gpa = gpa }),
.global_tag = .{ .what = .workspace, .gpa = gpa },
.fs = .{},
@@ -4989,7 +4994,10 @@ pub const Pardes = struct {
/// Recent keeps it.
fn noteClosed(p: *Pardes, pane: *const Pane) void {
const d = recentPlace(pane) orelse return;
- if (p.recent.get(d.path) == null and !recentKeeps(d.path)) 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
+ // file would ask on one side and not the other.
+ if (!recentKeeps(d.path) and p.recent.get(d.path) == null) return;
p.recent.closedSel(p.recentGpa(), d.path, d.line, d.col, d.aline, d.acol);
}
@@ -5024,9 +5032,38 @@ pub const Pardes = struct {
};
}
- /// The recent entry a closed jump names, by its path's hash.
- pub fn recentByHash(p: *const Pardes, hash: u64) ?recent_files.Entry {
- for (p.recent.entries.items) |e| if (std.hash.Wyhash.hash(0, e.path) == hash) return e;
+ /// The session's configuration directory and startup file, as a step
+ /// 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});
+ }
+
+ pub fn startupPath(p: *Pardes) ?[]const u8 {
+ return tape.authority(optsStartupPath, .{p});
+ }
+
+ fn optsConfigDir(p: *Pardes) ?[]const u8 {
+ return p.opts.config_dir;
+ }
+
+ fn optsStartupPath(p: *Pardes) ?[]const u8 {
+ return p.opts.startup_config_path;
+ }
+
+ /// The recent entry a closed jump names, by its path's hash, its path
+ /// 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 });
+ }
+
+ fn recentFound(p: *Pardes, hash: u64) ?recent_files.Entry {
+ for (p.recent.entries.items) |e| if (std.hash.Wyhash.hash(0, e.path) == hash) {
+ var found = e;
+ found.path = p.scratch.allocator().dupe(u8, e.path) catch return null;
+ return found;
+ };
return null;
}
@@ -6607,7 +6644,7 @@ pub const Pardes = struct {
if (header == null and pane.isTerminal() and pane.body.mode == .tty and pane.focus == .body and pane.prompt == .none) {
p.leader_on = false;
p.ctrl_w_pending = false;
- if (key.ctrl and !key.alt and key.cp == p.opts.tty_toggle)
+ if (key.ctrl and !key.alt and key.cp == p.tty_toggle)
return p.toggleTty(p.active);
// With ProgramEsc on, bare Escape leaves only at a shell prompt
// (Shift-Esc, above, always).
@@ -6672,7 +6709,7 @@ pub const Pardes = struct {
}
return;
}
- const tty_toggle = key.ctrl and key.cp == p.opts.tty_toggle;
+ const tty_toggle = key.ctrl and key.cp == p.tty_toggle;
if (pane.isTerminal() and tty_toggle) {
return p.toggleTty(p.active);
}
@@ -7624,10 +7661,12 @@ pub const Pardes = struct {
if (i == p.jcur) cur = w; // survives -> lands at w; dies -> the next one does
var kept = j;
const live = if (j.serial == 0) false else if (p.panes[j.pane]) |pane| pane.serial == j.serial else false;
- // A file's pane closed: its entry stays, closed, while the recent
- // list knows the file, and a jump to it opens it again.
+ // A file's pane closed: its entry stays, closed, and a jump to it
+ // opens it again from Recent, or drops it when Recent has
+ // forgotten it (`jumpBy`: Recent is the authority's, read when
+ // it is wanted, not at every step).
if (!live) {
- if (j.path_hash == 0 or p.recentByHash(j.path_hash) == null) continue;
+ if (j.path_hash == 0) continue;
kept.serial = 0;
// Open again in some pane (a look, Recent): the entry is that
// pane's, and closed only while no pane has the file.
@@ -7727,12 +7766,13 @@ pub const Pardes = struct {
// A closed file's entry: opened again at its dot, placed as a look
// places it, and the entry is that pane from here on.
if (j.serial == 0) {
- const e = p.recentByHash(j.path_hash) orelse return;
- // Deleted since: its entries go, it is said, and the step goes
- // on to the next place, never stuck on one that cannot open.
- if (!recentKeeps(e.path)) {
+ const found = p.recentByHash(j.path_hash);
+ // Deleted since, or Recent has forgotten it: its entries go (the
+ // first said), and the step goes on to the next place, never
+ // stuck on one that cannot open.
+ if (found == null or !recentKeeps(found.?.path)) {
var said: [recent_path_cap + 32]u8 = undefined;
- p.setMessage(p.active, std.fmt.bufPrint(&said, "{s}: deleted, skipped", .{e.path}) catch "deleted, skipped");
+ if (found) |e| p.setMessage(p.active, std.fmt.bufPrint(&said, "{s}: deleted, skipped", .{e.path}) catch "deleted, skipped");
const hash = j.path_hash;
var w: usize = 0;
var cur = p.jcur;
@@ -7750,6 +7790,7 @@ pub const Pardes = struct {
// round takes one file's entries away, so it ends.
return p.jumpBy(delta);
}
+ const e = found.?;
const from = p.active;
look.reopenAt(p, from, e.path, .{ .line = @max(1, j.line), .col = if (j.pdf) 0 else @max(1, j.col) });
const opened = p.panes[p.active] orelse return;
@@ -9284,7 +9325,7 @@ test "raw tty forwards Ctrl letters and former global shortcuts to the child" {
_ = drainWrites(p, &buf);
edit.setYank(p, "register text");
for ('a'..'z' + 1) |letter| {
- if (letter == p.opts.tty_toggle) continue; // editor/TTY mode shortcut
+ if (letter == p.tty_toggle) continue; // editor/TTY mode shortcut
if (letter == 'v') continue; // the window's paste, asserted just below
p.update(.{ .key = .{ .cp = @intCast(letter), .ctrl = true } });
const expected = [_]u8{@intCast(letter - 'a' + 1)};