summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/Lsp.zig4
-rw-r--r--dev/file_watch.zig16
-rw-r--r--dev/gui/gui.zig30
-rw-r--r--dev/host_io.zig20
-rw-r--r--dev/tui/tui.zig24
5 files changed, 47 insertions, 47 deletions
diff --git a/dev/Lsp.zig b/dev/Lsp.zig
index edc99eeb..d7f11bfe 100644
--- a/dev/Lsp.zig
+++ b/dev/Lsp.zig
@@ -118,12 +118,12 @@ pub fn start(io: std.Io, gpa: std.mem.Allocator, core: *pardes.Pardes, task: *?T
}
const job = snapshot(gpa, core, req) catch |err| {
core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } });
- return core.reportError(req.pane, "lsp", err);
+ return core.reportError(.at(req.pane), "lsp", err);
};
const future = io.concurrent(work, .{ io, gpa, job, ctx, deliver }) catch |err| {
job.free(gpa);
core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } });
- return core.reportError(req.pane, "lsp", err);
+ return core.reportError(.at(req.pane), "lsp", err);
};
task.* = .{ .id = req.id, .future = future };
}
diff --git a/dev/file_watch.zig b/dev/file_watch.zig
index 9d868e07..a02ad272 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;
}
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index 798368e3..3d050bbf 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -2548,7 +2548,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;
}
@@ -2680,7 +2680,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));
}
}
@@ -2759,7 +2759,7 @@ const Shell = struct {
if (s.gens[e.pane] == e.gen) eof: {
if (e.failure) |err| {
s.closePty(e.pane);
- s.core.readerFailed(e.pane, err);
+ s.core.readerFailed(.at(e.pane), err);
break :eof;
}
const pt = if (s.ptys[e.pane]) |*pt| pt else {
@@ -2789,7 +2789,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| {
@@ -3334,25 +3334,25 @@ fn spawnPane(ctx: ?*anyopaque, pane: u8, cwd: []const u8) void {
// 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(.at(pane), err);
+ return s.core.shellFailed(.at(pane), 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(.at(pane), "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(.at(pane), 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.closePty(pane);
- return s.core.reportError(pane, "terminal reader", err);
+ return s.core.reportError(.at(pane), "terminal reader", err);
};
}
@@ -3363,16 +3363,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.threads_ok) return;
s.ptys[pane].?.reader = s.queue.startReader(.{ .handle = a.fd, .flags = .{ .nonblocking = false } }, 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);
};
}
@@ -3501,14 +3501,14 @@ fn lsp(ctx: ?*anyopaque, req: host_io.Lsp.Request) void {
const s = shellOf(ctx);
if (s.threads_ok) return s.queue.startLsp(s.core, req);
s.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } });
- s.core.reportError(req.pane, "lsp", error.WorkersUnavailable);
+ s.core.reportError(.at(req.pane), "lsp", error.WorkersUnavailable);
}
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.
@@ -3579,7 +3579,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);
};
}
diff --git a/dev/host_io.zig b/dev/host_io.zig
index 377263a4..2ee7c47e 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);
@@ -93,13 +93,13 @@ 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 };
a.len += 1;
if (core.adoptShell()) |id| {
- a.list[a.len - 1].pane = id;
+ a.list[a.len - 1].pane = id.index();
a.taken += 1;
return;
}
@@ -108,7 +108,7 @@ 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.
@@ -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 };
}
@@ -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 {
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index 70ea3295..48b5d3d1 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -1500,7 +1500,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 +1673,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 => {},
}
@@ -1807,7 +1807,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 +1851,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 +1885,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;
@@ -2035,8 +2035,8 @@ const Shell = struct {
// 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(.at(pane), err);
+ return s.core.shellFailed(.at(pane), err);
};
closePty(ctx, pane); // a shell still in the slot goes, reaped
s.gens[pane] +%= 1;
@@ -2046,7 +2046,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(.at(pane), 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;
@@ -2062,9 +2062,9 @@ const Shell = struct {
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));
@@ -2185,7 +2185,7 @@ const Shell = struct {
const s = of(ctx);
if (!s.threads_ok) {
s.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } });
- return s.core.reportError(req.pane, "lsp", error.WorkersUnavailable);
+ return s.core.reportError(.at(req.pane), "lsp", error.WorkersUnavailable);
}
host_io.Lsp.start(s.io, s.lsp_gpa, s.core, &s.lsp_task, req, s, deliverLspRows);
}
@@ -2199,7 +2199,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);
}