diff options
Diffstat (limited to 'core/Pipe.zig')
| -rw-r--r-- | core/Pipe.zig | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/core/Pipe.zig b/core/Pipe.zig index 012ce689..70d551d0 100644 --- a/core/Pipe.zig +++ b/core/Pipe.zig @@ -88,14 +88,10 @@ pub const PendingPipe = struct { } }; +/// The notice band's pipe prompt answered (a tag's text, a header's). pub fn submitPipe(p: *Pardes, id: usize) void { const pane = p.panes[id] orelse return; const t = panes.promptTarget(p, pane) orelse return; - if (t.what == .body) { - const f = pane.file orelse return; - if (!panes.Output.fileTraits(f.output).saves) return; - } - const content = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(id), "pipe", err); const how = switch (pane.prompt) { .pipe => |pipe| pipe, else => return, @@ -103,7 +99,18 @@ pub fn submitPipe(p: *Pardes, id: usize) void { const armed = pane.promptText() orelse return; const marker = pipeMarker(how); if (!std.mem.startsWith(u8, armed, marker)) return; - const command = armed[marker.len..]; + submit(p, id, t, how, armed[marker.len..]); +} + +/// Pipe text `t` of pane `id` through `command`, `how` says: one run per +/// selection, off the loop. +pub fn submit(p: *Pardes, id: usize, t: *Text, how: modal.Normal.PipeBehavior, command: []const u8) void { + const pane = p.panes[id] orelse return; + if (t.what == .body) { + const f = pane.file orelse return; + if (!panes.Output.fileTraits(f.output).saves) return; + } + const content = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(id), "pipe", err); if (command.len == 0) return; var ranges: [panes.Text.max_selections]modal.Selection = undefined; @@ -344,12 +351,11 @@ test "selection pipe prompt submits exact request and Escape cancels" { pane.body.vsel = .{ .active = true, .row = 0, .col = 0, .explicit = true }; p.update(.{ .key = .{ .cp = '|' } }); - try std.testing.expect(pane.focus == .body and pane.prompt == .pipe); - try std.testing.expectEqualStrings(config.pipe_marker, pane.promptText().?); + try std.testing.expect(pane.focus == .body and p.view().tag_state.kind == .prompt); try std.testing.expect(nextPipeEffect(p) == null); p.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); p.update(.{ .key = .{ .cp = Key.enter } }); - try std.testing.expect(pane.focus == .body and pane.prompt != .pipe and pane.input.own == null); + try std.testing.expect(pane.focus == .body and p.view().tag_state.kind == .rest); const id = nextPipeEffect(p) orelse return error.MissingPipeEffect; const request = p.pipe.pipeRequest(id) orelse return error.MissingPipeRequest; try std.testing.expectEqualStrings("tr a-z A-Z", request.command); @@ -361,7 +367,7 @@ test "selection pipe prompt submits exact request and Escape cancels" { p.update(.{ .key = .{ .cp = '|' } }); p.update(.{ .key = .{ .cp = 'c', .text = "cat" } }); p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expect(pane.focus == .body and pane.prompt != .pipe); + try std.testing.expect(pane.focus == .body and p.view().tag_state.kind == .rest); try std.testing.expectEqualSlices(u8, before, pane.file.?.content); try std.testing.expect(nextPipeEffect(p) == null); } @@ -404,7 +410,7 @@ test "$ keeps the selections the command exits 0 on, and a real shell gives that }; pane.body.setRanges(config.tab_width, pane.file.?.content, &ranges, &.{}, 1, true); p.update(.{ .key = .{ .cp = '$' } }); - try std.testing.expectEqualStrings(config.pipe_marker_keep, pane.promptText().?); + try std.testing.expectEqual(pardes.Prompt.Op.keep_pipe, p.view().tag_state.prompt.op); p.update(.{ .key = .{ .cp = 'g', .text = "grep -v b" } }); p.update(.{ .key = .{ .cp = Key.enter } }); const id = nextPipeEffect(p) orelse return error.MissingPipeEffect; @@ -663,10 +669,10 @@ test "selection pipe binding is file-normal-only" { pane.file.?.output = .{ .from = .search }; p.update(.{ .key = .{ .cp = '|' } }); - try std.testing.expect(pane.prompt != .pipe); + try std.testing.expect(p.view().tag_state.kind != .prompt); pane.file.?.output = null; pane.body.mode = .insert; p.update(.{ .key = .{ .cp = '|', .text = "|" } }); - try std.testing.expect(pane.prompt != .pipe); + try std.testing.expect(p.view().tag_state.kind != .prompt); try std.testing.expectEqualSlices(u8, "|x", pane.file.?.content); } |
