summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/9p_io.zig12
-rw-r--r--runtime/addon_test.zig2
-rw-r--r--runtime/macos.zig81
-rw-r--r--runtime/upgrade.zig6
4 files changed, 55 insertions, 46 deletions
diff --git a/runtime/9p_io.zig b/runtime/9p_io.zig
index ef4ecfdd..bcb0f81b 100644
--- a/runtime/9p_io.zig
+++ b/runtime/9p_io.zig
@@ -1109,7 +1109,7 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes) ?*Listene
// unreachable: a u32 is at most 10 digits
const fallback = std.fmt.bufPrint(&name, "{d}", .{@as(u32, @intCast(libc.getpid()))}) catch unreachable;
return listen(io, gpa, core, core.opts.ninep_name, fallback, core.opts.ninep_tcp) catch {
- if (refusal.len > 0) core.setMessage(0, refusal) else core.reportError(0, "9p listener", error.ListenFailed);
+ if (refusal.len > 0) core.setMessage(.at(0), refusal) else core.reportError(.at(0), "9p listener", error.ListenFailed);
return null;
};
}
@@ -2647,7 +2647,7 @@ test "a held read is answered when the log has news, and a flushed one spends no
try s.flush();
try heldNow.count(p, 2);
pardes.turn.wake();
- p.setMessage(0, "after the flush");
+ p.setMessage(.at(0), "after the flush");
pardes.turn.rest();
try heldNow.count(p, 1);
pardes.turn.wake();
@@ -2670,7 +2670,7 @@ test "a held read is answered when the log has news, and a flushed one spends no
try testing.expectEqual(second, refused.tag);
try testing.expectEqualStrings(pardes.ctlfs.e_in_use, refused.result.fail);
pardes.turn.wake();
- p.setMessage(0, "while held");
+ p.setMessage(.at(0), "while held");
const retry_all = pardes.turn.parked;
pardes.turn.rest();
try testing.expect(!retry_all);
@@ -2698,9 +2698,9 @@ test "a held read is answered when the log has news, and a flushed one spends no
try s.flush();
try heldNow.count(p, 1);
pardes.turn.wake();
- p.setMessage(0, "queued one");
- p.setMessage(0, "queued two");
- p.setMessage(0, "queued three");
+ p.setMessage(.at(0), "queued one");
+ p.setMessage(.at(0), "queued two");
+ p.setMessage(.at(0), "queued three");
l.reset(p);
pardes.turn.rest();
const cut = try s.settle();
diff --git a/runtime/addon_test.zig b/runtime/addon_test.zig
index a08237fc..a37a2262 100644
--- a/runtime/addon_test.zig
+++ b/runtime/addon_test.zig
@@ -121,7 +121,7 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons
if (is(verb, "view")) {
const n = std.fmt.parseInt(u8, arg[0..@min(1, arg.len)], 10) catch 1;
while (n > 1 and !pardes.views.isOpen(p, n - 1)) _ = p.openView() orelse break;
- if (pardes.views.isOpen(p, n -| 1)) p.toView(n -| 1);
+ if (pardes.views.isOpen(p, n -| 1)) p.toView(.at(n -| 1));
}
p.update(.{ .frontend = .{ .windowed = false, .native_images = std.mem.endsWith(u8, arg, "on") } });
} else if (is(verb, "dump")) {
diff --git a/runtime/macos.zig b/runtime/macos.zig
index 4f8bd709..408915da 100644
--- a/runtime/macos.zig
+++ b/runtime/macos.zig
@@ -385,7 +385,7 @@ fn initCore(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) !void {
while (core.nextEffect()) |effect| core.perform(effect);
st.started = true;
- if (st.ninep) |listener| listener.watch(st, wakeNinep) catch |err| core.reportError(0, "9p wake", err);
+ if (st.ninep) |listener| listener.watch(st, wakeNinep) catch |err| core.reportError(.at(0), "9p wake", err);
for (&st.ptys, 0..) |*slot, id| if (slot.*) |*pt| startReader(st, pt, @intCast(id));
pardes.lsp.setStatusSink(&st.inbox, Inbox.lspStatus);
@@ -593,7 +593,7 @@ fn refreshCwds(ctx: ?*anyopaque) void {
stale.* = false;
const pt = st.ptys[id] orelse continue;
var buf: [1024]u8 = undefined;
- if (host_io.ttyCwd(pt.pid, pt.file.handle, st.core.settings.shell.effective.get(), &buf)) |wd| st.core.setCwd(id, wd);
+ if (host_io.ttyCwd(pt.pid, pt.file.handle, st.core.settings.shell.effective.get(), &buf)) |wd| st.core.setCwd(.at(id), wd);
}
}
@@ -682,7 +682,7 @@ fn reloadWatchedTheme(st: *State, announce: bool) bool {
live.retries_left = 0;
if (announce) {
var mbuf: [256]u8 = undefined;
- st.core.setMessage(request.pane, message.stamp(&mbuf, "reloaded theme", request.path));
+ st.core.setMessage(.at(request.pane), message.stamp(&mbuf, "reloaded theme", request.path));
}
return true;
}
@@ -711,7 +711,7 @@ fn reloadWatchedFile(st: *State, pane: u8, announce: bool) bool {
defer st.core.gpa.free(bytes);
const hash = std.hash.Wyhash.hash(0, bytes);
if (hash == old_hash) break :text .no_change;
- if (!st.core.reloadWatchedFile(pane, bytes)) {
+ if (!st.core.reloadWatchedFile(.at(pane), bytes)) {
retryWatchedFile(st, pane, generation);
break :text .no_change;
}
@@ -732,7 +732,7 @@ fn reloadWatchedFile(st: *State, pane: u8, announce: bool) bool {
break :pdf .no_change;
};
if (old_identity) |old| if (old.eql(before)) break :pdf .no_change;
- if (!st.core.reloadWatchedFile(pane, &.{})) {
+ if (!st.core.reloadWatchedFile(.at(pane), &.{})) {
retryWatchedFile(st, pane, generation);
break :pdf .no_change;
}
@@ -759,7 +759,7 @@ fn reloadWatchedFile(st: *State, pane: u8, announce: bool) bool {
};
if (result == .committed and announce) {
var mbuf: [256]u8 = undefined;
- st.core.setMessage(pane, message.stamp(&mbuf, "reloaded", watched.path));
+ st.core.setMessage(.at(pane), message.stamp(&mbuf, "reloaded", watched.path));
}
return result != .no_change;
}
@@ -781,31 +781,31 @@ fn drainInbox(st: *State) bool {
defer msg.deinit(st.gpa, st.gpa);
switch (msg) {
.output => |o| {
- if (st.gens[o.pane] != o.gen) continue;
- st.cwd_stale[o.pane] = true;
+ if (st.gens[o.pane.index()] != o.gen) continue;
+ st.cwd_stale[o.pane.index()] = true;
st.core.update(.{ .output = .{ .pane = o.pane, .bytes = o.bytes } });
},
.eof => |e| {
- if (st.gens[e.pane] != e.gen) continue;
- if (st.ptys[e.pane]) |*pt| {
+ if (st.gens[e.pane.index()] != e.gen) continue;
+ if (st.ptys[e.pane.index()]) |*pt| {
// A command's pty stays open until its child has exited:
// 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(st.core, &st.ptys, e.pane, st, closeWatched);
+ host_io.commandEof(st.core, &st.ptys, e.pane.index(), st, closeWatched);
continue;
}
// 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 command = if (st.core.panes[e.pane]) |pane| pane.command != null else false;
+ const command = if (st.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
- reap(st, e.pane);
+ reap(st, e.pane.index());
if (command or status != null) st.core.update(.{ .exited = .{ .pane = e.pane, .status = status } });
st.core.update(.{ .eof = .{ .pane = e.pane } });
continue;
}
- reap(st, e.pane);
+ reap(st, e.pane.index());
st.core.update(.{ .eof = .{ .pane = e.pane } });
},
.lsp => |d| {
@@ -817,7 +817,7 @@ fn drainInbox(st: *State) bool {
},
.lsp_status => |text| {
var mbuf: [256]u8 = undefined;
- st.core.setStatus(st.core.view().active, message.stamp(&mbuf, "lsp", text));
+ st.core.setStatus(.at(st.core.view().active), message.stamp(&mbuf, "lsp", text));
},
.pipe => |value| {
st.core.update(.{ .pipe_resp = .{
@@ -874,12 +874,12 @@ fn restoreCore(st: *State) bool {
if (st.core.quit) return false;
const path = st.core.takeRestore() orelse return false;
const bytes = dump.restoreBytes(st.core, st.gpa, path) catch |err| {
- st.core.reportError(st.core.view().active, "Restore", err);
+ st.core.reportError(.at(st.core.view().active), "Restore", err);
return false;
};
defer st.gpa.free(bytes);
const replacement = dump.restore(st.core, bytes, path) catch |err| {
- st.core.reportError(st.core.view().active, "Restore", err);
+ st.core.reportError(.at(st.core.view().active), "Restore", err);
return false;
};
if (st.inbox.lsp_task) |*task| {
@@ -1648,15 +1648,16 @@ fn hostState(ctx: ?*anyopaque) *State {
return @ptrCast(@alignCast(ctx.?));
}
-fn spawnShell(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void {
+fn spawnShell(ctx: ?*anyopaque, id: pardes.Pane.Id, cwd: []const u8) void {
+ const pane = id.index();
const st = hostState(ctx);
const core = st.core;
// The new shell starts before a running one goes: one that cannot
// start leaves the running one be (pty/ctl's exec).
const running = st.ptys[pane] != null;
const child = host_io.forkShell(core, pane, &st.prompt_rcs, core.shellBin(), cwd, core.view().screen_h, core.view().screen_w) catch |err| {
- if (running) return core.restartFailed(pane, err);
- return core.shellFailed(pane, err);
+ if (running) return core.restartFailed(id, err);
+ return core.shellFailed(id, err);
};
reap(st, pane);
st.gens[pane] +%= 1;
@@ -1673,54 +1674,61 @@ fn spawnShell(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void {
// 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| core.setCwd(pane, wd);
+ if (cwd.len == 0) if (host_io.shellCwd(child.pid, &lbuf)) |wd| core.setCwd(id, wd);
if (st.started) if (st.ptys[pane]) |*pt| startReader(st, pt, pane);
}
-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 st = hostState(ctx);
if (st.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 st = hostState(ctx);
const pt = st.ptys[pane] orelse return;
const ws: posix.winsize = .{ .row = rows, .col = cols, .xpixel = 0, .ypixel = 0 };
_ = posix.system.ioctl(pt.file.handle, TIOCSWINSZ, @intFromPtr(&ws));
}
-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 st = hostState(ctx);
// A command whose exit is recorded is reaped: its group may be another's.
if (st.ptys[pane]) |pt| if (!pt.cmd.exited) host_io.signalTty(pt.pid, pt.file.handle, 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 st = hostState(ctx);
const pt = st.ptys[pane] orelse return false;
return host_io.ttyTaken(pt.pid, pt.file.handle);
}
-fn killJob(ctx: ?*anyopaque, pane: u8) bool {
+fn killJob(ctx: ?*anyopaque, id: pardes.Pane.Id) bool {
+ const pane = id.index();
const st = hostState(ctx);
const pt = st.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 st = hostState(ctx);
filesystem.write(st.core, path, bytes) catch |err|
- return st.core.saveFailed(pane, path, err);
+ return st.core.saveFailed(id, path, err);
st.file_watches.restampText(pane, path, std.hash.Wyhash.hash(0, bytes));
var mbuf: [256]u8 = undefined;
- st.core.setMessage(pane, message.stamp(&mbuf, "saved", path));
+ st.core.setMessage(id, message.stamp(&mbuf, "saved", path));
}
fn writeDump(ctx: ?*anyopaque, bytes: []const u8) void {
host_io.writeDump(hostState(ctx).core, bytes);
}
-fn watchFile(ctx: ?*anyopaque, pane: u8, path: []const u8, on: bool, mode: pardes.WatchMode) void {
+fn watchFile(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, on: bool, mode: pardes.WatchMode) void {
+ const pane = id.index();
const st = hostState(ctx);
if (!on or path.len == 0) {
const generation = st.file_watches.stop(st.gpa, pane);
@@ -1735,16 +1743,16 @@ fn watchTheme(ctx: ?*anyopaque, generation: u32, on: bool) void {
setThemeFileWatch(st, generation, on);
}
-fn dumpThemes(ctx: ?*anyopaque, pane: u8) void {
+fn dumpThemes(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
const st = hostState(ctx);
const config_dir = st.core.opts.config_dir orelse return;
const out_dir = pardes.config.User.dumpThemes(st.io, st.gpa, config_dir, pardes.themes) catch |err| {
- st.core.reportError(pane, "dump themes", err);
+ st.core.reportError(id, "dump themes", err);
return;
};
defer st.gpa.free(out_dir);
var mbuf: [256]u8 = undefined;
- st.core.setMessage(pane, message.stamp(&mbuf, "dumped themes", out_dir));
+ st.core.setMessage(id, message.stamp(&mbuf, "dumped themes", out_dir));
}
fn setClipboard(ctx: ?*anyopaque, text: []const u8) void {
@@ -1764,14 +1772,15 @@ fn openLink(_: ?*anyopaque, url: []const u8) void {
}
fn startReader(st: *State, pt: *Pty, id: u8) void {
- pt.reader = st.inbox.startReader(pt.file, id, pt.gen) catch |err| {
+ pt.reader = st.inbox.startReader(pt.file, .at(id), pt.gen) catch |err| {
log.err("pane {d} has no reader ({t}); it will not show output", .{ id, err });
return;
};
}
/// The pane is gone: its shell goes with it.
-fn closePty(ctx: ?*anyopaque, pane: u8) void {
+fn closePty(ctx: ?*anyopaque, id: pardes.Pane.Id) void {
+ const pane = id.index();
const st = hostState(ctx);
if (st.ptys[pane] == null) return;
reap(st, pane);
@@ -1782,7 +1791,7 @@ fn reap(st: *State, pane: u8) void {
var pt = st.ptys[pane] orelse return;
st.ptys[pane] = null;
// The inbox first: a reader waiting for space there wakes and returns.
- st.inbox.cancelReader(pane, pt.gen);
+ st.inbox.cancelReader(.at(pane), pt.gen);
pt.reader.cancel(st.io);
_ = libc.close(pt.file.handle);
host_io.retireShell(pt.pid);
diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig
index 6ee5d29c..77928dd0 100644
--- a/runtime/upgrade.zig
+++ b/runtime/upgrade.zig
@@ -77,7 +77,7 @@ fn inodeOf(path: [:0]const u8) ?u64 {
/// rebuilding (a stat). ponytail: explicit only, no watch and no automatic
/// upgrade.
pub fn noticeNewer(core: *pardes.Pardes) void {
- if (newer()) core.setMessage(core.view().active, pardes.newer_build_words);
+ if (newer()) core.setMessage(.at(core.view().active), pardes.newer_build_words);
}
/// Whether to say a newer build is installed now (`noticeNewer`): the
@@ -413,7 +413,7 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op
// keep its blocks for as long as this session runs.
if (rec.old >= 0) _ = libc.close(rec.old);
rec.old = -1;
- p.setMessage(p.view().active, if (rec.refused.len > 0)
+ p.setMessage(.at(p.view().active), if (rec.refused.len > 0)
std.fmt.bufPrint(&buf, "Upgrade: the new build could not load this session ({s}); it goes on as {s}", .{ rec.refused[0..@min(rec.refused.len, 200)], version_line }) catch "Upgrade: the new build could not load this session; it goes on as before"
else
"Upgrade: now " ++ version_line);
@@ -435,7 +435,7 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op
var o = opts;
o.load_path = null;
const p = try pardes.Pardes.init(core_gpa, o);
- p.setMessage(p.view().active, std.fmt.bufPrint(&buf, "Upgrade: no build could load the session ({s}); its shells are here, and Restore {s} brings the rest back", .{ why, again_name[0..@min(again_name.len, 400)] }) catch "Upgrade: no build could load the session; its dump is kept for a Restore");
+ p.setMessage(.at(p.view().active), std.fmt.bufPrint(&buf, "Upgrade: no build could load the session ({s}); its shells are here, and Restore {s} brings the rest back", .{ why, again_name[0..@min(again_name.len, 400)] }) catch "Upgrade: no build could load the session; its dump is kept for a Restore");
return p;
}
}