diff options
Diffstat (limited to 'dev/tui')
| -rw-r--r-- | dev/tui/tui.zig | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 48b5d3d1..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; @@ -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); @@ -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(.at(pane), err); - return s.core.shellFailed(.at(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(.at(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,7 +2060,7 @@ 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 = .{} }; @@ -2067,18 +2070,20 @@ const Shell = struct { 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); } @@ -2185,7 +2198,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(.at(req.pane), "lsp", error.WorkersUnavailable); + return s.core.reportError(req.pane, "lsp", error.WorkersUnavailable); } host_io.Lsp.start(s.io, s.lsp_gpa, s.core, &s.lsp_task, req, s, deliverLspRows); } @@ -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; |
