summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/Host.zig28
-rw-r--r--dev/Inbox.zig28
-rw-r--r--dev/KindJob.zig2
-rw-r--r--dev/Lsp.zig22
-rw-r--r--dev/file_watch.zig22
-rw-r--r--dev/gui/gui.zig138
-rw-r--r--dev/host_io.zig68
-rw-r--r--dev/tui/tui.zig86
8 files changed, 211 insertions, 183 deletions
diff --git a/dev/Host.zig b/dev/Host.zig
index 1834e52e..24df3895 100644
--- a/dev/Host.zig
+++ b/dev/Host.zig
@@ -24,30 +24,30 @@ pub const VTable = struct {
/// for the daemon to attach again (daemon.zig).
detach: ?*const fn (ctx: ?*anyopaque) void = null,
/// Adopt: the shells a dead session left, asked of the daemon.
- adopt: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null,
+ adopt: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null,
/// Upgrade: this process exec'd as the pardes installed since, at
/// the step's end (upgrade.zig); `pane` hears why if it cannot be.
- upgrade: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null,
+ upgrade: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null,
/// Whether a newer pardes is installed at the path this process
/// started from, to be said once (upgrade.zig): asked at a focus-in.
newer_build: ?*const fn (ctx: ?*anyopaque) bool = null,
- spawn: ?*const fn (ctx: ?*anyopaque, pane: u8, cwd: []const u8) void = null,
- pty_write: ?*const fn (ctx: ?*anyopaque, pane: u8, bytes: []const u8) void = null,
- pty_resize: ?*const fn (ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void = null,
- pty_signal: ?*const fn (ctx: ?*anyopaque, pane: u8, sig: pardes.PtySignal) void = null,
- close_pty: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null,
- tty_taken: ?*const fn (ctx: ?*anyopaque, pane: u8) bool = null,
+ spawn: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, cwd: []const u8) void = null,
+ pty_write: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, bytes: []const u8) void = null,
+ pty_resize: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, cols: u16, rows: u16) void = null,
+ pty_signal: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, sig: pardes.PtySignal) void = null,
+ close_pty: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null,
+ tty_taken: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) bool = null,
/// The name of the program holding the tty, when it is not the
/// shell (host_io.foregroundName), in `buf`.
- fg_name: ?*const fn (ctx: ?*anyopaque, pane: u8, buf: []u8) ?[]const u8 = null,
+ fg_name: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, buf: []u8) ?[]const u8 = null,
/// Answered at once, not queued as an effect: Kill asks while the
/// job it saw running is still the one in the tty (host_io.killJob).
- kill_job: ?*const fn (ctx: ?*anyopaque, pane: u8) bool = null,
- write_file: ?*const fn (ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void = null,
+ kill_job: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) bool = null,
+ write_file: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, path: []const u8, bytes: []const u8) void = null,
write_dump: ?*const fn (ctx: ?*anyopaque, bytes: []const u8) void = null,
- watch_file: ?*const fn (ctx: ?*anyopaque, pane: u8, path: []const u8, on: bool, mode: pardes.WatchMode) void = null,
+ watch_file: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, path: []const u8, on: bool, mode: pardes.WatchMode) void = null,
watch_theme: ?*const fn (ctx: ?*anyopaque, generation: u32, on: bool) void = null,
- dump_themes: ?*const fn (ctx: ?*anyopaque, pane: u8) void = null,
+ dump_themes: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id) void = null,
set_clipboard: ?*const fn (ctx: ?*anyopaque, text: []const u8) void = null,
read_clipboard: ?*const fn (ctx: ?*anyopaque) void = null,
open_link: ?*const fn (ctx: ?*anyopaque, url: []const u8) void = null,
@@ -65,5 +65,5 @@ pub const VTable = struct {
/// Run job `token` of the pane in slot `pane` (whose serial is
/// `serial`) on a worker (`KindJob`), answering with the `job` event;
/// absent, it runs on the loop.
- job: ?*const fn (ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void = null,
+ job: ?*const fn (ctx: ?*anyopaque, pane: pardes.Pane.Id, serial: u32, token: u32) void = null,
};
diff --git a/dev/Inbox.zig b/dev/Inbox.zig
index d8b14221..ed3a9835 100644
--- a/dev/Inbox.zig
+++ b/dev/Inbox.zig
@@ -8,8 +8,8 @@ const Lsp = host_io.Lsp;
const Inbox = @This();
pub const Msg = union(enum) {
- output: struct { pane: u8, gen: u32, bytes: []u8 },
- eof: struct { pane: u8, gen: u32, failure: ?anyerror = null },
+ output: struct { pane: pardes.Pane.Id, gen: u32, bytes: []u8 },
+ eof: struct { pane: pardes.Pane.Id, gen: u32, failure: ?anyerror = null },
lsp: struct { id: u32, rows: ?[]u8 },
lsp_status: []u8,
pipe: selection_pipe.Response,
@@ -96,18 +96,18 @@ pub fn wake(q: *Inbox) void {
if (q.wake_fn) |f| f(q.wake_ctx);
}
-pub fn acceptReader(q: *Inbox, pane: u8, gen: u32) void {
+pub fn acceptReader(q: *Inbox, pane: pardes.Pane.Id, gen: u32) void {
q.lock();
defer q.unlock();
- std.debug.assert(q.readers[pane] == null);
- q.readers[pane] = gen;
+ std.debug.assert(q.readers[pane.index()] == null);
+ q.readers[pane.index()] = gen;
}
-pub fn cancelReader(q: *Inbox, pane: u8, gen: u32) void {
+pub fn cancelReader(q: *Inbox, pane: pardes.Pane.Id, gen: u32) void {
q.lock();
defer q.unlock();
- if (q.readers[pane] != gen) return;
- q.readers[pane] = null;
+ if (q.readers[pane.index()] != gen) return;
+ q.readers[pane.index()] = null;
var i: usize = 0;
while (i < q.len) {
const msg = q.items[(q.head + i) % q.items.len];
@@ -121,14 +121,14 @@ pub fn cancelReader(q: *Inbox, pane: u8, gen: u32) void {
q.space.broadcast(q.io);
}
-pub fn pushOutput(q: *Inbox, pane: u8, gen: u32, bytes: []u8) bool {
+pub fn pushOutput(q: *Inbox, pane: pardes.Pane.Id, gen: u32, bytes: []u8) bool {
q.lock();
- while (!q.closed and q.readers[pane] == gen and q.len >= output_capacity) {
+ while (!q.closed and q.readers[pane.index()] == gen and q.len >= output_capacity) {
q.waiting += 1;
q.space.waitUncancelable(q.io, &q.mutex);
q.waiting -= 1;
}
- if (q.closed or q.readers[pane] != gen) {
+ if (q.closed or q.readers[pane.index()] != gen) {
q.unlock();
q.gpa.free(bytes);
return false;
@@ -186,7 +186,7 @@ pub fn push(q: *Inbox, m: Msg) void {
},
else => {
if (m == .eof) {
- if (q.readers[m.eof.pane] != m.eof.gen) {
+ if (q.readers[m.eof.pane.index()] != m.eof.gen) {
q.unlock();
return;
}
@@ -270,13 +270,13 @@ pub fn deinit(q: *Inbox) void {
/// A pane's reader: its pty's output pushed as it comes, then its end
/// of file; canceled (closePty), it pushes nothing more.
-pub fn startReader(q: *Inbox, pty: std.Io.File, pane: u8, gen: u32) !std.Io.Future(void) {
+pub fn startReader(q: *Inbox, pty: std.Io.File, pane: pardes.Pane.Id, gen: u32) !std.Io.Future(void) {
q.acceptReader(pane, gen);
errdefer q.cancelReader(pane, gen);
return q.io.concurrent(readPty, .{ q, pty, pane, gen });
}
-fn readPty(q: *Inbox, pty: std.Io.File, pane: u8, gen: u32) void {
+fn readPty(q: *Inbox, pty: std.Io.File, pane: pardes.Pane.Id, gen: u32) void {
var buf: [0x10000]u8 = undefined;
var failure: ?anyerror = null;
while (true) {
diff --git a/dev/KindJob.zig b/dev/KindJob.zig
index c24ad88d..e9cea5b4 100644
--- a/dev/KindJob.zig
+++ b/dev/KindJob.zig
@@ -48,7 +48,7 @@ pub fn run(j: *KindJob) void {
/// Its answer to the core, and it gone.
pub fn land(j: *KindJob, p: *pardes.Pardes) void {
if (j.draw != null) return pardes.Kind.landDraw(p, j);
- p.update(.{ .job = .{ .pane = j.pane, .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } });
+ p.update(.{ .job = .{ .pane = .at(j.pane), .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } });
j.drop();
}
diff --git a/dev/Lsp.zig b/dev/Lsp.zig
index edc99eeb..4b8bfa03 100644
--- a/dev/Lsp.zig
+++ b/dev/Lsp.zig
@@ -5,7 +5,7 @@ const filesystem = @import("core").filesystem;
pub const Request = struct {
id: u32,
kind: pardes.lsp.Kind,
- pane: u8,
+ pane: pardes.Pane.Id,
offset: u32,
arg: []const u8,
};
@@ -45,8 +45,8 @@ pub const Job = struct {
// Copy before starting a worker; the editor may replace any source slice afterward.
pub fn snapshot(gpa: std.mem.Allocator, core: *const pardes.Pardes, req: Request) !*Job {
- if (req.pane >= core.panes.len) return error.NoPane;
- const pane = core.panes[req.pane] orelse return error.NoPane;
+ if (req.pane.index() >= core.panes.len) return error.NoPane;
+ const pane = core.panes[req.pane.index()] orelse return error.NoPane;
const file = pane.file;
const job = try gpa.create(Job);
errdefer gpa.destroy(job);
@@ -87,7 +87,7 @@ pub fn snapshot(gpa: std.mem.Allocator, core: *const pardes.Pardes, req: Request
var copied: usize = 0;
for (core.panes, 0..) |slot, i| {
const other = slot orelse continue;
- if (i == req.pane) continue;
+ if (i == req.pane.index()) continue;
const f = other.file orelse continue;
if (f.output != null) continue;
if (copied + f.content.len > pardes.memory.limits.lsp_snapshot_bytes) continue;
@@ -173,7 +173,7 @@ test "a snapshot owns every byte the backend will read" {
const job = try snapshot(gpa, core, .{
.id = 7,
.kind = .status,
- .pane = @intCast(core.view().active),
+ .pane = .at(core.view().active),
.offset = 0,
.arg = &needle,
});
@@ -202,7 +202,7 @@ test "LSP snapshot frees every partially copied field on allocation failure" {
const job = try snapshot(gpa, p, .{
.id = 7,
.kind = .hover,
- .pane = @intCast(p.view().active),
+ .pane = .at(p.view().active),
.offset = 6,
.arg = "query",
});
@@ -226,7 +226,7 @@ test "LSP snapshots translate explicit OS paths once and retain virtual names" {
const replacement = try gpa.dupe(u8, case.path);
gpa.free(pane.file.?.path);
pane.file.?.path = replacement;
- const job = try snapshot(gpa, core, .{ .id = 1, .kind = .hover, .pane = @intCast(core.view().active), .offset = 0, .arg = "" });
+ const job = try snapshot(gpa, core, .{ .id = 1, .kind = .hover, .pane = .at(core.view().active), .offset = 0, .arg = "" });
defer job.free(gpa);
try std.testing.expectEqualStrings(case.native, job.path);
try std.testing.expectEqualStrings(std.Io.Dir.path.dirname(case.native).?, job.root);
@@ -247,7 +247,7 @@ test "a pane that is gone yields no job rather than a null deref" {
try std.testing.expectError(error.NoPane, snapshot(gpa, core, .{
.id = 1,
.kind = .definition,
- .pane = empty,
+ .pane = .at(empty),
.offset = 0,
.arg = "",
}));
@@ -272,7 +272,7 @@ test "work consumes the job and hands its rows to the sink" {
const job = try snapshot(gpa, core, .{
.id = 42,
.kind = .status,
- .pane = @intCast(core.view().active),
+ .pane = .at(core.view().active),
.offset = 0,
.arg = "",
});
@@ -320,7 +320,7 @@ test "LSP edit query failure leaves text and undo untouched before a successful
const job = try snapshot(failing.allocator(), core, .{
.id = core.lsp_ask.wait.?.id,
.kind = kind,
- .pane = @intCast(core.view().active),
+ .pane = .at(core.view().active),
.offset = 6,
.arg = "renamed",
});
@@ -389,7 +389,7 @@ test "LSP work delivers failure when transferring result ownership cannot alloca
} };
const core = try pardes.Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer core.deinit();
- const job = try snapshot(gpa, core, .{ .id = 37, .kind = .status, .pane = @intCast(core.view().active), .offset = 0, .arg = "" });
+ const job = try snapshot(gpa, core, .{ .id = 37, .kind = .status, .pane = .at(core.view().active), .offset = 0, .arg = "" });
var sink: Sink = .{};
work(std.testing.io, gpa, job, &sink, Sink.take);
if (sink.rows) |rows| gpa.free(rows);
diff --git a/dev/file_watch.zig b/dev/file_watch.zig
index 9d868e07..84f37c81 100644
--- a/dev/file_watch.zig
+++ b/dev/file_watch.zig
@@ -459,7 +459,7 @@ pub fn reloadPane(
if (pane.file) |file| {
const bytes = filesystem.read(core, file.path) catch |err| {
// Gone from under the pane: said once, the text kept.
- if (err == error.FileNotFound and watched.existed == std.hash.Wyhash.hash(0, file.path)) pardes.panes.File.deleted(core, @intCast(id));
+ if (err == error.FileNotFound and watched.existed == std.hash.Wyhash.hash(0, file.path)) pardes.panes.File.deleted(core, .at(id));
return false;
};
if (watches[id]) |*live| live.existed = std.hash.Wyhash.hash(0, file.path);
@@ -477,7 +477,7 @@ pub fn reloadPane(
};
return false;
}
- if (!core.reloadWatchedFile(@intCast(id), bytes)) return false;
+ if (!core.reloadWatchedFile(.at(id), bytes)) return false;
const current = core.panes[id] orelse return false;
if (current.serial != watched.serial) return false;
const current_file = current.file orelse return false;
@@ -488,7 +488,7 @@ pub fn reloadPane(
}
if (announce) {
var msg_buf: [256]u8 = undefined;
- core.setMessage(id, message.stamp(&msg_buf, "reloaded", current_file.path));
+ core.setMessage(.at(id), message.stamp(&msg_buf, "reloaded", current_file.path));
}
return false;
}
@@ -510,7 +510,7 @@ pub fn reloadPane(
.text => {},
}
// Its kind reads the file again (Kind.fileChanged): on the tape, no bytes.
- if (!core.reloadWatchedFile(@intCast(id), &.{})) return false;
+ if (!core.reloadWatchedFile(.at(id), &.{})) return false;
const current = core.panes[id] orelse return false;
if (current.serial != watched.serial) return false;
const current_path = kindPath(current) orelse return false;
@@ -522,7 +522,7 @@ pub fn reloadPane(
}
if (announce) {
var msg_buf: [256]u8 = undefined;
- core.setMessage(id, message.stamp(&msg_buf, "reloaded", current_path));
+ core.setMessage(.at(id), message.stamp(&msg_buf, "reloaded", current_path));
}
return false;
}
@@ -611,12 +611,12 @@ pub fn applyThemeEffect(
const pane = request.pane;
const bytes = filesystem.readFile(&pardes.tape.none, gpa, request.path) catch |err| {
colors.failThemeFile(core, generation, err);
- core.noteLateFailure(pane);
+ core.noteLateFailure(.at(pane));
return false;
};
defer gpa.free(bytes);
if (!colors.loadThemeFile(core, generation, bytes)) {
- core.noteLateFailure(pane);
+ core.noteLateFailure(.at(pane));
return false;
}
const hash = std.hash.Wyhash.hash(0, bytes);
@@ -659,7 +659,7 @@ pub fn reloadTheme(
live.generation = .{ .text = hash };
if (announce) {
var msg_buf: [256]u8 = undefined;
- core.setMessage(request.pane, message.stamp(&msg_buf, "reloaded theme", request.path));
+ core.setMessage(.at(request.pane), message.stamp(&msg_buf, "reloaded theme", request.path));
}
return false;
}
@@ -706,7 +706,7 @@ test "a restored file is watched again: one clean takes what its file became sin
defer watchPane(fd, &watches, id, null, pane.serial, .{ .text = 0 });
var armed = false;
while (core.nextEffect()) |effect| switch (effect) {
- .watch => |watch| if (watch.pane == id and watch.on) {
+ .watch => |watch| if (watch.pane.index() == id and watch.on) {
_ = applyEffect(core, io, fd, &watches, id, watch.on, watch.mode);
armed = true;
},
@@ -774,7 +774,7 @@ test "ordinary file watches still reconcile changes between open and watch" {
defer watchPane(fd, &watches, id, null, pane.serial, .{ .text = 0 });
var armed = false;
while (core.nextEffect()) |effect| switch (effect) {
- .watch => |watch| if (watch.pane == id and watch.on) {
+ .watch => |watch| if (watch.pane.index() == id and watch.on) {
try std.testing.expectEqual(.reconcile, watch.mode);
try std.testing.expect(!applyEffect(core, io, fd, &watches, id, watch.on, watch.mode));
armed = true;
@@ -949,7 +949,7 @@ test "a watched file deleted wakes the watch at once, and its pane says so" {
var watches: Table = @splat(null);
defer watchPane(fd, &watches, id, null, pane.serial, .{ .text = 0 });
while (core.nextEffect()) |effect| switch (effect) {
- .watch => |watch| if (watch.pane == id and watch.on) {
+ .watch => |watch| if (watch.pane.index() == id and watch.on) {
_ = applyEffect(core, io, fd, &watches, id, watch.on, watch.mode);
},
else => {},
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index 798368e3..c147c2e2 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -1130,7 +1130,7 @@ const Own = struct {
pub fn start(o: *Own, l: *Session) !void {
for (&o.ptys, 0..) |*slot, id| if (slot.*) |*pt| {
- pt.reader = try o.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, @intCast(id), o.gens[id]);
+ pt.reader = try o.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, .at(id), o.gens[id]);
};
if (o.inotify_fd >= 0) {
o.watch_stop = try stopPipe();
@@ -2485,7 +2485,8 @@ const Shell = struct {
took_input: bool = false,
held: ?c.SDL_Event = null,
- fn closePaneShell(ctx: ?*anyopaque, pane: u8) void {
+ fn closePaneShell(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
shellOf(ctx).closePty(pane);
}
@@ -2493,7 +2494,7 @@ const Shell = struct {
const pt = if (s.ptys[pane]) |*pt| pt else return;
// Out of the queue first, which lets go a reader waiting for room
// in it; then its read is canceled (or, at its end, it is joined).
- s.queue.cancelReader(pane, s.gens[pane]);
+ s.queue.cancelReader(.at(pane), s.gens[pane]);
if (pt.reader) |*reader| {
reader.cancel(s.queue.io); // the Io it was started on (startReader)
pt.reader = null;
@@ -2548,7 +2549,7 @@ const Shell = struct {
/// last. True when it was not, and is now.
fn windowView(s: *Shell) bool {
if (s.core.live == s.gview or !pardes.views.isOpen(s.core, s.gview)) return false;
- s.core.toView(s.gview);
+ s.core.toView(.at(s.gview));
return true;
}
@@ -2603,12 +2604,14 @@ const Shell = struct {
return shellOf(ctx).gui != null;
}
- fn adopt(ctx: ?*anyopaque, pane: u8) void {
+ fn adopt(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = shellOf(ctx);
s.adoptions.ask(s.core, pane);
}
- fn upgradeAsked(ctx: ?*anyopaque, pane: u8) void {
+ fn upgradeAsked(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = shellOf(ctx);
if (comptime !upgrade.supported) return s.core.reportFailure(pane, "Upgrade: this system cannot move a session to another build in place");
s.upgrade_asked = pane;
@@ -2656,7 +2659,7 @@ const Shell = struct {
const failed = upgrade.dumpInto(core, &rec, &at_buf, &why) orelse upgrade.execAs(s.gpa, path, &rec, &at_buf, s.fs, &why);
// As it was: its ptys read on.
for (s.ptys, 0..) |*slot, id| if (slot.*) |*pt| if (pt.fd >= 0 and pt.reader == null) {
- pt.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, @intCast(id), s.gens[id]) catch null;
+ pt.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, .at(id), s.gens[id]) catch null;
};
core.reportFailure(pane, failed);
}
@@ -2680,7 +2683,7 @@ const Shell = struct {
s.gview = s.core.live;
for (0..pardes.views.max) |i| {
const k: u8 = @intCast(i);
- if (k != s.gview and pardes.views.isOpen(s.core, k) and !pardes.views.isAway(s.core, k)) s.core.closeView(k);
+ if (k != s.gview and pardes.views.isOpen(s.core, k) and !pardes.views.isAway(s.core, k)) s.core.closeView(.at(k));
}
}
@@ -2751,18 +2754,18 @@ const Shell = struct {
var check_files = false;
for (msgs.slice()) |m| switch (m) {
.output => |o| {
- if (s.gens[o.pane] == o.gen)
+ if (s.gens[o.pane.index()] == o.gen)
s.core.update(.{ .output = .{ .pane = o.pane, .bytes = o.bytes } });
s.gpa.free(o.bytes);
},
.eof => |e| {
- if (s.gens[e.pane] == e.gen) eof: {
+ if (s.gens[e.pane.index()] == e.gen) eof: {
if (e.failure) |err| {
- s.closePty(e.pane);
+ s.closePty(e.pane.index());
s.core.readerFailed(e.pane, err);
break :eof;
}
- const pt = if (s.ptys[e.pane]) |*pt| pt else {
+ const pt = if (s.ptys[e.pane.index()]) |*pt| pt else {
s.core.update(.{ .eof = .{ .pane = e.pane } });
break :eof;
};
@@ -2770,15 +2773,15 @@ const Shell = struct {
// closing it would hang up one that runs on without it.
// Its exit, if it came first, is told now its output is in.
if (pt.cmd.watched) {
- host_io.commandEof(s.core, s.ptys, e.pane, s, closeWatched);
+ host_io.commandEof(s.core, s.ptys, e.pane.index(), s, closeWatched);
break :eof;
}
// Unwatched, a command's exit is read here, as its end,
// and a shell's, for a run waiting on it and the log.
- const unwatched = if (s.core.panes[e.pane]) |pane| pane.command != null else false;
+ const unwatched = if (s.core.panes[e.pane.index()]) |pane| pane.command != null else false;
const status = host_io.exitStatus(pt.pid, 100);
if (status != null) pt.pid = 0; // reaped: no shell to retire
- s.closePty(e.pane);
+ s.closePty(e.pane.index());
if (unwatched or status != null) s.core.update(.{ .exited = .{ .pane = e.pane, .status = status } });
s.core.update(.{ .eof = .{ .pane = e.pane } });
}
@@ -2789,7 +2792,7 @@ const Shell = struct {
},
.lsp_status => |text| {
var mbuf: [256]u8 = undefined;
- s.core.setStatus(s.core.view().active, message.stamp(&mbuf, "lsp", text));
+ s.core.setStatus(.at(s.core.view().active), message.stamp(&mbuf, "lsp", text));
s.lsp_allocator.free(text);
},
.pipe => |response_value| {
@@ -3327,32 +3330,33 @@ fn guiNow(ctx: ?*anyopaque) u64 {
return s.test_clock orelse s.paced_ns orelse c.SDL_GetTicksNS();
}
-fn spawnPane(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void {
+fn spawnPane(ctx: ?*anyopaque, id: pardes.Pane.Id, cwd: []const u8) void {
+ const pane = id.index();
const s = shellOf(ctx);
- if (s.adoptions.take(pane)) |a| return takeShell(s, pane, a);
+ if (s.adoptions.take(id)) |a| return takeShell(s, pane, a);
// The new shell starts before a running one goes: one that cannot
// start leaves the running one be (pty/ctl's exec).
const running = s.ptys[pane] != null;
const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.view().screen_h, s.core.view().screen_w) catch |err| {
- if (running) return s.core.restartFailed(pane, err);
- return s.core.shellFailed(pane, err);
+ if (running) return s.core.restartFailed(id, err);
+ return s.core.shellFailed(id, err);
};
s.closePty(pane);
if (s.ptys[pane] != null) {
_ = libc.close(child.file.handle);
host_io.retireShell(child.pid);
- return s.core.reportError(pane, "shell", error.WorkersBusy);
+ return s.core.reportError(id, "shell", error.WorkersBusy);
}
s.gens[pane] +%= 1;
const command = s.core.panes[pane].?.command != null;
const pt: Pty = .{ .fd = child.file.handle, .pid = child.pid, .serial = s.core.panes[pane].?.serial, .cmd = .{ .watched = command and host_io.watchExit(child.pid), .fd = child.file.handle } };
s.ptys[pane] = pt;
var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- if (host_io.shellCwd(pt.pid, &lbuf)) |wd| s.core.setCwd(pane, wd);
+ if (host_io.shellCwd(pt.pid, &lbuf)) |wd| s.core.setCwd(id, wd);
if (!s.threads_ok) return;
- s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, pane, s.gens[pane]) catch |err| {
+ s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = pt.fd, .flags = .{ .nonblocking = false } }, id, s.gens[pane]) catch |err| {
s.closePty(pane);
- return s.core.reportError(pane, "terminal reader", err);
+ return s.core.reportError(id, "terminal reader", err);
};
}
@@ -3363,16 +3367,16 @@ fn takeShell(s: *Shell, pane: u8, a: host_io.Adoption) void {
s.gens[pane] +%= 1;
s.ptys[pane] = .{ .fd = a.fd, .pid = a.pid, .serial = s.core.panes[pane].?.serial, .cmd = .{} };
var exe_buf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- s.core.acknowledgeShell(pane, host_io.processExe(a.pid, &exe_buf) orelse "sh", host_io.marksPrompts(a.pid));
+ s.core.acknowledgeShell(.at(pane), host_io.processExe(a.pid, &exe_buf) orelse "sh", host_io.marksPrompts(a.pid));
var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(pane, wd);
+ if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd);
const tiny: posix.winsize = .{ .row = 1, .col = 1, .xpixel = 0, .ypixel = 0 };
_ = posix.system.ioctl(a.fd, TIOCSWINSZ, @intFromPtr(&tiny));
- if (s.core.panes[pane]) |pn| ptyResize(s, pane, @max(pn.cols, 1), @max(pn.rows, 1));
+ if (s.core.panes[pane]) |pn| ptyResize(s, .at(pane), @max(pn.cols, 1), @max(pn.rows, 1));
if (!s.threads_ok) return;
- s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = a.fd, .flags = .{ .nonblocking = false } }, pane, s.gens[pane]) catch |err| {
+ s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = a.fd, .flags = .{ .nonblocking = false } }, .at(pane), s.gens[pane]) catch |err| {
s.closePty(pane);
- return s.core.reportError(pane, "terminal reader", err);
+ return s.core.reportError(.at(pane), "terminal reader", err);
};
}
@@ -3397,12 +3401,14 @@ fn deliverNote(ctx: *anyopaque, note: daemon.Note) void {
}
}
-fn ptyWrite(ctx: ?*anyopaque, pane: u8, bytes: []const u8) void {
+fn ptyWrite(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void {
+ const pane = id.index();
const s = shellOf(ctx);
if (s.ptys[pane]) |pt| _ = host_io.writeFd(pt.fd, bytes);
}
-fn ptyResize(ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void {
+fn ptyResize(ctx: ?*anyopaque, id: pardes.Pane.Id, cols: u16, rows: u16) void {
+ const pane = id.index();
const s = shellOf(ctx);
if (s.ptys[pane]) |pt| {
const ws = host_io.ptyWinsize(s.core, cols, rows);
@@ -3410,31 +3416,36 @@ fn ptyResize(ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void {
}
}
-fn ptySignal(ctx: ?*anyopaque, pane: u8, sig: pardes.PtySignal) void {
+fn ptySignal(ctx: ?*anyopaque, id: pardes.Pane.Id, sig: pardes.PtySignal) void {
+ const pane = id.index();
const s = shellOf(ctx);
// A command whose exit is recorded is reaped: its group may be another's.
if (s.ptys[pane]) |pt| if (!pt.cmd.exited) host_io.signalTty(pt.pid, pt.fd, sig, pt.cmd.watched);
}
-fn ttyTaken(ctx: ?*anyopaque, pane: u8) bool {
+fn ttyTaken(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
+ const pane = id.index();
const s = shellOf(ctx);
const pt = s.ptys[pane] orelse return false;
return host_io.ttyTaken(pt.pid, pt.fd);
}
-fn fgName(ctx: ?*anyopaque, pane: u8, buf: []u8) ?[]const u8 {
+fn fgName(ctx: ?*anyopaque, id: pardes.Pane.Id, buf: []u8) ?[]const u8 {
+ const pane = id.index();
const s = shellOf(ctx);
const pt = s.ptys[pane] orelse return null;
return host_io.foregroundName(pt.pid, pt.fd, buf);
}
-fn killJob(ctx: ?*anyopaque, pane: u8) bool {
+fn killJob(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
+ const pane = id.index();
const s = shellOf(ctx);
const pt = s.ptys[pane] orelse return false;
return host_io.killJob(pt.pid, pt.fd);
}
-fn writeFile(ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void {
+fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, bytes: []const u8) void {
+ const pane = id.index();
const s = shellOf(ctx);
host_io.writeFile(s.core, s.watches, pane, path, bytes);
}
@@ -3443,7 +3454,8 @@ fn writeDump(ctx: ?*anyopaque, bytes: []const u8) void {
host_io.writeDump(shellOf(ctx).core, bytes);
}
-fn watchFile(ctx: ?*anyopaque, pane: u8, _: []const u8, on: bool, mode: pardes.WatchMode) void {
+fn watchFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, on: bool, mode: pardes.WatchMode) void {
+ const pane = id.index();
const s = shellOf(ctx);
if (file_watch.applyEffect(s.core, s.io, s.inotify_fd, s.watches, pane, on, mode))
s.queue.push(.files_changed);
@@ -3461,7 +3473,8 @@ fn watchTheme(ctx: ?*anyopaque, generation: u32, on: bool) void {
)) s.queue.push(.files_changed);
}
-fn dumpThemes(ctx: ?*anyopaque, pane: u8) void {
+fn dumpThemes(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = shellOf(ctx);
host_io.dumpThemes(s.core, s.io, s.gpa, pane);
}
@@ -3508,7 +3521,7 @@ fn pipe(ctx: ?*anyopaque, id: u32) void {
const s = shellOf(ctx);
if (s.threads_ok) return selection_pipe.start(s.io, s.gpa, s.core, s.pipe_tasks, id, s.queue, Queue.pushPipe);
s.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } });
- s.core.reportError(s.core.view().active, "pipe", error.WorkersUnavailable);
+ s.core.reportError(.at(s.core.view().active), "pipe", error.WorkersUnavailable);
}
/// A draw (api.draw) on a worker, as a job is.
@@ -3517,7 +3530,8 @@ fn kindDraw(ctx: ?*anyopaque, j: *host_io.KindJob) bool {
return (s.threads_ok or s.client != null) and host_io.KindJob.go(s.io, &s.job_tasks, j, s.queue, Queue.pushJob);
}
-fn kindJob(ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void {
+fn kindJob(ctx: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void {
+ const pane = id.index();
const s = shellOf(ctx);
if (s.threads_ok) return host_io.KindJob.start(s.io, s.core, &s.job_tasks, pane, serial, token, s.queue, Queue.pushJob);
host_io.KindJob.runHere(s.core, pane, serial, token);
@@ -3579,7 +3593,7 @@ fn handOver(ctx: ?*anyopaque, seq: u32, bytes: []const u8) void {
fn pollCwds(core: *pardes.Pardes, ptys: *[pardes.MAX_PANES]?Pty) void {
for (ptys, 0..) |slot, id| if (slot) |pt| {
var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- if (host_io.ttyCwd(pt.pid, pt.fd, core.settings.shell.effective.get(), &lbuf)) |cwd| core.setCwd(id, cwd);
+ if (host_io.ttyCwd(pt.pid, pt.fd, core.settings.shell.effective.get(), &lbuf)) |cwd| core.setCwd(.at(id), cwd);
};
}
@@ -6280,7 +6294,7 @@ test "GUI PTY reader delivers a real shell tail before EOF and joins on close" {
const rcs: host_io.Shell.PromptFiles = .{};
const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80);
ptys[0] = .{ .fd = child.file.handle, .pid = child.pid, .serial = core.panes[0].?.serial };
- ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, 0, 1);
+ ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, .at(0), 1);
try std.testing.expect(host_io.writeFd(child.file.handle, "printf '\\120\\101\\122\\104\\105\\123\\055\\124\\101\\111\\114'; exit\n"));
var bytes: std.ArrayList(u8) = .empty;
defer bytes.deinit(gpa);
@@ -6317,8 +6331,8 @@ test "GUI PTY Restore joins a real reader waiting for queue space" {
try dump.dumpState(core);
var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
defer queue.deinit();
- queue.acceptReader(1, 1);
- for (0..output_capacity) |_| queue.push(.{ .output = .{ .pane = 1, .gen = 1, .bytes = try gpa.dupe(u8, "other pane") } });
+ queue.acceptReader(.at(1), 1);
+ for (0..output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(1), .gen = 1, .bytes = try gpa.dupe(u8, "other pane") } });
var ptys: [pardes.MAX_PANES]?Pty = @splat(null);
var gens: [pardes.MAX_PANES]u32 = @splat(1);
var shell: Shell = undefined;
@@ -6331,7 +6345,7 @@ test "GUI PTY Restore joins a real reader waiting for queue space" {
const rcs: host_io.Shell.PromptFiles = .{};
const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80);
ptys[0] = .{ .fd = child.file.handle, .pid = child.pid, .serial = core.panes[0].?.serial };
- ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, 0, 1);
+ ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, .at(0), 1);
try std.testing.expect(host_io.writeFd(child.file.handle, "printf 'after-full'; exit\n"));
try host_io.PtyTests.waitBlocked(&queue);
const old_serial = core.panes[0].?.serial;
@@ -6345,10 +6359,10 @@ test "GUI PTY Restore joins a real reader waiting for queue space" {
try std.testing.expectEqual(@as(usize, 0), queue.waiting);
try std.testing.expect(queue.readers[0] == null);
try std.testing.expectEqual(@as(c_int, -1), libc.fcntl(child.file.handle, libc.F.GETFD));
- queue.cancelReader(1, 1);
- queue.acceptReader(0, gens[0]);
- queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } });
- try std.testing.expect(queue.pushOutput(0, gens[0], try gpa.dupe(u8, "fresh")));
+ queue.cancelReader(.at(1), 1);
+ queue.acceptReader(.at(0), gens[0]);
+ queue.push(.{ .eof = .{ .pane = .at(0), .gen = 1 } });
+ try std.testing.expect(queue.pushOutput(.at(0), gens[0], try gpa.dupe(u8, "fresh")));
var batch = queue.take();
defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
try std.testing.expectEqual(@as(usize, 1), batch.len);
@@ -6373,7 +6387,7 @@ test "GUI PTY deletion joins an idle reader and its shell is reaped by exit" {
const rcs: host_io.Shell.PromptFiles = .{};
const child = try host_io.forkShell(null, 0, &rcs, "/bin/sh", "", 24, 80);
ptys[0] = .{ .fd = child.file.handle, .pid = child.pid, .serial = core.panes[0].?.serial };
- ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, 0, 1);
+ ptys[0].?.reader = try queue.startReader(.{ .handle = ptys[0].?.fd, .flags = .{ .nonblocking = false } }, .at(0), 1);
try core.removePane(0, null);
shell.reconcilePtys();
try std.testing.expect(queue.readers[0] == null);
@@ -6414,9 +6428,9 @@ test "GUI completion failure survives backlog and leaves the document unchanged"
const id = core.lsp_ask.wait.?.id;
var queue: Queue = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = id };
defer queue.deinit();
- queue.acceptReader(0, 1);
+ queue.acceptReader(.at(0), 1);
for (0..output_capacity) |_| queue.push(.{ .output = .{
- .pane = 0,
+ .pane = .at(0),
.gen = 1,
.bytes = try gpa.dupe(u8, "output"),
} });
@@ -6459,7 +6473,7 @@ test "GUI worker setup failures finish matching LSP and pipe requests" {
const req: host_io.Lsp.Request = .{
.id = core.lsp_ask.wait.?.id,
.kind = .status,
- .pane = @intCast(core.view().active),
+ .pane = .at(core.view().active),
.offset = 0,
.arg = "",
};
@@ -6560,7 +6574,7 @@ test "the window's function and editing keys reach a terminal as its cursor keys
.{ .modes = "", .sym = c.SDLK_UP, .sent = "\x1b[1;1:1A" },
};
for (cases) |case| {
- core.update(.{ .output = .{ .pane = 0, .bytes = case.modes } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = case.modes } });
while (core.nextEffect()) |_| {}
keyDown(&in, case.sym, case.mod);
written.clearRetainingCapacity();
@@ -6678,7 +6692,7 @@ test "the clipboard pasted into a terminal reaches its pty as xterm pastes: brac
fn f(core_: *pardes.Pardes, out: *std.ArrayList(u8)) ![]const u8 {
out.clearRetainingCapacity();
while (core_.nextEffect()) |effect| {
- if (effect == .write and effect.write.pane == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
+ if (effect == .write and effect.write.pane.index() == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
}
return out.items;
}
@@ -6692,7 +6706,7 @@ test "the clipboard pasted into a terminal reaches its pty as xterm pastes: brac
putClipboard(gpa, "ls\x1b[201~; rm -rf ~\nx");
readClipboard(&shell);
try std.testing.expectEqualStrings("ls [201~; rm -rf ~\rx", try take(core, &sent));
- core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h" } });
_ = try take(core, &sent);
readClipboard(&shell);
try std.testing.expectEqualStrings("\x1b[200~ls [201~; rm -rf ~\nx\x1b[201~", try take(core, &sent));
@@ -6774,7 +6788,7 @@ test "a click over codex in a terminal reaches its pty with its modifiers; Shift
fn f(core_: *pardes.Pardes, out: *std.ArrayList(u8)) ![]const u8 {
out.clearRetainingCapacity();
while (core_.nextEffect()) |effect| {
- if (effect == .write and effect.write.pane == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
+ if (effect == .write and effect.write.pane.index() == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
}
return out.items;
}
@@ -6784,7 +6798,7 @@ test "a click over codex in a terminal reaches its pty with its modifiers; Shift
const r = core.view().rects[0];
const mc: MouseCell = .{ .col = r.x + config.GUTTER + 5, .row = core.bodyTop(pane, r) + 3 };
const next: MouseCell = .{ .col = mc.col + 1, .row = mc.row };
- core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049h\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } });
_ = try take(core, &sent);
in.post(.{ .mouse = pointerMouse(.none, .motion, mc, .{}) });
try std.testing.expectEqualStrings("\x1b[<35;6;4M", try take(core, &sent));
@@ -6824,7 +6838,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a
fn take(core_: *pardes.Pardes, out: *std.ArrayList(u8)) ![]const u8 {
out.clearRetainingCapacity();
while (core_.nextEffect()) |effect| {
- if (effect == .write and effect.write.pane == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
+ if (effect == .write and effect.write.pane.index() == 0) try out.appendSlice(std.testing.allocator, effect.write.bytes.slice());
}
return out.items;
}
@@ -6834,7 +6848,7 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a
const r = core.view().rects[0];
const mc: MouseCell = .{ .col = r.x + config.GUTTER + 5, .row = core.bodyTop(pane, r) + 3 };
// What codex 0.159's chat sets on start.
- core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h\x1b[>7u\x1b[?1004h\x1b[?1049h\x1b[?1007l\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h\x1b[>7u\x1b[?1004h\x1b[?1049h\x1b[?1007l\x1b[?1000h\x1b[?1002h\x1b[?1003h\x1b[?1006h" } });
pardes.draw.facts(core, &g.facts);
_ = try Sent.take(core, &sent);
// A notch up, then a fast turn of three down: each its report, none
@@ -6860,14 +6874,14 @@ test "a wheel over codex in a terminal reaches its pty as the mouse reports it a
try std.testing.expectEqualStrings("", try Sent.take(core, &sent));
resetScroll(&g);
// Its sign-in screen: mouse off, alternate scroll on, so arrow keys.
- core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1006l\x1b[?1003l\x1b[?1002l\x1b[?1000l\x1b[?1007h" } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1006l\x1b[?1003l\x1b[?1002l\x1b[?1000l\x1b[?1007h" } });
pardes.draw.facts(core, &g.facts);
_ = try Sent.take(core, &sent);
wheelAt(&g, &in, .{ .y = -1, .integer_y = -1 }, mc);
try std.testing.expectEqualStrings("\x1b[B", try Sent.take(core, &sent));
// Back on the main screen a shell's wheel is ours: a notch to glide,
// nothing to the pty.
- core.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049l" } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049l" } });
pardes.draw.facts(core, &g.facts);
_ = try Sent.take(core, &sent);
wheelAt(&g, &in, .{ .y = 1, .integer_y = 1 }, mc);
diff --git a/dev/host_io.zig b/dev/host_io.zig
index 377263a4..f86c3250 100644
--- a/dev/host_io.zig
+++ b/dev/host_io.zig
@@ -54,12 +54,12 @@ pub fn stopWorkers() void {
pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u8, peers: *replica.Peers, inotify_fd: c_int, watches: *file_watch.Table) ?*pardes.Pardes {
peers.dropAll(core);
const bytes = pardes.dump.restoreBytes(core, gpa, path) catch |err| {
- core.reportError(core.view().active, "Restore", err);
+ core.reportError(.at(core.view().active), "Restore", err);
return null;
};
defer gpa.free(bytes);
const nc = pardes.dump.restore(core, bytes, path) catch |err| {
- core.reportError(core.view().active, "Restore", err);
+ core.reportError(.at(core.view().active), "Restore", err);
return null;
};
file_watch.unwatchAll(inotify_fd, watches);
@@ -69,7 +69,7 @@ pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u
/// A shell of a dead session the daemon handed this one (Adopt), and the
/// terminal pane made for it once there is one.
-pub const Adoption = struct { pid: libc.pid_t, fd: c_int, pane: ?u8 };
+pub const Adoption = struct { pid: libc.pid_t, fd: c_int, pane: ?pardes.Pane.Id };
/// The shells of dead sessions handed this one (Adopt), each waiting for
/// the spawn of the terminal pane made for it (`take`).
@@ -93,7 +93,7 @@ pub const Adoptions = struct {
pub fn adoptShell(a: *Adoptions, core: *pardes.Pardes, pid: libc.pid_t, fd: c_int) void {
if (pid == 0) {
var buf: pardes.Kind.Buf(96) = .{};
- return core.setMessage(core.view().active, if (a.taken == 0) "Adopt: no shell of a session that died is waiting" else buf.print("Adopt: {d} shell{s} taken in; what they showed is gone", .{ a.taken, if (a.taken == 1) "" else "s" }));
+ return core.setMessage(.at(core.view().active), if (a.taken == 0) "Adopt: no shell of a session that died is waiting" else buf.print("Adopt: {d} shell{s} taken in; what they showed is gone", .{ a.taken, if (a.taken == 1) "" else "s" }));
}
if (a.len < a.list.len) {
a.list[a.len] = .{ .pid = pid, .fd = fd, .pane = null };
@@ -108,11 +108,11 @@ pub const Adoptions = struct {
// No room for it: its master goes, and the shell with this session.
_ = libc.close(fd);
var buf: pardes.Kind.Buf(96) = .{};
- core.setMessage(core.view().active, buf.print("Adopt: no room for shell {d}; it ends with this session", .{pid}));
+ core.setMessage(.at(core.view().active), buf.print("Adopt: no room for shell {d}; it ends with this session", .{pid}));
}
/// The adopted shell pane `pane`'s spawn takes, off the list.
- pub fn take(a: *Adoptions, pane: u8) ?Adoption {
+ pub fn take(a: *Adoptions, pane: pardes.Pane.Id) ?Adoption {
for (a.list[0..a.len], 0..) |it, i| if (it.pane == pane) {
std.mem.copyForwards(Adoption, a.list[i .. a.len - 1], a.list[i + 1 .. a.len]);
a.len -= 1;
@@ -549,7 +549,7 @@ pub fn forkShell(
// The daemon keeps a dup: this session killed outright never hangs the
// shell up (daemon.zig).
@import("runtime").daemon.pty(pid, master);
- if (core) |c| c.acknowledgeShell(pane, std.mem.span(spawn.path), one_line == null and spawn.argv[1] != null);
+ if (core) |c| c.acknowledgeShell(.at(pane), std.mem.span(spawn.path), one_line == null and spawn.argv[1] != null);
return .{ .file = .{ .handle = master, .flags = .{ .nonblocking = false } }, .pid = pid };
}
@@ -1105,7 +1105,7 @@ pub fn takeExits(core: *pardes.Pardes, ptys: anytype, ctx: anytype, comptime clo
if (!pt.cmd.watched or !pt.cmd.due()) continue;
pt.cmd.told = true;
const eof = pt.cmd.eof;
- core.update(.{ .exited = .{ .pane = @intCast(id), .status = pt.cmd.status } });
+ core.update(.{ .exited = .{ .pane = .at(id), .status = pt.cmd.status } });
if (eof) close(ctx, id);
}
}
@@ -1115,7 +1115,7 @@ pub fn takeExits(core: *pardes.Pardes, ptys: anytype, ctx: anytype, comptime clo
pub fn commandEof(core: *pardes.Pardes, ptys: anytype, id: usize, ctx: anytype, comptime close: anytype) void {
const pt = slotPty(&ptys[id]) orelse return;
pt.cmd.eof = true;
- core.update(.{ .eof = .{ .pane = @intCast(id) } });
+ core.update(.{ .eof = .{ .pane = .at(id) } });
if (pt.cmd.told) return close(ctx, id);
takeExits(core, ptys, ctx, close);
}
@@ -1481,7 +1481,7 @@ fn sleepMs(ms: i64) void {
/// change), and "saved" said on the pane.
pub fn writeFile(core: *pardes.Pardes, watches: *file_watch.Table, pane: u8, path: []const u8, bytes: []const u8) void {
filesystem.write(core, path, bytes) catch |err|
- return core.saveFailed(pane, path, err);
+ return core.saveFailed(.at(pane), path, err);
if (core.panes[pane]) |pn| if (pn.file) |f| if (std.mem.eql(u8, f.path, path)) {
if (watches[pane]) |*w| if (w.serial == pn.serial) switch (w.generation) {
.text => w.generation = .{ .text = std.hash.Wyhash.hash(0, bytes) },
@@ -1489,7 +1489,7 @@ pub fn writeFile(core: *pardes.Pardes, watches: *file_watch.Table, pane: u8, pat
};
};
var mbuf: [256]u8 = undefined;
- core.setMessage(pane, pardes.Messages.Message.stamp(&mbuf, "saved", path));
+ core.setMessage(.at(pane), pardes.Messages.Message.stamp(&mbuf, "saved", path));
// The init file, saved here (Config): its settings take effect now.
pardes.exec.reapplyInitFile(core, path, bytes);
// The plumbing file (Plumb): its rules in force now.
@@ -1527,12 +1527,12 @@ pub fn writeDump(core: *pardes.Pardes, bytes: []const u8) void {
pub fn dumpThemes(core: *pardes.Pardes, io: std.Io, gpa: std.mem.Allocator, pane: u8) void {
const config_dir = core.opts.config_dir orelse return;
const out_dir = pardes.config.User.dumpThemes(io, gpa, config_dir, pardes.themes) catch |err| {
- core.reportError(pane, "dump themes", err);
+ core.reportError(.at(pane), "dump themes", err);
return;
};
defer gpa.free(out_dir);
var mbuf: [256]u8 = undefined;
- core.setMessage(pane, pardes.Messages.Message.stamp(&mbuf, "dumped themes", out_dir));
+ core.setMessage(.at(pane), pardes.Messages.Message.stamp(&mbuf, "dumped themes", out_dir));
}
pub const PtyTests = struct {
@@ -1549,7 +1549,7 @@ pub const PtyTests = struct {
}
fn tail(queue: *Inbox, bytes: []u8) void {
- if (queue.pushOutput(0, 1, bytes)) queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } });
+ if (queue.pushOutput(.at(0), 1, bytes)) queue.push(.{ .eof = .{ .pane = .at(0), .gen = 1 } });
}
};
@@ -2155,9 +2155,9 @@ test "completion survives a full output queue" {
const gpa = std.testing.allocator;
var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 7 };
defer queue.deinit();
- queue.acceptReader(0, 1);
+ queue.acceptReader(.at(0), 1);
for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{
- .pane = 0,
+ .pane = .at(0),
.gen = 1,
.bytes = try gpa.dupe(u8, "output"),
} });
@@ -2193,15 +2193,15 @@ test "PTY backpressure retains byte order and tail before EOF" {
const gpa = std.testing.allocator;
var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
defer queue.deinit();
- queue.acceptReader(0, 1);
- for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
+ queue.acceptReader(.at(0), 1);
+ for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
const tail = try gpa.dupe(u8, "tail");
var thread: ?std.Thread = std.Thread.spawn(.{}, PtyTests.tail, .{ &queue, tail }) catch |err| {
gpa.free(tail);
return err;
};
defer {
- queue.cancelReader(0, 1);
+ queue.cancelReader(.at(0), 1);
if (thread) |owned| owned.join();
}
try PtyTests.waitBlocked(&queue);
@@ -2227,24 +2227,24 @@ test "PTY backpressure cancellation and close release owned producers" {
for ([_]bool{ false, true }) |close| {
var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
defer queue.deinit();
- queue.acceptReader(0, 1);
- for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
+ queue.acceptReader(.at(0), 1);
+ for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
const tail = try gpa.dupe(u8, "cancelled");
const thread = std.Thread.spawn(.{}, PtyTests.tail, .{ &queue, tail }) catch |err| {
gpa.free(tail);
return err;
};
defer {
- queue.cancelReader(0, 1);
+ queue.cancelReader(.at(0), 1);
thread.join();
}
try PtyTests.waitBlocked(&queue);
- if (close) queue.close() else queue.cancelReader(0, 1);
+ if (close) queue.close() else queue.cancelReader(.at(0), 1);
if (!close) {
- queue.acceptReader(0, 2);
- queue.push(.{ .eof = .{ .pane = 0, .gen = 1 } });
- try std.testing.expect(queue.pushOutput(0, 2, try gpa.dupe(u8, "replacement")));
- queue.push(.{ .eof = .{ .pane = 0, .gen = 2 } });
+ queue.acceptReader(.at(0), 2);
+ queue.push(.{ .eof = .{ .pane = .at(0), .gen = 1 } });
+ try std.testing.expect(queue.pushOutput(.at(0), 2, try gpa.dupe(u8, "replacement")));
+ queue.push(.{ .eof = .{ .pane = .at(0), .gen = 2 } });
var batch = queue.take();
defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
try std.testing.expectEqual(@as(usize, 2), batch.len);
@@ -2258,14 +2258,14 @@ test "PTY EOF reserve cannot evict terminal output" {
const gpa = std.testing.allocator;
var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa };
defer queue.deinit();
- for (0..pardes.MAX_PANES) |pane| queue.acceptReader(@intCast(pane), 1);
- for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
- for (0..pardes.MAX_PANES) |pane| queue.push(.{ .eof = .{ .pane = @intCast(pane), .gen = 1 } });
+ for (0..pardes.MAX_PANES) |pane| queue.acceptReader(.at(pane), 1);
+ for (0..Inbox.output_capacity) |_| queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "before") } });
+ for (0..pardes.MAX_PANES) |pane| queue.push(.{ .eof = .{ .pane = .at(pane), .gen = 1 } });
var batch = queue.take();
defer for (batch.slice()) |msg| msg.deinit(gpa, gpa);
try std.testing.expectEqual(Inbox.capacity, batch.len);
for (batch.items[0..Inbox.output_capacity]) |msg| try std.testing.expectEqualStrings("before", msg.output.bytes);
- for (batch.items[Inbox.output_capacity..batch.len], 0..) |msg, pane| try std.testing.expectEqual(pane, msg.eof.pane);
+ for (batch.items[Inbox.output_capacity..batch.len], 0..) |msg, pane| try std.testing.expectEqual(pane, msg.eof.pane.index());
}
test "completions retain their arrival order across LSP and pipes" {
@@ -2288,8 +2288,8 @@ test "completion reset frees queued payloads and rejects late LSP workers" {
const gpa = std.testing.allocator;
var queue: Inbox = .{ .io = std.testing.io, .gpa = gpa, .lsp_allocator = gpa, .lsp_id = 9 };
defer queue.deinit();
- queue.acceptReader(0, 1);
- queue.push(.{ .output = .{ .pane = 0, .gen = 1, .bytes = try gpa.dupe(u8, "retained") } });
+ queue.acceptReader(.at(0), 1);
+ queue.push(.{ .output = .{ .pane = .at(0), .gen = 1, .bytes = try gpa.dupe(u8, "retained") } });
queue.push(.{ .lsp = .{ .id = 9, .rows = try gpa.dupe(u8, "current") } });
queue.push(.{ .lsp = .{ .id = 8, .rows = try gpa.dupe(u8, "late old request") } });
try std.testing.expectEqualStrings("current", queue.completions[0].lsp.rows.?);
@@ -2343,7 +2343,7 @@ test "LSP query answers, and a newer one cancels it" {
defer queue.deinit();
for (0..2) |_| {
core.lspRequest(core.view().active, .status, "");
- queue.startLsp(core, .{ .id = core.lsp_ask.wait.?.id, .kind = .status, .pane = @intCast(core.view().active), .offset = 0, .arg = "" });
+ queue.startLsp(core, .{ .id = core.lsp_ask.wait.?.id, .kind = .status, .pane = .at(core.view().active), .offset = 0, .arg = "" });
}
const last = core.lsp_ask.wait.?.id;
queue.lsp_task.?.future.await(io);
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index 70ea3295..1f6b9a49 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -1099,7 +1099,7 @@ const Own = struct {
}
sh.pipe_tasks.cancelAll(io);
for (&sh.gens) |*generation| generation.* +%= 1;
- for (0..pardes.MAX_PANES) |pane| Shell.closePty(sh, @intCast(pane));
+ for (0..pardes.MAX_PANES) |pane| Shell.closePty(sh, .at(pane));
// One view, the terminal's (host_io.restoreCore).
const live = o.screen;
stopInput(io, &live.thread);
@@ -1386,7 +1386,8 @@ const Shell = struct {
if (stub >= 0) daemon.tellStub(stub, "r{s}", .{why});
}
- fn adopt(ctx: ?*anyopaque, pane: u8) void {
+ fn adopt(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = of(ctx);
s.adoptions.ask(s.core, pane);
}
@@ -1397,7 +1398,8 @@ const Shell = struct {
return of(ctx).client == null and upgrade.newer();
}
- fn upgradeAsked(ctx: ?*anyopaque, pane: u8) void {
+ fn upgradeAsked(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = of(ctx);
if (comptime !upgrade.supported) return s.core.reportFailure(pane, "Upgrade: this system cannot move a session to another build in place");
s.upgrade_asked = pane;
@@ -1500,7 +1502,7 @@ const Shell = struct {
if (t.stub >= 0) daemon.tellStub(t.stub, "d{s}", .{daemon.name()});
}
if (rec.fresh) return;
- for (0..pardes.views.max) |k| if (k != s.own and pardes.views.isOpen(core, @intCast(k)) and !pardes.views.isAway(core, @intCast(k))) core.closeView(@intCast(k));
+ for (0..pardes.views.max) |k| if (k != s.own and pardes.views.isOpen(core, @intCast(k)) and !pardes.views.isAway(core, @intCast(k))) core.closeView(.at(k));
}
fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
@@ -1673,7 +1675,7 @@ const Shell = struct {
// The terminal's input goes into its view.
switch (event) {
.key_press, .mouse, .paste, .paste_start, .paste_end, .winsize, .focus_in, .focus_out, .quit => {
- if (s.local() and s.client == null) core.toView(s.own);
+ if (s.local() and s.client == null) core.toView(.at(s.own));
},
else => {},
}
@@ -1748,7 +1750,7 @@ const Shell = struct {
s.output_seen = true;
if (pr.id == core.view().active) s.focused_ns = @intCast(std.Io.Clock.awake.now(s.io).nanoseconds);
if (s.gens[pr.id] == pr.gen)
- core.update(.{ .output = .{ .pane = @intCast(pr.id), .bytes = pr.bytes } });
+ core.update(.{ .output = .{ .pane = .at(pr.id), .bytes = pr.bytes } });
s.gpa.free(pr.bytes);
// An exit waiting behind this output may be told now.
s.takeExits();
@@ -1771,9 +1773,9 @@ const Shell = struct {
const status = host_io.exitStatus(pt.pid, 100);
if (status == null) host_io.retireShell(pt.pid);
s.ptys[e.id] = null;
- if (command or status != null) core.update(.{ .exited = .{ .pane = @intCast(e.id), .status = status } });
+ if (command or status != null) core.update(.{ .exited = .{ .pane = .at(e.id), .status = status } });
}
- core.update(.{ .eof = .{ .pane = @intCast(e.id) } });
+ core.update(.{ .eof = .{ .pane = .at(e.id) } });
},
.key_press => |key| if (s.in_paste) {
const bytes = vaxis_input.pasteBytes(key);
@@ -1807,7 +1809,7 @@ const Shell = struct {
},
.lsp_status => |text| {
var mbuf: [256]u8 = undefined;
- core.setStatus(core.view().active, message.stamp(&mbuf, "lsp", text));
+ core.setStatus(.at(core.view().active), message.stamp(&mbuf, "lsp", text));
s.lsp_gpa.free(text);
},
.pipe_done => |response_value| {
@@ -1851,7 +1853,7 @@ const Shell = struct {
if (!sc.on or sc.vx.state.in_band_resize) return;
const ws = sc.tty.getWinsize() catch return;
if (sc.size) |was| if (std.meta.eql(was, ws)) return;
- if (s.client == null) s.core.toView(s.own);
+ if (s.client == null) s.core.toView(.at(s.own));
s.resized(sc, ws);
}
@@ -1885,7 +1887,7 @@ const Shell = struct {
};
for (&s.ptys, 0..) |*slot, id| if (slot.*) |pt| {
var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- if (host_io.ttyCwd(pt.pid, pt.file.handle, s.core.settings.shell.effective.get(), &lbuf)) |cwd| s.core.setCwd(id, cwd);
+ if (host_io.ttyCwd(pt.pid, pt.file.handle, s.core.settings.shell.effective.get(), &lbuf)) |cwd| s.core.setCwd(.at(id), cwd);
};
const sc = s.term() orelse return;
@@ -2028,17 +2030,18 @@ const Shell = struct {
tracy.frameMark();
}
- fn spawn(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void {
+ fn spawn(ctx: ?*anyopaque, id: pardes.Pane.Id, cwd: []const u8) void {
+ const pane = id.index();
const s = of(ctx);
- if (s.adoptions.take(pane)) |a| return s.takeShell(pane, a);
+ if (s.adoptions.take(id)) |a| return s.takeShell(pane, a);
// The new shell starts before a running one goes: one that cannot
// start leaves the running one be (pty/ctl's exec).
const running = s.ptys[pane] != null;
const child = host_io.forkShell(s.core, pane, s.prompt_rcs, s.core.shellBin(), cwd, s.core.view().screen_h, s.core.view().screen_w) catch |err| {
- if (running) return s.core.restartFailed(pane, err);
- return s.core.shellFailed(pane, err);
+ if (running) return s.core.restartFailed(id, err);
+ return s.core.shellFailed(id, err);
};
- closePty(ctx, pane); // a shell still in the slot goes, reaped
+ closePty(ctx, id); // a shell still in the slot goes, reaped
s.gens[pane] +%= 1;
const command = if (s.core.panes[pane]) |pn| pn.command != null else false;
s.ptys[pane] = .{ .file = child.file, .pid = child.pid, .reader = .{ .any_future = null, .result = {} }, .cmd = .{ .watched = command and host_io.watchExit(child.pid), .fd = child.file.handle } };
@@ -2046,7 +2049,7 @@ const Shell = struct {
// Only a shell given no directory is asked where it is: one given a
// directory is named by it already (newShell), and asked now, before
// its chdir, it would answer this process's, a rename to undo.
- if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| s.core.setCwd(pane, wd);
+ if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| s.core.setCwd(id, wd);
if (s.threads_ok) {
if (s.ptys[pane]) |*pt| {
pt.reader = s.io.concurrent(readPty, .{ s.io, s.gpa, pt.file, @as(usize, pane), s.gens[pane], s.loop }) catch pt.reader;
@@ -2057,28 +2060,30 @@ const Shell = struct {
/// An adopted shell, running already, as pane `pane`'s: told the size
/// twice (a size it never had, then the pane's), which makes it redraw.
fn takeShell(s: *Shell, pane: u8, a: host_io.Adoption) void {
- closePty(s, pane);
+ closePty(s, .at(pane));
s.gens[pane] +%= 1;
const file: std.Io.File = .{ .handle = a.fd, .flags = .{ .nonblocking = false } };
s.ptys[pane] = .{ .file = file, .pid = a.pid, .reader = .{ .any_future = null, .result = {} }, .cmd = .{} };
var exe_buf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- s.core.acknowledgeShell(pane, host_io.processExe(a.pid, &exe_buf) orelse "sh", host_io.marksPrompts(a.pid));
+ s.core.acknowledgeShell(.at(pane), host_io.processExe(a.pid, &exe_buf) orelse "sh", host_io.marksPrompts(a.pid));
var lbuf: [pardes.memory.limits.host_path_cap + 1]u8 = undefined;
- if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(pane, wd);
+ if (host_io.shellCwd(a.pid, &lbuf)) |wd| s.core.setCwd(.at(pane), wd);
const tiny: posix.winsize = .{ .row = 1, .col = 1, .xpixel = 0, .ypixel = 0 };
_ = posix.system.ioctl(a.fd, TIOCSWINSZ, @intFromPtr(&tiny));
- if (s.core.panes[pane]) |pn| ptyResize(s, pane, @max(pn.cols, 1), @max(pn.rows, 1));
+ if (s.core.panes[pane]) |pn| ptyResize(s, .at(pane), @max(pn.cols, 1), @max(pn.rows, 1));
if (s.threads_ok) if (s.ptys[pane]) |*pt| {
pt.reader = s.io.concurrent(readPty, .{ s.io, s.gpa, pt.file, @as(usize, pane), s.gens[pane], s.loop }) catch pt.reader;
};
}
- fn ptyWrite(ctx: ?*anyopaque, pane: u8, bytes: []const u8) void {
+ fn ptyWrite(ctx: ?*anyopaque, id: pardes.Pane.Id, bytes: []const u8) void {
+ const pane = id.index();
const s = of(ctx);
if (s.ptys[pane]) |pt| _ = host_io.writeFd(pt.file.handle, bytes);
}
- fn ptyResize(ctx: ?*anyopaque, pane: u8, cols: u16, rows: u16) void {
+ fn ptyResize(ctx: ?*anyopaque, id: pardes.Pane.Id, cols: u16, rows: u16) void {
+ const pane = id.index();
const s = of(ctx);
if (s.ptys[pane]) |pt| {
const ws = host_io.ptyWinsize(s.core, cols, rows);
@@ -2086,7 +2091,8 @@ const Shell = struct {
}
}
- fn ptySignal(ctx: ?*anyopaque, pane: u8, sig: pardes.PtySignal) void {
+ fn ptySignal(ctx: ?*anyopaque, id: pardes.Pane.Id, sig: pardes.PtySignal) void {
+ const pane = id.index();
const s = of(ctx);
// A command whose exit is recorded is reaped: its group may be
// another's by now.
@@ -2096,7 +2102,8 @@ const Shell = struct {
/// The pane is gone: hang its pty up, which the kernel passes on to the
/// shell as SIGHUP, and retire the shell. Output still in flight
/// carries the old generation and is dropped.
- fn closePty(ctx: ?*anyopaque, pane: u8) void {
+ fn closePty(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = of(ctx);
var pt = s.ptys[pane] orelse return;
s.ptys[pane] = null;
@@ -2107,13 +2114,15 @@ const Shell = struct {
host_io.retireShell(pt.pid);
}
- fn ttyTaken(ctx: ?*anyopaque, pane: u8) bool {
+ fn ttyTaken(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
+ const pane = id.index();
const s = of(ctx);
const pt = s.ptys[pane] orelse return false;
return host_io.ttyTaken(pt.pid, pt.file.handle);
}
- fn fgName(ctx: ?*anyopaque, pane: u8, buf: []u8) ?[]const u8 {
+ fn fgName(ctx: ?*anyopaque, id: pardes.Pane.Id, buf: []u8) ?[]const u8 {
+ const pane = id.index();
const s = of(ctx);
const pt = s.ptys[pane] orelse return null;
return host_io.foregroundName(pt.pid, pt.file.handle, buf);
@@ -2130,13 +2139,15 @@ const Shell = struct {
s.ptys[id] = null;
}
- fn killJob(ctx: ?*anyopaque, pane: u8) bool {
+ fn killJob(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
+ const pane = id.index();
const s = of(ctx);
const pt = s.ptys[pane] orelse return false;
return host_io.killJob(pt.pid, pt.file.handle);
}
- fn writeFile(ctx: ?*anyopaque, pane: u8, path: []const u8, bytes: []const u8) void {
+ fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, bytes: []const u8) void {
+ const pane = id.index();
const s = of(ctx);
host_io.writeFile(s.core, &s.watches, pane, path, bytes);
}
@@ -2145,7 +2156,8 @@ const Shell = struct {
host_io.writeDump(of(ctx).core, bytes);
}
- fn watchFile(ctx: ?*anyopaque, pane: u8, _: []const u8, on: bool, mode: pardes.WatchMode) void {
+ fn watchFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, on: bool, mode: pardes.WatchMode) void {
+ const pane = id.index();
const s = of(ctx);
if (file_watch.applyEffect(s.core, s.io, s.inotify_fd, &s.watches, pane, on, mode))
s.loop.postEvent(.files_changed) catch {};
@@ -2157,7 +2169,8 @@ const Shell = struct {
s.loop.postEvent(.files_changed) catch {};
}
- fn dumpThemes(ctx: ?*anyopaque, pane: u8) void {
+ fn dumpThemes(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const s = of(ctx);
host_io.dumpThemes(s.core, s.io, s.gpa, pane);
}
@@ -2199,7 +2212,7 @@ const Shell = struct {
const s = of(ctx);
if (!s.threads_ok) {
s.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } });
- return s.core.reportError(s.core.view().active, "pipe", error.WorkersUnavailable);
+ return s.core.reportError(.at(s.core.view().active), "pipe", error.WorkersUnavailable);
}
selection_pipe.start(s.io, s.gpa, s.core, &s.pipe_tasks, id, s, deliverPipe);
}
@@ -2220,7 +2233,8 @@ const Shell = struct {
}.deliver);
}
- fn job(ctx: ?*anyopaque, pane: u8, serial: u32, token: u32) void {
+ fn job(ctx: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void {
+ const pane = id.index();
const s = of(ctx);
if (!s.threads_ok) return host_io.KindJob.runHere(s.core, pane, serial, token);
host_io.KindJob.start(s.io, s.core, &s.job_tasks, pane, serial, token, s, struct {
@@ -2960,7 +2974,7 @@ test "on a terminal with no kitty graphics a program's 64x64 image over 8x4 cell
for (0..64 * 64) |i| px[i * 3 ..][0..3].* = .{ 13, 77, 231 };
const enc = try a.alloc(u8, std.base64.standard.Encoder.calcSize(px.len));
_ = std.base64.standard.Encoder.encode(enc, px);
- core.update(.{ .output = .{ .pane = 0, .bytes = try std.fmt.allocPrint(a, "\x1b[H\x1b[2J\r\nANCHOR>\x1b_Ga=T,i=42,f=24,s=64,v=64,c=8,r=4;{s}\x1b\\\r\n", .{enc}) } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = try std.fmt.allocPrint(a, "\x1b[H\x1b[2J\r\nANCHOR>\x1b_Ga=T,i=42,f=24,s=64,v=64,c=8,r=4;{s}\x1b\\\r\n", .{enc}) } });
while (core.nextEffect()) |_| {}
const s = try core.render(a);
try std.testing.expectEqual(@as(usize, 4), s.placements.items.len);
@@ -3056,7 +3070,7 @@ test "TTY worker setup failures finish matching LSP and pipe requests" {
const req: host_io.Lsp.Request = .{
.id = core.lsp_ask.wait.?.id,
.kind = .status,
- .pane = @intCast(core.view().active),
+ .pane = .at(core.view().active),
.offset = 0,
.arg = "",
};
@@ -3156,7 +3170,7 @@ test "the terminal's keys reach a program as its cursor keys' mode and keyboard
.{ .modes = "\x1b[?1l\x1b[>7u", .in = "\x1b[99;5u\x1b[97;3u\x1b[A", .sent = "\x1b[99;5u\x1b[97;3u\x1b[1;1:1A" },
};
for (cases) |case| {
- core.update(.{ .output = .{ .pane = 0, .bytes = case.modes } });
+ core.update(.{ .output = .{ .pane = .at(0), .bytes = case.modes } });
while (core.nextEffect()) |_| {}
var parser: vaxis.Parser = .{};
var bytes = case.in;