diff options
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/macos.zig | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/runtime/macos.zig b/runtime/macos.zig index 3a00210d..408915da 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -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| { @@ -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(.at(pane), err); - return core.shellFailed(.at(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(.at(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(.at(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(.at(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(.at(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(.at(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); |
