From 7c299a78d72274a2c101f5da0be4114f7c4dc4f3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 23:33:30 -0300 Subject: selection_pipe, Pipe, edit_cmd: a pipe's inputs are plain byte slices, not a one-field Input struct, dupeAll takes them concretely (no anytype, no length argument), and an Edit's request leaves the single command and cwd empty, which runJob never reads when every input has its own Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/Pipe.zig | 16 ++++++++-------- src/edit_cmd.zig | 10 +++++----- src/selection_pipe.zig | 29 +++++++++++++---------------- test/panes.zig | 2 +- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/Pipe.zig b/src/Pipe.zig index f53a353d..af500665 100644 --- a/src/Pipe.zig +++ b/src/Pipe.zig @@ -74,7 +74,7 @@ pub const PendingPipe = struct { arena: std.heap.ArenaAllocator, command: []u8, cwd: []u8, - inputs: []selection_pipe.Input, + inputs: [][]const u8, ranges: [panes.Text.max_selections]modal.Selection, primary: u16, explicit: bool, @@ -120,13 +120,13 @@ pub fn submitPipe(p: *Pardes, id: usize) void { const ninputs = if (how.pipes()) got.n else 1; var arena_state: std.heap.ArenaAllocator = .init(p.gpa); const arena = arena_state.allocator(); - const inputs = arena.alloc(selection_pipe.Input, ninputs) catch return arena_state.deinit(); + const inputs = arena.alloc([]const u8, ninputs) catch return arena_state.deinit(); for (ranges[0..ninputs], inputs) |range, *input| { const lo = @min(range.anchor, range.head); const hi = @max(range.anchor, range.head); if (how.pipes() and hi > content.len) return arena_state.deinit(); const bytes = if (how.pipes()) content[lo..hi] else ""; - input.* = .{ .bytes = arena.dupe(u8, bytes) catch return arena_state.deinit() }; + input.* = arena.dupe(u8, bytes) catch return arena_state.deinit(); } // `$` wants a verdict per selection where the runner's is all or // nothing: the command runs in a subshell whose exit status becomes the @@ -346,7 +346,7 @@ test "selection pipe prompt submits exact request and Escape cancels" { try std.testing.expectEqualStrings("tr a-z A-Z", request.command); try std.testing.expectEqualStrings("/", request.cwd); try std.testing.expectEqual(@as(usize, 1), request.inputs.len); - try std.testing.expectEqualSlices(u8, "one", request.inputs[0].bytes); + try std.testing.expectEqualSlices(u8, "one", request.inputs[0]); const before = pane.file.?.content; p.update(.{ .key = .{ .cp = '|' } }); @@ -373,7 +373,7 @@ test "| in a tag pipes the tag's own text, and undo there brings it back" { const id = nextPipeEffect(p) orelse return error.MissingPipeEffect; const request = p.pipe.pipeRequest(id) orelse return error.MissingPipeRequest; try std.testing.expectEqual(@as(usize, 1), request.inputs.len); - try std.testing.expectEqualSlices(u8, "Save", request.inputs[0].bytes); + try std.testing.expectEqualSlices(u8, "Save", request.inputs[0]); const outputs: []const []const u8 = &.{"SAVE"}; p.update(.{ .pipe_resp = .{ .id = id, .success = true, .outputs = outputs } }); try std.testing.expect(std.mem.startsWith(u8, pardes.tagline.curTail(pane), " SAVE ")); @@ -437,8 +437,8 @@ test "selection pipe replaces all ranges atomically and undo restores them" { const id = nextPipeEffect(p) orelse return error.MissingPipeEffect; const request = p.pipe.pipeRequest(id) orelse return error.MissingPipeRequest; try std.testing.expectEqual(@as(usize, 2), request.inputs.len); - try std.testing.expectEqualSlices(u8, "aa", request.inputs[0].bytes); - try std.testing.expectEqualSlices(u8, "cc", request.inputs[1].bytes); + try std.testing.expectEqualSlices(u8, "aa", request.inputs[0]); + try std.testing.expectEqualSlices(u8, "cc", request.inputs[1]); var denied = std.testing.FailingAllocator.init(gpa, .{ .fail_index = 0 }); p.scratch.deinit(); @@ -510,7 +510,7 @@ test "a command with no stdin runs once and every cursor gets that one answer" { const request = p.pipe.pipeRequest(id) orelse return error.MissingPipeRequest; try std.testing.expectEqual(@as(usize, 1), request.inputs.len); - try std.testing.expectEqualSlices(u8, "", request.inputs[0].bytes); + try std.testing.expectEqualSlices(u8, "", request.inputs[0]); p.update(.{ .pipe_resp = .{ .id = id, .success = true, .outputs = &.{"T"} } }); try std.testing.expectEqualSlices(u8, "Taa bb Tcc\n", pane.file.?.content); diff --git a/src/edit_cmd.zig b/src/edit_cmd.zig index 9542f4a9..876c6157 100644 --- a/src/edit_cmd.zig +++ b/src/edit_cmd.zig @@ -217,19 +217,19 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void { const n = res.jobs.len; const commands = arena.alloc([]const u8, n) catch |err| return p.reportError(id, "Edit", err); const cwds = arena.alloc([]const u8, n) catch |err| return p.reportError(id, "Edit", err); - const inputs = arena.alloc(selection_pipe.Input, n) catch |err| return p.reportError(id, "Edit", err); + const inputs = arena.alloc([]const u8, n) catch |err| return p.reportError(id, "Edit", err); for (res.jobs, 0..) |job, i| { const f = res.files[job.file]; commands[i] = job.command; cwds[i] = arena.dupe(u8, Pardes.paneDir(p.panes[f.id].?)) catch |err| return p.reportError(id, "Edit", err); - inputs[i] = .{ .bytes = if (job.c == '<') "" else arena.dupe(u8, f.text[job.q0..job.q1]) catch |err| return p.reportError(id, "Edit", err) }; + inputs[i] = if (job.c == '<') "" else arena.dupe(u8, f.text[job.q0..job.q1]) catch |err| return p.reportError(id, "Edit", err); } p.pipe.seq +%= 1; pd.id = p.pipe.seq; pd.request = .{ .id = pd.id, - .command = commands[0], - .cwd = cwds[0], + .command = "", + .cwd = "", .inputs = inputs, .commands = commands, .cwds = cwds, @@ -500,7 +500,7 @@ test "Edit , | sort runs off the loop, through the session's shell in the file's try testing.expectEqualStrings("b\na\nc\n", p.panes[0].?.file.?.content); const req = p.pipe.pipeRequest(p.pipe.edit_run.?.id).?; try testing.expectEqualStrings("sort", req.commands[0]); - try testing.expectEqualStrings("b\na\nc\n", req.inputs[0].bytes); + try testing.expectEqualStrings("b\na\nc\n", req.inputs[0]); try testing.expectEqualStrings("/", req.cwds[0]); try testing.expectEqualStrings(p.shellBin(), req.shell); // An Edit that would change the file being filtered is busy. diff --git a/src/selection_pipe.zig b/src/selection_pipe.zig index a03ab3eb..7832a75d 100644 --- a/src/selection_pipe.zig +++ b/src/selection_pipe.zig @@ -16,8 +16,6 @@ pub const max_total_stdout_bytes: usize = 4 * 1024 * 1024; pub const max_stderr_bytes: usize = 64 * 1024; pub const command_timeout_seconds: u64 = 10; -pub const Input = struct { bytes: []const u8 }; - /// Borrowed view exposed by the core while an effect is being drained. /// An Edit's `<`, `|` and `>` (src/edit_cmd.zig) run a command of their own /// per input, each in its file's directory: `commands` and `cwds`, when @@ -27,7 +25,7 @@ pub const Request = struct { id: u32, command: []const u8, cwd: []const u8, - inputs: []const Input, + inputs: []const []const u8, commands: []const []const u8 = &.{}, cwds: []const []const u8 = &.{}, shell: []const u8 = "", @@ -66,30 +64,29 @@ pub const Job = struct { errdefer gpa.free(job.command); job.cwd = try gpa.dupe(u8, filesystem.localPath(request.cwd) orelse request.cwd); errdefer gpa.free(job.cwd); - job.inputs = try dupeAll(gpa, request.inputs.len, request.inputs, false); + job.inputs = try dupeAll(gpa, request.inputs, false); errdefer freeAll(gpa, job.inputs); - job.commands = try dupeAll(gpa, request.commands.len, request.commands, false); + job.commands = try dupeAll(gpa, request.commands, false); errdefer freeAll(gpa, job.commands); - job.cwds = try dupeAll(gpa, request.cwds.len, request.cwds, true); + job.cwds = try dupeAll(gpa, request.cwds, true); errdefer freeAll(gpa, job.cwds); job.shell = try gpa.dupe(u8, request.shell); errdefer gpa.free(job.shell); - job.env = try dupeAll(gpa, request.env.len, request.env, false); + job.env = try dupeAll(gpa, request.env, false); return job; } - /// Owned copies of `items` (Inputs or strings); a directory as the - /// host's own path, as `cwd` is. - fn dupeAll(gpa: std.mem.Allocator, n: usize, items: anytype, dirs: bool) ![][]u8 { - const out = try gpa.alloc([]u8, n); + /// Owned copies of `items`; a directory as the host's own path, as + /// `cwd` is. + fn dupeAll(gpa: std.mem.Allocator, items: []const []const u8, dirs: bool) ![][]u8 { + const out = try gpa.alloc([]u8, items.len); var made: usize = 0; errdefer { for (out[0..made]) |item| gpa.free(item); gpa.free(out); } for (items) |item| { - const bytes: []const u8 = if (@TypeOf(item) == Input) item.bytes else item; - out[made] = try gpa.dupe(u8, if (dirs) filesystem.localPath(bytes) orelse bytes else bytes); + out[made] = try gpa.dupe(u8, if (dirs) filesystem.localPath(item) orelse item else item); made += 1; } return out; @@ -554,7 +551,7 @@ test "native selection filters use the physical directory of an explicit OS moun const directory = directory_buf[0..try tmp.dir.realPath(std.testing.io, &directory_buf)]; var declared_buf: [4102]u8 = undefined; const declared = try std.fmt.bufPrint(&declared_buf, "/n/os{s}", .{directory}); - const job = try Job.copy(gpa, .{ .id = 1, .command = "pwd", .cwd = declared, .inputs = &.{.{ .bytes = "" }} }); + const job = try Job.copy(gpa, .{ .id = 1, .command = "pwd", .cwd = declared, .inputs = &.{""} }); defer job.deinit(gpa); try std.testing.expectEqualStrings(directory, job.cwd); switch (runIn(gpa, std.testing.io, "", job.command, job.cwd, "", 0, &.{})) { @@ -619,7 +616,7 @@ test "a request may give each input its own command and directory, run by the sh .id = 3, .command = "", .cwd = "", - .inputs = &.{ .{ .bytes = "" }, .{ .bytes = "abc" } }, + .inputs = &.{ "", "abc" }, .commands = &.{ "pwd", "tr a-z A-Z" }, .cwds = &.{ "/tmp", "/" }, .shell = "/bin/sh", @@ -639,7 +636,7 @@ test "stop kills a running request's commands, the whole group, and starts none .id = 1, .command = "", .cwd = "", - .inputs = &.{ .{ .bytes = "" }, .{ .bytes = "" } }, + .inputs = &.{ "", "" }, .commands = &.{ "sleep 30; echo late", "echo never" }, .token = token, }); diff --git a/test/panes.zig b/test/panes.zig index 22fdd225..b111f5d1 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -1306,7 +1306,7 @@ test "a prompt owns the pipe behavior through cancellation and submission" { else try std.testing.expectEqualStrings("cat", pending.command); try std.testing.expectEqual(@as(usize, 1), pending.inputs.len); - try std.testing.expectEqualStrings(if (how.pipes()) "one" else "", pending.inputs[0].bytes); + try std.testing.expectEqualStrings(if (how.pipes()) "one" else "", pending.inputs[0]); try std.testing.expect(pane.prompt == .none); } } -- cgit v1.3