summaryrefslogtreecommitdiff
path: root/src/exec.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/exec.zig')
-rw-r--r--src/exec.zig37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/exec.zig b/src/exec.zig
index 35d081fd..8e96be80 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -29,19 +29,6 @@ const Key = pardes.Key;
const sel_slot = pardes.sel_slot;
const Pardes = pardes.Pardes;
-pub fn takesCommandLine(p: *const Pardes, id: usize) bool {
- const pane = p.panes[id] orelse return false;
- // A command pane's child is its command, never a shell to type at.
- if (!pane.isTerminal() or pane.command != null) return false;
- // Someone's line at the shell's prompt, typed and not sent: typing a
- // command there would run it joined to theirs (`echo TYPEDls`). Only an
- // idle, EMPTY prompt is typed at; otherwise a new pane runs the line.
- // (Text in pardes's own edit buffer is not the shell's yet: an exec of
- // it, or of anything, types only what it runs.)
- if (panes.terminal.promptInputReady(pane) and !panes.terminal.promptInputEmpty(pane)) return false;
- return !p.hostTtyTaken(id);
-}
-
pub fn chordEachSel(p: *Pardes, pane: *Pane, cmd: Builtin) bool {
const v = p.view();
if (pane.body.nsel == 0) return false;
@@ -106,6 +93,13 @@ pub fn currentOperand(p: *Pardes, pane: *Pane) ?[]const u8 {
return operandAt(p, pane, look.cursorWordSel(p, pane), false, true).text;
}
+fn spanHas(r: i32, c: i32, ar: i32, ac: i32, br: i32, bc: i32) bool {
+ const fwd = ar < br or (ar == br and ac <= bc);
+ const sr, const sc = if (fwd) .{ ar, ac } else .{ br, bc };
+ const er, const ec = if (fwd) .{ br, bc } else .{ ar, ac };
+ return (r > sr or (r == sr and c >= sc)) and (r < er or (r == er and c <= ec));
+}
+
/// What a look or an exec at `clicked` takes: the ONE expansion every
/// entry point uses (a B2/B3 click, Enter and Tab in normal mode, a bare
/// Look), so a diff line, a hunk line's code word and a file word expand
@@ -158,14 +152,14 @@ pub fn operandAt(p: *Pardes, pane: *Pane, clicked: Pane.Sel, borrow: bool, for_l
break :inside true;
}
break :inside false;
- } else edit.spanHas(clicked.r0, clicked.c0, kept.r0, kept.c0, kept.r1, kept.c1);
+ } else spanHas(clicked.r0, clicked.c0, kept.r0, kept.c0, kept.r1, kept.c1);
if (kept.state == .done and inside_kept) {
result.text = edit.selectionText(p, pane, kept) catch null;
result.preview = kept;
return result;
}
if (pane.body.vsel.active and pane.body.vsel.explicit and
- edit.spanHas(row, col, pane.body.vsel.row, pane.body.vsel.col, pane.body.cur_row, pane.body.cur_col))
+ spanHas(row, col, pane.body.vsel.row, pane.body.vsel.col, pane.body.cur_row, pane.body.cur_col))
{
result.text = edit.currentSelText(p, pane);
return result;
@@ -660,6 +654,19 @@ pub fn isComment(line: []const u8) bool {
return t.len > 0 and t[0] == '#';
}
+pub fn takesCommandLine(p: *const Pardes, id: usize) bool {
+ const pane = p.panes[id] orelse return false;
+ // A command pane's child is its command, never a shell to type at.
+ if (!pane.isTerminal() or pane.command != null) return false;
+ // Someone's line at the shell's prompt, typed and not sent: typing a
+ // command there would run it joined to theirs (`echo TYPEDls`). Only an
+ // idle, EMPTY prompt is typed at; otherwise a new pane runs the line.
+ // (Text in pardes's own edit buffer is not the shell's yet: an exec of
+ // it, or of anything, types only what it runs.)
+ if (panes.terminal.promptInputReady(pane) and !panes.terminal.promptInputEmpty(pane)) return false;
+ return !p.hostTtyTaken(id);
+}
+
/// `execute` for text a gesture took from `id`'s body when `from_body`:
/// such text may be a bound REPL's. Run by name (`Exec ...`, whose line
/// comes back through `execute`) or written as a command word, never.