summaryrefslogtreecommitdiff
path: root/src/normal_input.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/normal_input.zig')
-rw-r--r--src/normal_input.zig34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/normal_input.zig b/src/normal_input.zig
index 4b047a7f..5fa29bea 100644
--- a/src/normal_input.zig
+++ b/src/normal_input.zig
@@ -125,6 +125,9 @@ pub const Role = enum {
leader,
command_line,
pipe_selection,
+ pipe_selection_to,
+ insert_output,
+ append_output,
search,
search_next,
search_prev,
@@ -180,6 +183,27 @@ pub const State = struct {
}
};
+/// WHERE a filter's output goes, and whether the selection is its stdin.
+/// helix's `|`, `A-|`, `!` and `A-!` in one word each (commands.rs
+/// `ShellBehavior`); its `$` (keep selections by exit status) is not here yet
+/// because it needs a per-selection verdict rather than one atomic answer.
+pub const PipeBehavior = enum {
+ /// `|` — stdin is the selection, and the output REPLACES it.
+ replace,
+ /// `A-|` — stdin is the selection, and the output is discarded. The text
+ /// is not touched at all; the point is the command's side effect.
+ ignore,
+ /// `!` — no stdin, and the output is inserted BEFORE each selection.
+ insert,
+ /// `A-!` — no stdin, and the output is appended AFTER each selection.
+ append,
+
+ /// Do the selections become stdin? helix's `pipe` flag.
+ pub fn pipes(b: PipeBehavior) bool {
+ return b == .replace or b == .ignore;
+ }
+};
+
pub const Scope = enum { once, per_selection };
pub const Direction = enum { backward, forward };
pub const Motion = enum {
@@ -286,7 +310,10 @@ pub const Action = union(enum) {
adjust_number: i64,
leader,
command_line,
- pipe_selection,
+ /// helix's five shell commands are one action with a behaviour, because
+ /// they differ only in where the output lands and whether the selection is
+ /// stdin. See `PipeBehavior`.
+ pipe_selection: PipeBehavior,
search,
search_step: Direction,
@@ -548,7 +575,10 @@ pub fn parse(state: *State, key: Input) Result {
if (key.has(.leader)) return resultAction(.leader);
if (key.has(.command_line)) return resultAction(.command_line);
- if (key.has(.pipe_selection)) return resultAction(.pipe_selection);
+ if (key.has(.pipe_selection)) return resultAction(.{ .pipe_selection = .replace });
+ if (key.has(.pipe_selection_to)) return resultAction(.{ .pipe_selection = .ignore });
+ if (key.has(.insert_output)) return resultAction(.{ .pipe_selection = .insert });
+ if (key.has(.append_output)) return resultAction(.{ .pipe_selection = .append });
if (key.has(.search)) return resultAction(.search);
if (key.has(.search_next)) return resultAction(.{ .search_step = .forward });
if (key.has(.search_prev)) return resultAction(.{ .search_step = .backward });