summaryrefslogtreecommitdiff
path: root/core/panes.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/panes.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/panes.zig')
-rw-r--r--core/panes.zig53
1 files changed, 34 insertions, 19 deletions
diff --git a/core/panes.zig b/core/panes.zig
index cdc28dba..b928917a 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -38,6 +38,21 @@ pub const Pane = struct {
// it there).
.alloc = .{ .{ "addon", "image" }, .{ "pdf", "image" }, .{ "terminal", "terminal" } },
};
+ /// A pane's slot in `Pardes.panes`, as it crosses the core's edge: an
+ /// entry's argument or answer, an event's, an effect's, a host call's.
+ /// A type of its own, so a view's slot (`View.Id`) is not taken for
+ /// it; the core's own loops and tables keep their integers.
+ pub const Id = enum(u8) {
+ _,
+ /// The id of slot `i`, a slot the core holds.
+ pub fn at(i: usize) Id {
+ return @fromBackingInt(@intCast(i));
+ }
+ /// The slot, to index the core's tables with.
+ pub fn index(id: Id) u8 {
+ return @backingInt(id);
+ }
+ };
/// The words that throw unsaved text away (builtins.zig warnModified).
pub const Discarding = enum { Exit, Restore, get, Del, Delcol };
@@ -701,7 +716,7 @@ pub const Pane = struct {
// A replica's emulator is what the authority's deltas make it; what
// pardes keeps over it moves as the authority's feed told it.
if (tape.screenReplica()) {
- if (has_positions and pane.followRows(state, bytes)) if (paneIdOf(p, pane)) |id| p.setMessage(id, positions_lost);
+ if (has_positions and pane.followRows(state, bytes)) if (paneIdOf(p, pane)) |id| p.setMessage(.at(id), positions_lost);
return;
}
// Sticky bottom, as every other terminal does it: output drags the
@@ -713,7 +728,7 @@ pub const Pane = struct {
Term.cellPixels(state, p.view().cell_pixels.w, p.view().cell_pixels.h);
if (!has_positions) {
_ = Term.feed(state, bytes, &.{}, &.{}, &.{});
- } else if (pane.followRows(state, bytes)) if (paneIdOf(p, pane)) |id| p.setMessage(id, positions_lost);
+ } else if (pane.followRows(state, bytes)) if (paneIdOf(p, pane)) |id| p.setMessage(.at(id), positions_lost);
p.shell_rows.markStale(pane);
if (pane.body.mode == .tty and at_bottom) pane.followOutput();
}
@@ -1063,7 +1078,7 @@ pub const Pane = struct {
// failure is worth the pane.
if (pane.command_pages) {
pane.command_pages = false;
- if (status == 0) return p.removePane(id, null) catch |err| p.reportError(id, "close", err);
+ if (status == 0) return p.removePane(id, null) catch |err| p.reportError(.at(id), "close", err);
}
var buf: [16]u8 = undefined;
const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit status fits 16
@@ -1177,8 +1192,8 @@ pub fn retirePane(p: *Pardes, pane: *Pane) void {
if (pane.file) |*file| panes.File.leaveTwins(p, file);
const watched = (if (pane.file) |f| f.output == null else false) or (if (pane.addon) |k| k.path.len > 0 else false);
for (p.panes, 0..) |slot, id| if (slot == pane) {
- if (watched) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } });
- if (pane.isTerminal()) p.emit(.{ .close_pty = .{ .pane = @intCast(id) } });
+ if (watched) p.emit(.{ .watch = .{ .pane = .at(id), .on = false } });
+ if (pane.isTerminal()) p.emit(.{ .close_pty = .{ .pane = .at(id) } });
// Its pty's end and its emulator are the authority's: a replica's
// speculation that closes a terminal waits for it.
if (pane.terminal != null) tape.poison("close a terminal");
@@ -1279,7 +1294,7 @@ pub fn emitSpawn(p: *Pardes, id: usize, serial: u32, cwd: []const u8) void {
if (p.spawn_dirs[id]) |old| p.gpa.free(old);
p.spawn_dirs[id] = null;
if (cwd.len > effect_path_cap) p.spawn_dirs[id] = p.gpa.dupe(u8, cwd) catch null;
- p.emit(.{ .spawn = .{ .pane = @intCast(id), .serial = serial, .cwd = .from(if (cwd.len > effect_path_cap) "" else cwd) } });
+ p.emit(.{ .spawn = .{ .pane = .at(id), .serial = serial, .cwd = .from(if (cwd.len > effect_path_cap) "" else cwd) } });
}
/// A command pane: a terminal whose child is `$SHELL -c line` rather
@@ -1335,8 +1350,8 @@ pub fn newScratchBelow(p: *Pardes, from_id: usize) void {
/// A scratch for New (`.scratch`) or 9P's pane/new (`.fs`).
pub fn newScratchFor(p: *Pardes, from_id: usize, kind: layout.NewPane) void {
- const free = p.freeSlot() orelse return p.reportError(from_id, "New", error.NoPaneSlots);
- _ = newScratch(p, from_id, free, kind) catch |err| return p.reportError(from_id, "New", err);
+ const free = p.freeSlot() orelse return p.reportError(.at(from_id), "New", error.NoPaneSlots);
+ _ = newScratch(p, from_id, free, kind) catch |err| return p.reportError(.at(from_id), "New", err);
layout.placeNew(p, from_id, from_id, free, kind);
}
@@ -1514,7 +1529,7 @@ pub fn startPrompt(p: *Pardes, pane: *Pane, t: *Text, request: union(enum) {
// directory for the name to be typed onto.
const dir = if (request == .save) paneDir(pane) else "";
const slash: []const u8 = if (request == .save and (dir.len == 0 or dir[dir.len - 1] != '/')) "/" else "";
- const answer = std.mem.concat(p.gpa, u8, &.{ marker, dir, slash }) catch |err| return p.reportError(p.view().active, "prompt", err);
+ const answer = std.mem.concat(p.gpa, u8, &.{ marker, dir, slash }) catch |err| return p.reportError(.at(p.view().active), "prompt", err);
// The keyboard comes back to the text answered for; a prompt for
// the body takes it out of a tag or header.
switch (t.what) {
@@ -1569,7 +1584,7 @@ test "owned cwd preserves long paths aliases and failed updates" {
var path: [3072]u8 = @splat('d');
path[0] = '/';
for (1..12) |i| path[i * 256] = '/';
- p.setCwd(0, &path);
+ p.setCwd(.at(0), &path);
try std.testing.expectEqualStrings(&path, pane.cwdSlice());
try std.testing.expect(pane.cwdSlice().ptr != &path);
const original = pane.cwdSlice();
@@ -1594,15 +1609,15 @@ test "owned cwd preserves long paths aliases and failed updates" {
const current = pane.cwdSlice();
allocator.fail_index = allocator.alloc_index;
- p.setCwd(0, "/replacement");
+ p.setCwd(.at(0), "/replacement");
try std.testing.expectEqual(current.ptr, pane.cwdSlice().ptr);
try std.testing.expectEqualStrings(&path, pane.cwdSlice());
try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "out of memory") != null);
allocator.fail_index = std.math.maxInt(usize);
- p.setCwd(0, "/replacement");
+ p.setCwd(.at(0), "/replacement");
try std.testing.expectEqualStrings("/replacement", pane.cwdSlice());
const allocations = allocator.allocations;
- p.setCwd(0, "/replacement");
+ p.setCwd(.at(0), "/replacement");
try std.testing.expectEqual(allocations, allocator.allocations);
pane.clearCwd();
try std.testing.expect(pane.cwd == .none);
@@ -1663,8 +1678,8 @@ test "owned cwd column close allocates every copy before removing any pane" {
var allocator = std.testing.FailingAllocator.init(std.testing.allocator, .{});
const p = try Pardes.init(allocator.allocator(), .{ .shells = 3, .cols = 100, .rows = 30 });
defer p.deinit();
- p.setCwd(0, "/first");
- p.setCwd(1, "/second");
+ p.setCwd(.at(0), "/first");
+ p.setCwd(.at(1), "/second");
const first_child = try p.newDocPane(3);
const second_child = try p.newDocPane(4);
first_child.cwd = .{ .inherited = p.panes[0].? };
@@ -1691,14 +1706,14 @@ test "owned cwd EOF failure retains the pane and Del retries its close" {
var allocator = std.testing.FailingAllocator.init(std.testing.allocator, .{});
const p = try Pardes.init(allocator.allocator(), .{ .tty_only = true });
defer p.deinit();
- p.setCwd(0, "/exited");
+ p.setCwd(.at(0), "/exited");
const parent = p.panes[0].?;
p.newScratchBelow(0);
const child = p.panes[p.view().active].?;
p.sync();
while (p.nextEffect()) |_| {}
allocator.fail_index = allocator.alloc_index;
- p.update(.{ .eof = .{ .pane = 0 } });
+ p.update(.{ .eof = .{ .pane = .at(0) } });
try std.testing.expectEqual(parent, p.panes[0].?);
try std.testing.expectEqual(parent, child.cwd.inherited);
try std.testing.expectEqual(Text.Mode.normal, parent.body.mode);
@@ -1785,7 +1800,7 @@ test "New opens an empty scratch below the caller, inheriting its directory" {
while (p.nextEffect()) |_| {}
const source: usize = 2; // the right column; active starts in the left
- p.setCwd(source, "/tmp/pardes-scratch-dir");
+ p.setCwd(.at(source), "/tmp/pardes-scratch-dir");
const source_col = layout.findPane(p, source).?.col;
try std.testing.expect(p.executeBuiltinLine(source, "New"));
@@ -1799,7 +1814,7 @@ test "New opens an empty scratch below the caller, inheriting its directory" {
try std.testing.expectEqual(@as(usize, 0), np.file.?.content.len);
// its directory is a LIVE link to the opener, not a snapshot taken at New
try std.testing.expectEqualStrings("/tmp/pardes-scratch-dir", Pardes.paneDir(np));
- p.setCwd(source, "/tmp/pardes-moved");
+ p.setCwd(.at(source), "/tmp/pardes-moved");
try std.testing.expectEqualStrings("/tmp/pardes-moved", Pardes.paneDir(np));
try p.removePane(source, null);
p.sync();