summaryrefslogtreecommitdiff
path: root/core/Effect.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 20:31:32 -0300
committerGabriel Schneider <[email protected]>2026-11-19 20:31:32 -0300
commit0db34fbf28e70c8c6a3c6025c0888fc5ec75201c (patch)
treef2e288668decded9276ebc45907f16d651b06f9e /core/Effect.zig
parent2ab05b536bc3b063666b5aaab497157adc2a9120 (diff)
parentbf351b62e8843a3d173cedeefa2dd0b8ef4b4392 (diff)
downloadpardes-0db34fbf28e70c8c6a3c6025c0888fc5ec75201c.tar.gz
pardes-0db34fbf28e70c8c6a3c6025c0888fc5ec75201c.zip
integration: a pane's and a view's slot as types, with the regular-expression fixes and the fixes the real loops asked for: pardes-ids (Pane.Id and View.Id through the entries, the events, the effects, the Host table and the device messages) and pardes-merge21, merged without a textual conflict; one call site written since on the old type follows (core/draw.zig: the twin test's file_changed event, .pane = .at(0)); tui core-test 848/991 (143 skipped), shell-test 1027/1030, the window builds; gates in the coordinator's ledger
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Effect.zig')
-rw-r--r--core/Effect.zig98
1 files changed, 49 insertions, 49 deletions
diff --git a/core/Effect.zig b/core/Effect.zig
index bc952b8b..7166294f 100644
--- a/core/Effect.zig
+++ b/core/Effect.zig
@@ -37,29 +37,29 @@ pub const Effect = union(enum) {
/// A child for the pane in slot `pane` -- the one whose serial is
/// `serial`: a pane closed and its slot taken before the effect is
/// performed is not the one it was for (perform).
- spawn: struct { pane: u8, serial: u32, cwd: Buf(effect_path_cap) },
- write: struct { pane: u8, bytes: Buf(effect_write_cap) },
- resize_pty: struct { pane: u8, cols: u16, rows: u16 },
+ spawn: struct { pane: Pane.Id, serial: u32, cwd: Buf(effect_path_cap) },
+ write: struct { pane: Pane.Id, bytes: Buf(effect_write_cap) },
+ resize_pty: struct { pane: Pane.Id, cols: u16, rows: u16 },
/// For the pane whose serial is `serial`, as `spawn` is (perform).
- signal_pty: struct { pane: u8, serial: u32, sig: PtySignal },
+ signal_pty: struct { pane: Pane.Id, serial: u32, sig: PtySignal },
/// The terminal pane in this slot is gone: the shell hangs up its pty
/// and ends the shell, rather than leave it running with nobody to read.
- close_pty: struct { pane: u8 },
+ close_pty: struct { pane: Pane.Id },
open_link: Buf(256),
/// A program a plumbing rule starts (Plumb.run): its directory, then
/// its argv, each ended by a NUL. A failure to start it is said at
/// pane `pane`.
- start: struct { pane: u8, line: Buf(effect_path_cap) },
+ start: struct { pane: Pane.Id, line: Buf(effect_path_cap) },
/// write this pane's file content to its path; the shell reads both off
/// the core (content is unbounded, effects are fixed-size values)
- save_file: struct { pane: u8 },
- save_text: struct { pane: u8, serial: u32, path: Buf(effect_path_cap), promote: bool = false },
+ save_file: struct { pane: Pane.Id },
+ save_text: struct { pane: Pane.Id, serial: u32, path: Buf(effect_path_cap), promote: bool = false },
write_dump,
set_clipboard,
read_clipboard,
/// `arg` up to 128 bytes, or for `explain` the query it explains,
/// `<kind> <arg>`.
- lsp: struct { id: u32, kind: lsp.Kind, pane: u8, offset: u32, arg: Buf(160) },
+ lsp: struct { id: u32, kind: lsp.Kind, pane: Pane.Id, offset: u32, arg: Buf(160) },
/// Snapshot the matching request with pipeRequest(id), then run it away
/// from the UI/event loop and answer with pipe_resp.
pipe: struct { id: u32 },
@@ -71,19 +71,19 @@ pub const Effect = union(enum) {
hand_over: struct { seq: u32 },
/// Write what an Edit's `w` took (`Pipe.writes`), in order.
edit_write,
- watch: struct { pane: u8, on: bool, mode: WatchMode = .reconcile },
+ watch: struct { pane: Pane.Id, on: bool, mode: WatchMode = .reconcile },
theme_file: struct { generation: u32, on: bool },
/// Write the build-time theme ring below the per-user config directory.
/// The pane receives the completion/error message from the native host.
- dump_themes: struct { pane: u8 },
- detach: struct { pane: u8 },
+ dump_themes: struct { pane: Pane.Id },
+ detach: struct { pane: Pane.Id },
/// An addon loaded, let go, or let go and loaded again (Addon.zig):
/// `arg` its path, or for unload its kind's name. Answered by an
/// `addon` event.
- addon: struct { op: @import("Addon.zig").Op, pane: u8, arg: Buf(effect_path_cap) },
+ addon: struct { op: @import("Addon.zig").Op, pane: Pane.Id, arg: Buf(effect_path_cap) },
/// A kind's job for the host's workers (host_io.Job), answered by a
/// `job` event.
- job: struct { pane: u8, serial: u32, token: u32 },
+ job: struct { pane: Pane.Id, serial: u32, token: u32 },
quit,
pub fn Buf(comptime n: usize) type {
@@ -120,8 +120,8 @@ fn performInner(p: *Pardes, e: Effect) void {
switch (e) {
// The host reads the pane (its command, its shell) as it forks,
// so the slot must still hold the pane the spawn was for.
- .spawn => |s| if (if (p.panes[s.pane]) |pane| pane.serial != s.serial else true) {} else if (v.spawn) |f| f(p.host.ctx, s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane] orelse "") else s.cwd.slice()) else {
- p.fallback.spawned[s.pane] = true;
+ .spawn => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.spawn) |f| f(p.host.ctx, s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane.index()] orelse "") else s.cwd.slice()) else {
+ p.fallback.spawned[s.pane.index()] = true;
},
// A pane with no child is silent: nothing invents output on its
// screen, and the bytes are dropped rather than transcribed.
@@ -129,7 +129,7 @@ fn performInner(p: *Pardes, e: Effect) void {
.resize_pty => |r| if (v.pty_resize) |f| f(p.host.ctx, r.pane, r.cols, r.rows),
// A signal for a pane that closed, its slot retaken in the same
// step, would reach another pane's child.
- .signal_pty => |s| if (if (p.panes[s.pane]) |pane| pane.serial != s.serial else true) {} else if (v.pty_signal) |f| f(p.host.ctx, s.pane, s.sig),
+ .signal_pty => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.pty_signal) |f| f(p.host.ctx, s.pane, s.sig),
.close_pty => |c| if (v.close_pty) |f| f(p.host.ctx, c.pane),
// The view's frontend opens it, yanks and pastes, on its own
// machine (View.yanks); the host here only for a view no client
@@ -149,17 +149,17 @@ fn performInner(p: *Pardes, e: Effect) void {
_ = words.next(); // its directory
const prog = words.next() orelse "";
var said: pardes.Kind.Buf(160) = .{};
- p.reportFailure(st.pane, said.print("plumb start: {s}: {s}", .{ prog[0..@min(64, prog.len)], w }));
+ p.reportFailure(st.pane.index(), said.print("plumb start: {s}: {s}", .{ prog[0..@min(64, prog.len)], w }));
},
.save_file => |sf| {
- const pane = p.panes[sf.pane] orelse return;
+ const pane = p.panes[sf.pane.index()] orelse return;
const f = if (pane.file) |*file| file else return;
const was = f.saved_revision;
f.saved_revision = f.revision;
// A save the host could not do (saveFailed) is its err
// record alone, not a `save`, and changes nothing: a clean
// file stays clean.
- const saved_pane = writeChecked(p, sf.pane, pane.serial, f.path, f.content, was) orelse return;
+ const saved_pane = writeChecked(p, sf.pane.index(), pane.serial, f.path, f.content, was) orelse return;
const saved = if (saved_pane.file) |*file| file else return;
// Edited while it was written: what is on disk is not this.
if (saved.saved_revision != saved.revision) return;
@@ -174,19 +174,19 @@ fn performInner(p: *Pardes, e: Effect) void {
p.emit(.{ .watch = .{ .pane = sf.pane, .on = true } });
},
.save_text => |st| {
- const pane = p.panes[st.pane] orelse return;
+ const pane = p.panes[st.pane.index()] orelse return;
if (pane.serial != st.serial) return; // a recycled slot: not ours
if (pane.file) |*f| {
// Failed, it changes nothing: not the name, not dirty.
- const after = writeChecked(p, st.pane, st.serial, st.path.slice(), f.content, f.saved_revision) orelse return;
+ const after = writeChecked(p, st.pane.index(), st.serial, st.path.slice(), f.content, f.saved_revision) orelse return;
if (after.file == null) return;
- if (st.promote) promoteSaved(p, st.pane, st.path.slice()) else ctlfs.events.noteLogAs(p, .save, after, st.path.slice());
+ if (st.promote) promoteSaved(p, st.pane.index(), st.path.slice()) else ctlfs.events.noteLogAs(p, .save, after, st.path.slice());
return;
}
if (!pane.isTerminal()) return;
const text = pardes.Term.scrollback(pane.terminal, p.gpa) catch |err| return p.reportError(st.pane, "Save", err);
defer p.gpa.free(text);
- if (writeChecked(p, st.pane, st.serial, st.path.slice(), text, 0)) |still|
+ if (writeChecked(p, st.pane.index(), st.serial, st.path.slice(), text, 0)) |still|
ctlfs.events.noteLogAs(p, .save, still, st.path.slice());
},
.write_dump => {
@@ -249,10 +249,10 @@ fn performInner(p: *Pardes, e: Effect) void {
},
.watch => |w| if (v.watch_file) |f| {
// What a watch is about: a real file, or a kind's (a PDF's).
- const path: []const u8 = if (p.panes[w.pane]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else if (pane.addon) |k| k.path else "") else "";
+ const path: []const u8 = if (p.panes[w.pane.index()]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else if (pane.addon) |k| k.path else "") else "";
f(p.host.ctx, w.pane, path, w.on, w.mode);
} else {
- p.fallback.watched[w.pane] = w.on;
+ p.fallback.watched[w.pane.index()] = w.on;
},
.theme_file => |t| if (v.watch_theme) |f| f(p.host.ctx, t.generation, t.on),
.dump_themes => |d| if (v.dump_themes) |f| f(p.host.ctx, d.pane),
@@ -263,8 +263,8 @@ fn performInner(p: *Pardes, e: Effect) void {
// dlopen is the same on every host, so none has a method of its
// own; a replica's core holds no library (what it brought comes in
// the event this taped).
- .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane, a.arg.slice()),
- .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane, j.serial, j.token),
+ .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane.index(), a.arg.slice()),
+ .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane.index(), j.serial, j.token),
// the loop's own condition; a host tears down after its own loop
.quit => p.endSession(),
}
@@ -282,7 +282,7 @@ pub fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: []
if (filesystem.localPath(path)) |local| filesystem.makeDirs(p.tape, std.Io.Dir.path.dirname(local) orelse "/");
// The in-process filesystem reports the same way a real host does,
// so an OOM there leaves the pane dirty rather than looking saved.
- if (p.host.vtable.write_file) |f| f(p.host.ctx, id, path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(id, path, error.OutOfMemory);
+ if (p.host.vtable.write_file) |f| f(p.host.ctx, .at(id), path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(.at(id), path, error.OutOfMemory);
const pane = p.panes[id] orelse return null;
if (pane.serial != serial) return null;
if (p.fs.failures == failures) return pane;
@@ -298,7 +298,7 @@ pub fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: []
fn promoteSaved(p: *Pardes, id: u8, path: []const u8) void {
const pane = p.panes[id] orelse return;
const f = if (pane.file) |*file| file else return;
- const owned = p.gpa.dupe(u8, path) catch |err| return p.reportError(id, "Save", err);
+ const owned = p.gpa.dupe(u8, path) catch |err| return p.reportError(.at(id), "Save", err);
p.gpa.free(f.path);
f.path = owned;
f.output = null;
@@ -312,7 +312,7 @@ fn promoteSaved(p: *Pardes, id: u8, path: []const u8) void {
ctlfs.events.noteLog(p, .save, pane);
p.recent.opened(p.recentGpa(), f.path);
if (filesystem.localPath(f.path) != null)
- p.emit(.{ .watch = .{ .pane = id, .on = true } });
+ p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
}
fn drainForSavePath(p: *Pardes, buf: []u8) ?[]const u8 {
@@ -343,7 +343,7 @@ test "Detach asks the host to let its terminal go, and says so when there is not
.detach => |d| break d,
else => {},
} else return error.NoDetachAsked;
- try std.testing.expectEqual(@as(u8, 0), asked.pane);
+ try std.testing.expectEqual(0, asked.pane.index());
p.perform(.{ .detach = asked });
const pane = p.panes[0].?;
@@ -358,7 +358,7 @@ test "Save on a scratch asks for a path in its inherited dir and makes it a file
while (p.nextEffect()) |_| {}
const source: usize = 2;
- p.setCwd(source, "/tmp/pardes-save-dir");
+ p.setCwd(.at(source), "/tmp/pardes-save-dir");
try std.testing.expect(p.executeBuiltinLine(source, "New"));
const id = p.view().active;
const np = p.panes[id].?;
@@ -376,7 +376,7 @@ test "Save on a scratch asks for a path in its inherited dir and makes it a file
// The write asked for, the pane is the file once it is done.
var saved = false;
while (p.nextEffect()) |effect| {
- if (effect == .save_text and @as(usize, effect.save_text.pane) == id) saved = true;
+ if (effect == .save_text and effect.save_text.pane.index() == id) saved = true;
p.perform(effect);
}
try std.testing.expect(saved);
@@ -391,8 +391,8 @@ test "Save on a terminal writes its plaintext scrollback and stays a terminal" {
defer p.deinit();
while (p.nextEffect()) |_| {}
const pane = p.panes[0].?;
- p.setCwd(0, "/tmp/pardes-tty-save");
- p.update(.{ .output = .{ .pane = 0, .bytes = "hello scrollback\r\n" } });
+ p.setCwd(.at(0), "/tmp/pardes-tty-save");
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "hello scrollback\r\n" } });
while (p.nextEffect()) |_| {}
try std.testing.expect(p.executeBuiltinLine(0, "Save"));
@@ -422,7 +422,7 @@ test "Save on an output buffer writes its rows out and leaves the buffer alone"
while (p.nextEffect()) |_| {}
const source: usize = 2;
- p.setCwd(source, "/tmp/pardes-output-save");
+ p.setCwd(.at(source), "/tmp/pardes-output-save");
try std.testing.expect(p.executeBuiltinLine(source, "Help"));
p.sync(); // the frame boundary that gives the new pane its geometry
while (p.nextEffect()) |_| {}
@@ -473,8 +473,8 @@ test "Save takes the path as an argument, relative to the pane's own directory"
defer p.deinit();
while (p.nextEffect()) |_| {}
const pane = p.panes[0].?;
- p.setCwd(0, "/tmp/pardes-arg-save");
- p.update(.{ .output = .{ .pane = 0, .bytes = "typed and gone\r\n" } });
+ p.setCwd(.at(0), "/tmp/pardes-arg-save");
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "typed and gone\r\n" } });
while (p.nextEffect()) |_| {}
var buf: [256]u8 = undefined;
@@ -510,9 +510,9 @@ test "Save takes the path as an argument, relative to the pane's own directory"
test "a save the host could not do leaves the pane dirty" {
const gpa = std.testing.allocator;
const Refusing = struct {
- fn writeFile(ctx: ?*anyopaque, pane: u8, _: []const u8, _: []const u8) void {
+ fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: []const u8) void {
const core: *Pardes = @ptrCast(@alignCast(ctx.?));
- core.saveFailed(pane, "/x/y.txt", error.PermissionDenied);
+ core.saveFailed(id, "/x/y.txt", error.PermissionDenied);
}
};
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 });
@@ -576,8 +576,8 @@ test "saves armed in one batch stay with their own panes" {
const tty_id = p.freeSlot() orelse return error.NoPaneSlots;
const shell = try p.newShell(tty_id, "/tmp/pardes-batch");
- p.setCwd(tty_id, "/tmp/pardes-batch");
- p.update(.{ .output = .{ .pane = @intCast(tty_id), .bytes = "shell text\r\n" } });
+ p.setCwd(.at(tty_id), "/tmp/pardes-batch");
+ p.update(.{ .output = .{ .pane = .at(tty_id), .bytes = "shell text\r\n" } });
const file = try p.setTestFile("file text\n");
const file_id = panes.paneIdOf(p, file) orelse return error.MissingFilePane;
try std.testing.expect(shell.isTerminal());
@@ -606,7 +606,7 @@ test "a save whose pane is gone before the drain writes nothing" {
const doomed = p.freeSlot() orelse return error.NoPaneSlots;
const shell = try p.newShell(doomed, "/tmp/pardes-gone");
- p.update(.{ .output = .{ .pane = @intCast(doomed), .bytes = "doomed text\r\n" } });
+ p.update(.{ .output = .{ .pane = .at(doomed), .bytes = "doomed text\r\n" } });
while (p.nextEffect()) |_| {}
try std.testing.expect(shell.isTerminal());
@@ -659,7 +659,7 @@ test "a save path that names no file is refused before anything is rewritten" {
while (p.nextEffect()) |_| {}
const source: usize = 2;
- p.setCwd(source, "/tmp/pardes-refuse");
+ p.setCwd(.at(source), "/tmp/pardes-refuse");
try std.testing.expect(p.executeBuiltinLine(source, "New"));
const id = p.view().active;
const scratch = p.panes[id].?;
@@ -687,19 +687,19 @@ test "a Save the host could not do logs no save record" {
const Failing = struct {
core: *Pardes,
const vtable: Host.VTable = .{ .write_file = write };
- fn write(ctx: ?*anyopaque, pane: u8, path: []const u8, _: []const u8) void {
+ fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, _: []const u8) void {
const f: *@This() = @ptrCast(@alignCast(ctx.?));
- f.core.saveFailed(pane, path, error.AccessDenied);
+ f.core.saveFailed(id, path, error.AccessDenied);
}
};
var host: Failing = .{ .core = p };
p.host = .{ .ctx = &host, .vtable = &Failing.vtable };
_ = th.wr(p, ctlfs.Node.of(p.panes[0].?.serial, .body), "more\n");
- p.perform(.{ .save_file = .{ .pane = 0 } });
+ p.perform(.{ .save_file = .{ .pane = .at(0) } });
try std.testing.expect(!th.logHas(p, "\nsave "));
try std.testing.expect(p.panes[0].?.file.?.saved_revision != p.panes[0].?.file.?.revision);
// With the host's write done, it is logged.
p.host = .{};
- p.perform(.{ .save_file = .{ .pane = 0 } });
+ p.perform(.{ .save_file = .{ .pane = .at(0) } });
try std.testing.expect(th.logHas(p, "\nsave "));
}