diff options
Diffstat (limited to 'dev/host_io.zig')
| -rw-r--r-- | dev/host_io.zig | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/dev/host_io.zig b/dev/host_io.zig index 2ee7c47e..f86c3250 100644 --- a/dev/host_io.zig +++ b/dev/host_io.zig @@ -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`). @@ -99,7 +99,7 @@ pub const Adoptions = struct { a.list[a.len] = .{ .pid = pid, .fd = fd, .pane = null }; a.len += 1; if (core.adoptShell()) |id| { - a.list[a.len - 1].pane = id.index(); + a.list[a.len - 1].pane = id; a.taken += 1; return; } @@ -112,7 +112,7 @@ pub const Adoptions = struct { } /// 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; @@ -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); } @@ -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); |
