summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--abi/wire.zig5
-rw-r--r--core/Band.zig8
-rw-r--r--core/Core.zig3
-rw-r--r--core/Pipe.zig32
-rw-r--r--core/Prompt.zig533
-rw-r--r--core/TagState.zig13
-rw-r--r--core/body_layer.zig7
-rw-r--r--core/draw.zig1
-rw-r--r--core/edit.zig9
-rw-r--r--core/keys.zig13
-rw-r--r--core/lib_editor.zig2
-rw-r--r--core/look.zig3
-rw-r--r--core/normal.zig48
-rw-r--r--core/panes.zig16
-rw-r--r--core/root.zig2
-rw-r--r--test/behaviour/keys.zig18
-rw-r--r--test/daemon.py2
-rw-r--r--test/snapshots/msg.golden14
-rw-r--r--test/snapshots/pipe.golden6
-rw-r--r--test/snapshots/selregex.golden27
20 files changed, 685 insertions, 77 deletions
diff --git a/abi/wire.zig b/abi/wire.zig
index d07e6a57..cbe255f4 100644
--- a/abi/wire.zig
+++ b/abi/wire.zig
@@ -10,6 +10,9 @@ const pardes = @import("core");
const config = @import("pardes_options");
const build_info = @import("build_info");
+/// 37: a view's text prompt in its tag (walk UI: `TagState.prompt`, which
+/// prompt, its history's place, what its field found) and the session's
+/// prompt histories (`prompt_history`) in the dump and the digest;
/// 36: a view's tag out of rest (walk UI: `View.tag_state`, its root's
/// delay, its level unrolled and that level's cursor, the leaf each group
/// ran last) in the dump and the digest; a pointer's tag hit may be on a
@@ -80,7 +83,7 @@ const build_info = @import("build_info");
/// part B); 14: the hello names a session and
/// carries the semantics hash, and a ping is answered (phase 5's
/// groundwork); 13: the frames went (phase 3).
-pub const version: u16 = 36;
+pub const version: u16 = 37;
/// The terminal's build and the window's step alike (`semantics`).
const family = switch (config.platform) {
diff --git a/core/Band.zig b/core/Band.zig
index 079a1bcc..7f9cfc7b 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -27,6 +27,7 @@ const panes = @import("panes.zig");
const builtins = @import("builtins.zig");
const TagState = @import("TagState.zig");
const Names = @import("Names.zig");
+const Prompt = @import("Prompt.zig");
const Pardes = pardes.Pardes;
const Pane = pardes.Pane;
const File = panes.File;
@@ -89,6 +90,7 @@ pub fn takes(p: *Pardes, id: usize) u16 {
.rest => {},
.help => return @max(doc_rows, @max(1, @min(Cursor.shown, s.nhits))),
.describe => return 0,
+ .prompt => return Prompt.takes(p),
}
if (!s.unrolled) return 0;
const cur = TagState.current(p, v) orelse return 0;
@@ -117,6 +119,12 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band {
return band;
},
.describe => return null,
+ .prompt => {
+ var steps: [max_steps]Step = undefined;
+ for (try Prompt.steps(p, arena, &steps)) |step| band.add(step);
+ try band.place(p, arena, pane, id);
+ return band;
+ },
}
const cur = TagState.current(p, v).?;
// The level, its cursor on the child it names, else the leaf its group
diff --git a/core/Core.zig b/core/Core.zig
index 11f254ab..987c4f85 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -437,6 +437,9 @@ in_head: usize = 0,
in_len: usize = 0,
registers: Registers = .{},
+/// The text prompts' histories (Prompt.zig): search and select's, the
+/// pipes', the command line's.
+prompt_history: pardes.Prompt.History = .{},
macro: Macro = .{},
/// an edited text nothing kept (a tag's shown text): see edit.retireEditText
retired_edit: ?[]u8 = null,
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);
}
diff --git a/core/Prompt.zig b/core/Prompt.zig
new file mode 100644
index 00000000..e5fac06c
--- /dev/null
+++ b/core/Prompt.zig
@@ -0,0 +1,533 @@
+//! A text prompt in a pane's tag (walk UI, pick-ui SPEC.md §7): `s S K A-K`
+//! select by a pattern, `| A-| ! A-! $` pipe through a command, typed in
+//! the head's field after the prompt's key cell, the plain word it stands
+//! for and its count beside it (`s self = Exec Edit x/self/ 4 selections in
+//! 6 lines`), its effect drawn live in the body on every key; Enter applies
+//! it and keeps the line in its history, Esc puts the body back.
+//!
+//! A view's own (TagState.prompt, the coordinator's R4): its field the
+//! head's (TagState.field); its histories the session's, three of them
+//! (`/ ? s S K A-K` share one, the pipes another, `:` its own). A prompt for
+//! a tag's text or a header's still asks on the notice band (panes.zig
+//! startPrompt), as does Save's.
+const Prompt = @This();
+
+const std = @import("std");
+const pardes = @import("root.zig");
+const config = @import("config.zig");
+const modal = @import("modal.zig");
+const panes = @import("panes.zig");
+const normal = @import("normal.zig");
+const edit = @import("edit.zig");
+const regexp = @import("regexp.zig");
+const tagline = @import("tagline.zig");
+const Pipe = @import("Pipe.zig");
+const Field = @import("Field.zig");
+const Band = @import("Band.zig");
+const TagState = @import("TagState.zig");
+const Kind = @import("Kind.zig");
+const Pardes = pardes.Pardes;
+const Pane = panes.Pane;
+const Text = panes.Text;
+const Key = pardes.Key;
+const hit = pardes.hit;
+
+pub const Op = enum(u8) { search, search_back, select, split, keep, remove, pipe, pipe_to, insert, append, keep_pipe, command };
+
+op: Op = .select,
+/// Up and Down's place in its history: 0 the field as typed, n the n-th
+/// newest line.
+recall: u8 = 0,
+/// Ctrl-r: its history unrolled under the tag, filtered by the field.
+history: bool = false,
+/// The field is no regex: the body keeps the last result, dimmed, and the
+/// count says why.
+bad: bool = false,
+/// The ranges the last pattern found (0: none, the selections it started
+/// from back), and the lines those it started from cover.
+found: u16 = 0,
+scope: u32 = 0,
+
+/// The session's prompt histories: the lines Enter took, newest last.
+pub const History = struct {
+ search: Ring = .{},
+ pipe: Ring = .{},
+ command: Ring = .{},
+};
+
+pub const Ring = struct {
+ pub const replica = .{ .len = .{.{ "lines", "n" }} };
+ /// The lines a history keeps; past it the oldest goes.
+ pub const max = 16;
+ lines: [max]Kind.Buf(Field.max) = undefined,
+ n: u8 = 0,
+
+ /// `line` the newest, an older copy of it gone.
+ pub fn add(r: *Ring, line: []const u8) void {
+ if (line.len == 0) return;
+ var w: u8 = 0;
+ for (r.lines[0..r.n]) |l| if (!std.mem.eql(u8, l.slice(), line)) {
+ r.lines[w] = l;
+ w += 1;
+ };
+ r.n = w;
+ if (r.n == max) {
+ std.mem.copyForwards(Kind.Buf(Field.max), r.lines[0 .. max - 1], r.lines[1..]);
+ r.n -= 1;
+ }
+ r.lines[r.n].set(line);
+ r.n += 1;
+ }
+
+ /// The `back`-th newest line, 1 the newest.
+ pub fn get(r: *const Ring, back: u8) ?[]const u8 {
+ if (back == 0 or back > r.n) return null;
+ return r.lines[r.n - back].slice();
+ }
+};
+
+const Info = struct {
+ /// Its key cell.
+ cell: []const u8,
+ hint: []const u8,
+};
+
+const info = std.EnumArray(Op, Info).init(.{
+ .search = .{ .cell = "/", .hint = "⏎ land · C-r history · esc" },
+ .search_back = .{ .cell = "?", .hint = "⏎ land · C-r history · esc" },
+ .select = .{ .cell = "s", .hint = "⏎ select · C-r history · esc" },
+ .split = .{ .cell = "S", .hint = "⏎ select · C-r history · esc" },
+ .keep = .{ .cell = "K", .hint = "⏎ keep · C-r history · esc" },
+ .remove = .{ .cell = "A-K", .hint = "⏎ keep · C-r history · esc" },
+ .pipe = .{ .cell = "|", .hint = "⏎ replace · C-r history · esc" },
+ .pipe_to = .{ .cell = "A-|", .hint = "⏎ run · C-r history · esc" },
+ .insert = .{ .cell = "!", .hint = "⏎ insert · C-r history · esc" },
+ .append = .{ .cell = "A-!", .hint = "⏎ append · C-r history · esc" },
+ .keep_pipe = .{ .cell = "$", .hint = "⏎ keep · C-r history · esc" },
+ .command = .{ .cell = ":", .hint = "⏎ run · C-r history · esc" },
+});
+
+/// The history `op` reads and Enter adds to.
+fn ring(p: *Pardes, op: Op) *Ring {
+ return switch (op) {
+ .search, .search_back, .select, .split, .keep, .remove => &p.prompt_history.search,
+ .pipe, .pipe_to, .insert, .append, .keep_pipe => &p.prompt_history.pipe,
+ .command => &p.prompt_history.command,
+ };
+}
+
+pub fn ofMode(m: modal.Normal.RegexMode) Op {
+ return switch (m) {
+ .select => .select,
+ .split => .split,
+ .keep => .keep,
+ .remove => .remove,
+ };
+}
+
+fn mode(op: Op) ?modal.Normal.RegexMode {
+ return switch (op) {
+ .select => .select,
+ .split => .split,
+ .keep => .keep,
+ .remove => .remove,
+ else => null,
+ };
+}
+
+pub fn ofBehavior(how: modal.Normal.PipeBehavior) Op {
+ return switch (how) {
+ .replace => .pipe,
+ .ignore => .pipe_to,
+ .insert => .insert,
+ .append => .append,
+ .keep => .keep_pipe,
+ };
+}
+
+fn behavior(op: Op) ?modal.Normal.PipeBehavior {
+ return switch (op) {
+ .pipe => .replace,
+ .pipe_to => .ignore,
+ .insert => .insert,
+ .append => .append,
+ .keep_pipe => .keep,
+ else => null,
+ };
+}
+
+/// Prompt `op` in the tag of `pane`, the pane with the keyboard, for its
+/// body: its field empty, the body's selections as they are (`s S K A-K`
+/// select inside them, Esc puts them back).
+pub fn open(p: *Pardes, pane: *Pane, op: Op) void {
+ // Nobody is at the keyboard to answer a command a script wrote to a
+ // ctl file: the write fails instead (core/ninep/ctl.zig).
+ if (p.fs.no_prompt) {
+ p.fs.refused = true;
+ p.fs.failures +%= 1;
+ return;
+ }
+ const t = &pane.body;
+ // A body is piped only when it is a file that saves.
+ if (behavior(op) != null) {
+ const f = pane.file orelse return;
+ if (!panes.Output.fileTraits(f.output).saves) return;
+ }
+ var scope: u32 = 0;
+ if (mode(op) != null) {
+ const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(p.view().active), "prompt", err);
+ const got = t.ranges(text, 0, &pane.sel_snap);
+ pane.nsel_snap = @intCast(got.n);
+ pane.sel_snap_pri = @intCast(got.pri);
+ pane.sel_snap_expl = t.vsel.active and t.vsel.explicit;
+ for (pane.sel_snap[0..got.n]) |r| {
+ const lo = @min(r.anchor, r.head, text.len);
+ const hi = @min(@max(r.anchor, r.head), text.len);
+ scope += @intCast(std.mem.count(u8, text[lo..hi -| @intFromBool(hi > lo and text[hi - 1] == '\n')], "\n") + 1);
+ }
+ }
+ pane.focus = .body;
+ tagline.exitHeader(p);
+ t.mode = .normal;
+ t.normal.clear();
+ TagState.toRest(p);
+ const s = &p.view().tag_state;
+ s.kind = .prompt;
+ s.host = pane.serial;
+ s.field.clear();
+ s.rows = .{};
+ s.prompt = .{ .op = op, .scope = scope };
+}
+
+/// A key in the prompt of the live view's tag: the field's editing keys,
+/// and the prompt's own.
+pub fn key(p: *Pardes, k: Key) void {
+ const v = p.view();
+ const s = &v.tag_state;
+ const id = TagState.hostOf(p) orelse return TagState.toRest(p);
+ const pane = p.panes[id].?;
+ const plain = !k.ctrl and !k.alt;
+ const ctrl = k.ctrl and !k.alt;
+ if (hit(k, config.escape)) return cancel(p, pane);
+ if (plain and k.cp == Key.enter) return commit(p, id, pane);
+ // Backspace on an empty field: the prompt goes, as Esc.
+ if (plain and k.cp == Key.backspace and s.field.len == 0) return cancel(p, pane);
+ // Up and Down bring its history's lines into the field, the newest first.
+ if (plain and (k.cp == Key.up or k.cp == Key.down)) {
+ const r = ring(p, s.prompt.op);
+ const to: u8 = if (k.cp == Key.up) @min(r.n, s.prompt.recall + 1) else s.prompt.recall -| 1;
+ if (to == s.prompt.recall) return;
+ s.prompt.recall = to;
+ s.field.set(r.get(to) orelse "");
+ return live(p, pane);
+ }
+ if (ctrl and k.cp == 'r') {
+ s.prompt.history = !s.prompt.history;
+ return;
+ }
+ if (!s.field.key(k)) return;
+ s.prompt.recall = 0;
+ live(p, pane);
+}
+
+/// What the field says now, done to the body: the selections a pattern
+/// finds inside the ones the prompt began with; none, or no pattern, those
+/// it began with. A pattern that is no regex changes nothing, and the
+/// prompt says why.
+fn live(p: *Pardes, pane: *Pane) void {
+ const s = &p.view().tag_state;
+ const m = mode(s.prompt.op) orelse return;
+ const pat = s.field.text();
+ s.prompt.bad = pat.len > 0 and if (regexp.Regex.compile(pat)) |_| false else |_| true;
+ if (s.prompt.bad) return;
+ s.prompt.found = @intCast(normal.applySelRegex(p, pane, &pane.body, pat, m));
+}
+
+/// Enter: what the field says, applied, and the line kept in its history
+/// and its register (`/` a pattern's, `|` a command's).
+fn commit(p: *Pardes, id: usize, pane: *Pane) void {
+ const s = &p.view().tag_state;
+ const op = s.prompt.op;
+ const line = s.field.text();
+ // The field is the view's: what is kept of it is copied before rest.
+ var kept: [Field.max]u8 = undefined;
+ @memcpy(kept[0..line.len], line);
+ const typed = kept[0..line.len];
+ const bad = s.prompt.bad;
+ s.kind = .rest;
+ TagState.toRest(p);
+ if (typed.len == 0) return undo(p, pane, op);
+ ring(p, op).add(typed);
+ if (mode(op) != null) {
+ // No regex: the selections it began with, and why.
+ if (bad) {
+ undo(p, pane, op);
+ return p.setMessage(.at(id), regexMessage(typed));
+ }
+ // helix keeps the pattern in `/`
+ p.registers.put(p.gpa, '/', typed, 0, 1, true) catch |err| return p.reportError(.at(id), "prompt", err);
+ p.registers.last_search = '/';
+ return;
+ }
+ if (behavior(op)) |how| {
+ p.registers.put(p.gpa, '|', typed, 0, 1, true) catch |err| return p.reportError(.at(id), "prompt", err);
+ return Pipe.submit(p, id, &pane.body, how, typed);
+ }
+}
+
+/// Esc: the prompt goes and the body is as it was before it.
+fn cancel(p: *Pardes, pane: *Pane) void {
+ const op = p.view().tag_state.prompt.op;
+ p.view().tag_state.kind = .rest;
+ TagState.toRest(p);
+ undo(p, pane, op);
+}
+
+/// The live effect of prompt `op` on `pane`'s body taken back.
+fn undo(p: *Pardes, pane: *Pane, op: Op) void {
+ if (mode(op)) |m| _ = normal.applySelRegex(p, pane, &pane.body, "", m);
+ pane.nsel_snap = 0;
+}
+
+/// The prompt left by something else than its keys (TagState.toRest: a
+/// click, a word run from the band): its effect taken back, as Esc's.
+pub fn leave(p: *Pardes) void {
+ const s = &p.view().tag_state;
+ const pane = p.panes[TagState.hostOf(p) orelse return] orelse return;
+ s.kind = .rest;
+ undo(p, pane, s.prompt.op);
+}
+
+/// A paste into the field: its first line.
+pub fn paste(p: *Pardes, bytes: []const u8) void {
+ const s = &p.view().tag_state;
+ const pane = p.panes[TagState.hostOf(p) orelse return] orelse return;
+ const line = bytes[0 .. std.mem.indexOfAny(u8, bytes, "\r\n") orelse bytes.len];
+ s.field.insert(line[0..modal.graphemeStart(line, @min(line.len, Field.max - s.field.len))]);
+ s.prompt.recall = 0;
+ live(p, pane);
+}
+
+/// Whether `pane`'s body shows a selecting prompt's live result: its
+/// selections drawn as a preview (body_layer), dimmed while the field is
+/// no regex.
+pub fn selecting(p: *const Pardes, pane: *const Pane) ?struct { dim: bool } {
+ const s = &p.view().tag_state;
+ if (s.kind != .prompt or mode(s.prompt.op) == null or s.host != pane.serial) return null;
+ return .{ .dim = s.prompt.bad };
+}
+
+fn regexMessage(pat: []const u8) []const u8 {
+ return if (regexp.Regex.compile(pat)) |_| "" else |err| regexp.Regex.message(err);
+}
+
+/// The sam command a pattern prompt is (`s S K A-K` are sam's `x y g v`),
+/// its `/` written `\/`.
+fn samWord(w: *std.Io.Writer, c: u8, pat: []const u8) !void {
+ try w.print("{c}/", .{c});
+ for (pat) |b| if (b == '/') try w.writeAll("\\/") else try w.writeByte(b);
+ try w.writeByte('/');
+}
+
+/// The plain word prompt `op` with field `line` stands for: what Look or
+/// Exec would do typed in a tag. None for `! A-! $`, which sam cannot say.
+fn plainWord(w: *std.Io.Writer, op: Op, line: []const u8) !?[]const u8 {
+ switch (op) {
+ .search => try w.print("/{s}/", .{line}),
+ .search_back => try w.print("?{s}?", .{line}),
+ .select, .split, .keep, .remove => {
+ try w.writeAll("Edit ");
+ try samWord(w, switch (op) {
+ .select => 'x',
+ .split => 'y',
+ .keep => 'g',
+ else => 'v',
+ }, line);
+ },
+ .pipe => try w.print("Edit |{s}", .{line}),
+ .pipe_to => try w.print("Edit >{s}", .{line}),
+ .insert, .append, .keep_pipe => return null,
+ .command => try w.writeAll(line),
+ }
+ return if (op == .search or op == .search_back) "Look" else "Exec";
+}
+
+/// The head of the prompt's tag: ` s self▌ = Exec Edit x/self/ 4
+/// selections in 6 lines ⏎ select · C-r history · esc`.
+pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head {
+ const s = &p.view().tag_state;
+ const pr = &s.prompt;
+ var text: std.ArrayList(u8) = .empty;
+ var spans: std.ArrayList(TagState.Span) = .empty;
+ try text.append(arena, ' ');
+ try styled(arena, &text, &spans, info.get(pr.op).cell, .key);
+ try text.append(arena, ' ');
+ const caret: u32 = @intCast(text.items.len + s.field.caret);
+ const line = s.field.text();
+ try text.appendSlice(arena, line);
+ if (line.len > 0) {
+ var buf: [Field.max + 16]u8 = undefined;
+ var w: std.Io.Writer = .fixed(&buf);
+ if (plainWord(&w, pr.op, line) catch null) |verb| {
+ try styled(arena, &text, &spans, try std.fmt.allocPrint(arena, " = {s}", .{verb}), .dim);
+ try text.print(arena, " {s}", .{w.buffered()});
+ }
+ if (pr.bad) {
+ try text.appendSlice(arena, " ");
+ try styled(arena, &text, &spans, regexMessage(line), .err);
+ try text.print(arena, " · the {d} from before shown, dimmed", .{@as(usize, pane.body.nsel) + 1});
+ } else try count(arena, &text, pane, pr);
+ }
+ try text.appendSlice(arena, " ");
+ try styled(arena, &text, &spans, info.get(pr.op).hint, .dim);
+ return .{ .text = text.items, .spans = spans.items, .cells = 1, .caret = caret };
+}
+
+fn styled(arena: std.mem.Allocator, text: *std.ArrayList(u8), spans: *std.ArrayList(TagState.Span), s: []const u8, style: TagState.Style) !void {
+ const lo: u32 = @intCast(text.items.len);
+ try text.appendSlice(arena, s);
+ try spans.append(arena, .{ .lo = lo, .hi = @intCast(text.items.len), .style = style });
+}
+
+/// The prompt's count after its field: what it found (`4 selections in 6
+/// lines`, `keeps 3 of 9`, `0`).
+fn count(arena: std.mem.Allocator, text: *std.ArrayList(u8), pane: *const Pane, pr: *const Prompt) !void {
+ switch (pr.op) {
+ .select, .split => if (pr.found == 0)
+ try text.appendSlice(arena, " 0")
+ else
+ try text.print(arena, " {d} selection{s} in {d} line{s}", .{ pr.found, plural(pr.found), pr.scope, plural(pr.scope) }),
+ .keep, .remove => try text.print(arena, " keeps {d} of {d}", .{ pr.found, pane.nsel_snap }),
+ else => {},
+ }
+}
+
+fn plural(n: usize) []const u8 {
+ return if (n == 1) "" else "s";
+}
+
+/// The rows the prompt's band takes: its history unrolled (Ctrl-r), the
+/// lines the field is in, eleven at most.
+pub fn takes(p: *Pardes) u16 {
+ const s = &p.view().tag_state;
+ if (!s.prompt.history) return 0;
+ var n: u16 = 0;
+ const r = ring(p, s.prompt.op);
+ for (r.lines[0..r.n]) |l| {
+ if (std.mem.indexOf(u8, l.slice(), s.field.text()) != null) n += 1;
+ }
+ return @max(1, @min(Band.Cursor.shown, n));
+}
+
+/// The prompt's steps in its band: its history, newest first, the lines
+/// holding the field, the one Up recalled on.
+pub fn steps(p: *Pardes, arena: std.mem.Allocator, out: *[Band.max_steps]Band.Step) ![]Band.Step {
+ const s = &p.view().tag_state;
+ if (!s.prompt.history) return out[0..0];
+ const r = ring(p, s.prompt.op);
+ var rows: std.ArrayList(Band.Row) = .empty;
+ const q = s.field.text();
+ var back: u8 = 1;
+ while (back <= r.n and rows.items.len < Band.Cursor.shown) : (back += 1) {
+ const l = r.get(back).?;
+ if (std.mem.indexOf(u8, l, q) == null) continue;
+ try rows.append(arena, .{ .text = l, .on = back == s.prompt.recall, .index = back });
+ }
+ if (rows.items.len == 0) try rows.append(arena, .{ .text = if (r.n == 0) "no history yet" else "no line holds it", .dim = true });
+ out[0] = .{ .rows = rows.items };
+ return out[0..1];
+}
+
+fn typeKeys(p: *Pardes, keys: []const u8) void {
+ for (keys) |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+}
+
+fn tagOf(p: *Pardes) ![]const u8 {
+ return tagline.tagText(p, p.scratch.allocator(), p.panes[p.view().active].?);
+}
+
+fn has(hay: []const u8, needle: []const u8) bool {
+ return std.mem.indexOf(u8, hay, needle) != null;
+}
+
+test "s asks in the tag's head: its key cell, the field, the plain word and the count, the selections live in the body; no match is 0, a pattern that is no regex keeps the last result dimmed and says why, Esc puts them back" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("self.a = 1;\nself.b = 2;\nother = 3;\n");
+ const rest = try std.testing.allocator.dupe(u8, try tagOf(p));
+ defer std.testing.allocator.free(rest);
+ typeKeys(p, "%s");
+ try std.testing.expectEqual(TagState.Kind.prompt, p.view().tag_state.kind);
+ // No chip on the notice band: the prompt is the tag's.
+ try std.testing.expectEqual(Pane.Prompt.none, pane.prompt);
+ try std.testing.expect(std.mem.endsWith(u8, try tagOf(p), " s ⏎ select · C-r history · esc"));
+ typeKeys(p, "self");
+ try std.testing.expect(has(try tagOf(p), " s self = Exec Edit x/self/ 2 selections in 3 lines ⏎ select"));
+ try std.testing.expectEqual(@as(u16, 1), pane.body.nsel);
+ try std.testing.expect(selecting(p, pane).?.dim == false);
+ // No match: 0, and the selection it began with.
+ typeKeys(p, "x");
+ try std.testing.expect(has(try tagOf(p), "= Exec Edit x/selfx/ 0 "));
+ try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
+ p.update(.{ .key = .{ .cp = Key.backspace } });
+ try std.testing.expectEqual(@as(u16, 1), pane.body.nsel);
+ // No regex: the two from before, dimmed, and why.
+ typeKeys(p, "(");
+ try std.testing.expect(has(try tagOf(p), " bad regular expression · the 2 from before shown, dimmed "));
+ try std.testing.expectEqual(@as(u16, 1), pane.body.nsel);
+ try std.testing.expect(selecting(p, pane).?.dim);
+ // Esc: rest, the tag and the selection as they were.
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind);
+ try std.testing.expectEqualStrings(rest, try tagOf(p));
+ try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
+ const r = pane.body.primaryRange(pane.file.?.content, 0);
+ try std.testing.expectEqual(pane.file.?.content.len, @max(r.anchor, r.head));
+ try std.testing.expect(selecting(p, pane) == null);
+}
+
+test "Enter keeps what s found, the pattern in / and in the history Up brings back; K keeps, counted; a pipe from the body asks in the tag and runs off the loop" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 30 });
+ defer p.deinit();
+ while (p.nextEffect()) |_| {}
+ const pane = try p.setTestFile("self.a = 1;\nself.b = 2;\nother = 3;\n");
+ typeKeys(p, "%sself..");
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind);
+ try std.testing.expectEqual(@as(u16, 1), pane.body.nsel);
+ try std.testing.expectEqualStrings("self..", p.registers.value('/', 0).?);
+ try std.testing.expectEqualStrings("self..", p.prompt_history.search.get(1).?);
+ // K over the two: Up brings `self..` back, `b` keeps one of them.
+ typeKeys(p, "K");
+ p.update(.{ .key = .{ .cp = Key.up } });
+ try std.testing.expectEqualStrings("self..", p.view().tag_state.field.text());
+ try std.testing.expect(has(try tagOf(p), " K self.. = Exec Edit g/self../ keeps 2 of 2"));
+ p.update(.{ .key = .{ .cp = Key.down } });
+ typeKeys(p, "b");
+ try std.testing.expect(has(try tagOf(p), " K b = Exec Edit g/b/ keeps 1 of 2 ⏎ keep"));
+ // Ctrl-r: the history under the tag, a row a line.
+ p.update(.{ .key = .{ .cp = 'r', .ctrl = true } });
+ try std.testing.expectEqual(@as(u16, 1), Band.takes(p, p.view().active));
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
+ try std.testing.expectEqualStrings("b", p.prompt_history.search.get(1).?);
+ try std.testing.expectEqualStrings("self..", p.prompt_history.search.get(2).?);
+ // | from the body: in the tag, the plain word Edit's, Enter pipes.
+ typeKeys(p, "|");
+ try std.testing.expectEqual(Pane.Prompt.none, pane.prompt);
+ p.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } });
+ try std.testing.expect(has(try tagOf(p), " | tr a-z A-Z = Exec Edit |tr a-z A-Z ⏎ replace"));
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqualStrings("tr a-z A-Z", p.registers.value('|', 0).?);
+ var asked: ?u32 = null;
+ while (p.nextEffect()) |effect| if (effect == .pipe) {
+ asked = effect.pipe.id;
+ };
+ const request = p.pipe.pipeRequest(asked orelse return error.MissingPipeEffect).?;
+ try std.testing.expectEqualStrings("tr a-z A-Z", request.command);
+ try std.testing.expectEqualSlices(u8, "self.b", request.inputs[0]);
+ // Esc in a pipe's prompt runs nothing.
+ typeKeys(p, "|cat");
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ while (p.nextEffect()) |effect| try std.testing.expect(effect != .pipe);
+}
diff --git a/core/TagState.zig b/core/TagState.zig
index 56c715af..716704b7 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -24,11 +24,13 @@ const Root = bindings.Root;
const Field = @import("Field.zig");
const Band = @import("Band.zig");
const Names = @import("Names.zig");
+const Prompt = @import("Prompt.zig");
/// The tag's states besides a root's level (which `kind` rest with a root
/// current is): `help`, a field over every leaf (SPEC §4.5); `describe`,
-/// a sequence replayed in the tree (item 5).
-pub const Kind = enum(u8) { rest, help, describe };
+/// a sequence replayed in the tree (item 5); `prompt`, a text prompt
+/// (Prompt.zig, SPEC §7).
+pub const Kind = enum(u8) { rest, help, describe, prompt };
pub const replica = .{ .len = .{ .{ "scope", "scope_n" }, .{ "hits", "nhits" } } };
@@ -52,6 +54,9 @@ nhits: u16 = 0,
ntotal: u16 = 0,
/// The rows' cursor (Band.Cursor).
rows: Band.Cursor = .{},
+/// A text prompt's own (Prompt.zig): which, its history's place, what its
+/// field found.
+prompt: Prompt = .{},
/// The root the last key left current, whose delay `due_ns` counts.
root: ?Root = null,
/// When its level shows, on the session's clock: `asked` from its key
@@ -155,6 +160,7 @@ pub fn toRest(p: *Pardes) void {
pane.tag.normal.clear();
}
const s = &v.tag_state;
+ if (s.kind == .prompt) Prompt.leave(p);
s.kind = .rest;
s.previewing = .empty;
s.root = null;
@@ -312,7 +318,7 @@ pub fn helpLeaf(p: *const Pardes, at: u16, buf: *[row_max]u8) Leaf {
}
/// How a span of the head is drawn (draw.zig paintPaneTag).
-pub const Style = enum { key, dim, under, strike };
+pub const Style = enum { key, dim, under, strike, err };
pub const Span = struct { lo: u32, hi: u32, style: Style };
/// The head: its text, the spans drawn apart, and the caret in it when the
/// head is typed in.
@@ -378,6 +384,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
return h;
},
.describe => return null,
+ .prompt => return try Prompt.head(p, arena, pane),
}
const cur = current(p, v) orelse return null;
try b.put(" ");
diff --git a/core/body_layer.zig b/core/body_layer.zig
index 9c4a4c73..4176514b 100644
--- a/core/body_layer.zig
+++ b/core/body_layer.zig
@@ -379,7 +379,10 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
if (b == pardes.sel_slot and @min(sl.r0, sl.r1) < pane.tag_rows) continue;
paintPointerSelection(p, s, pane, r, sl, pane.tag_rows, sel_btn[b], buttonInks(th)[b]);
}
- const preview = normal.selRegexArmed(pane) != null;
+ // A selecting prompt's live result (Prompt.zig), dimmed while its
+ // field is no regex.
+ const selecting = pardes.Prompt.selecting(p, pane);
+ const preview = normal.selRegexArmed(pane) != null or selecting != null;
const show_prim = (pane.body.mode == .normal and pane.body.vsel.active) or preview or
(modal_hover and pane.body.vsel.active);
const show_extra = pane.body.mode != .tty and pane.body.nsel > 0;
@@ -397,7 +400,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
} else pane.body.sels[si];
const bnd = edit.cellBounds(sr);
const hover_only = primary and modal_hover and pane.body.mode != .normal and !preview;
- const bg = if (hover_only)
+ const bg = if (hover_only or (selecting != null and selecting.?.dim))
colors.mix(page_rgb, colors.mix(page_rgb, th.sel_bg))
else if (primary)
th.sel_bg
diff --git a/core/draw.zig b/core/draw.zig
index bc606f02..3365f0a8 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -1002,6 +1002,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
.dim => style.dim = true,
.under => style.ul = .single,
.strike => style.strikethrough = true,
+ .err => style.fg = .{ .rgb = chrome.diagnostic_error },
}
}
}
diff --git a/core/edit.zig b/core/edit.zig
index 8ed7752e..6c0ba02b 100644
--- a/core/edit.zig
+++ b/core/edit.zig
@@ -124,6 +124,11 @@ pub fn applyPaste(p: *Pardes, whole: []const u8) Error!void {
var said: pardes.Kind.Buf(96) = .{};
p.setMessage(.at(v.active), said.print("paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024}));
}
+ // A text prompt in a tag takes it into its field (Prompt.zig).
+ if (v.tag_state.kind == .prompt) {
+ v.clip_pending = null;
+ return pardes.Prompt.paste(p, bytes);
+ }
// A prompt answering for a header takes the paste, as it takes keys.
const asking = if (p.panes[v.active]) |active| active.prompt != .none else false;
if (!asking) if (tagline.focusedHeader(p)) |t| {
@@ -146,7 +151,9 @@ pub fn applyPaste(p: *Pardes, whole: []const u8) Error!void {
n += 1;
};
if (n > 0) try insertKey(p.editor(), &pane.input, .{ .cp = line[0], .text = line[0..n] });
- if (normal.selRegexArmed(pane)) |a| if (panes.promptTarget(p, pane)) |t| normal.applySelRegex(p, pane, t, a.pat, a.mode);
+ if (normal.selRegexArmed(pane)) |a| if (panes.promptTarget(p, pane)) |t| {
+ _ = normal.applySelRegex(p, pane, t, a.pat, a.mode);
+ };
return;
}
if (pane.focus == .tag) return pasteInto(p, &pane.tag, bytes);
diff --git a/core/keys.zig b/core/keys.zig
index 6f43e166..6ffca8e1 100644
--- a/core/keys.zig
+++ b/core/keys.zig
@@ -20,6 +20,7 @@ const Pipe = @import("Pipe.zig");
const Registers = @import("Registers.zig");
const bindings = @import("bindings.zig");
const TagState = @import("TagState.zig");
+const Prompt = @import("Prompt.zig");
const Pardes = pardes.Pardes;
const Pane = panes.Pane;
const Text = panes.Text;
@@ -360,8 +361,9 @@ pub fn handleKey(p: *Pardes, key: Key) void {
.save => if (submit) exec.submitSave(p, p.view().active),
.search => if (submit)
look.submitSearch(p, p.view().active)
- else if (normal.selRegexArmed(pane)) |_| if (target) |answered|
- normal.applySelRegex(p, pane, answered, "", .select),
+ else if (normal.selRegexArmed(pane)) |_| if (target) |answered| {
+ _ = normal.applySelRegex(p, pane, answered, "", .select);
+ },
.none, .del_side, .repl_choice, .name => unreachable,
}
pane.closePrompt();
@@ -372,7 +374,9 @@ pub fn handleKey(p: *Pardes, key: Key) void {
return;
}
edit.handleInsert(p.editor(), &pane.input, key);
- if (normal.selRegexArmed(pane)) |a| if (panes.promptTarget(p, pane)) |answered| normal.applySelRegex(p, pane, answered, a.pat, a.mode);
+ if (normal.selRegexArmed(pane)) |a| if (panes.promptTarget(p, pane)) |answered| {
+ _ = normal.applySelRegex(p, pane, answered, a.pat, a.mode);
+ };
return;
}
if (header == null) if (TagState.current(p, p.view())) |cur| if (cur.root != .leader and cur.root != .window) {
@@ -549,9 +553,10 @@ fn leaderTake(p: *Pardes, c: u8) void {
fn tagStateKey(p: *Pardes, key: Key) void {
const v = p.view();
const s = &v.tag_state;
+ if (s.kind == .prompt) return Prompt.key(p, key);
if (TagState.hostOf(p) == null or hit(key, config.escape)) return TagState.toRest(p);
switch (s.kind) {
- .rest => unreachable,
+ .rest, .prompt => unreachable,
.describe => return TagState.toRest(p),
.help => {
const plain = !key.ctrl and !key.alt;
diff --git a/core/lib_editor.zig b/core/lib_editor.zig
index 3e4a1f15..e5c160ed 100644
--- a/core/lib_editor.zig
+++ b/core/lib_editor.zig
@@ -370,7 +370,7 @@ pub fn Editor(comptime cap: Capacity) type {
}
var snap: [max_selections]Selection = undefined;
const got = t.ranges(t.own.?, 0, &snap);
- normal.selectByRegex(live.context(a), t, snap[0..got.n], got.pri, t.vsel.active and t.vsel.explicit, pattern, how);
+ _ = normal.selectByRegex(live.context(a), t, snap[0..got.n], got.pri, t.vsel.active and t.vsel.explicit, pattern, how);
return ed.keep(a, live, .done);
}
diff --git a/core/look.zig b/core/look.zig
index cc3e750f..d7dd7690 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -390,7 +390,8 @@ pub fn submitSearch(p: *Pardes, id: usize) void {
p.registers.put(p.gpa, '/', a.pat, 0, 1, true) catch |err| return p.reportError(.at(id), "search", err);
p.registers.last_search = '/';
}
- return if (panes.promptTarget(p, pane)) |t| normal.applySelRegex(p, pane, t, a.pat, a.mode);
+ if (panes.promptTarget(p, pane)) |t| _ = normal.applySelRegex(p, pane, t, a.pat, a.mode);
+ return;
}
const armed = pane.promptText() orelse return;
const slash = std.mem.indexOfScalar(u8, armed, '/') orelse return;
diff --git a/core/normal.zig b/core/normal.zig
index 1f7ce1a7..c59a847c 100644
--- a/core/normal.zig
+++ b/core/normal.zig
@@ -22,6 +22,7 @@ const sel_slot = pardes.sel_slot;
const Pardes = pardes.Pardes;
const Macro = pardes.Macro;
const Editor = @import("Editor.zig");
+const Prompt = @import("Prompt.zig");
fn isPrefix(key: Key, cp: u21) bool {
return key.cp == cp and !key.ctrl and !key.alt;
@@ -53,15 +54,19 @@ pub fn selRegexArmed(pane: *Pane) ?struct { pat: []const u8, mode: modal.Normal.
/// Select (or split on, keep or remove by) `pat` inside the selections `t`
/// had when s/S/K/Alt-K was pressed; the prompt's snapshot of them lives on
-/// `pane`.
-pub fn applySelRegex(p: *Pardes, pane: *Pane, t: *Text, pat: []const u8, mode: modal.Normal.RegexMode) void {
- selectByRegex(p.editor(), t, pane.sel_snap[0..pane.nsel_snap], pane.sel_snap_pri, pane.sel_snap_expl, pat, mode);
+/// `pane`. The ranges it found: none, the snapshot's back.
+pub fn applySelRegex(p: *Pardes, pane: *Pane, t: *Text, pat: []const u8, mode: modal.Normal.RegexMode) usize {
+ return selectByRegex(p.editor(), t, pane.sel_snap[0..pane.nsel_snap], pane.sel_snap_pri, pane.sel_snap_expl, pat, mode);
}
/// Select (or split on, keep or remove by) `pat` inside `snap`, the
-/// ranges there were (primary `pri`) when s/S/K/Alt-K was pressed.
-pub fn selectByRegex(e: Editor, t: *Text, snap: []modal.Selection, pri: usize, expl: bool, pat: []const u8, mode: modal.Normal.RegexMode) void {
- const text = edit.flatSurface(e, t) catch |err| return e.reportError(err);
+/// ranges there were (primary `pri`) when s/S/K/Alt-K was pressed; the
+/// ranges it found.
+pub fn selectByRegex(e: Editor, t: *Text, snap: []modal.Selection, pri: usize, expl: bool, pat: []const u8, mode: modal.Normal.RegexMode) usize {
+ const text = edit.flatSurface(e, t) catch |err| {
+ e.reportError(err);
+ return 0;
+ };
var out: [Text.max_selections]modal.Selection = undefined;
var m: usize = 0;
if (regexp.Regex.compile(pat)) |compiled| {
@@ -69,7 +74,10 @@ pub fn selectByRegex(e: Editor, t: *Text, snap: []modal.Selection, pri: usize, e
var hay_all = text;
if (for (pat) |c| {
if (std.ascii.isUpper(c)) break false;
- } else true) hay_all = std.ascii.allocLowerString(e.scratch, text) catch |err| return e.reportError(err);
+ } else true) hay_all = std.ascii.allocLowerString(e.scratch, text) catch |err| {
+ e.reportError(err);
+ return 0;
+ };
for (snap) |r| {
const from = @min(r.anchor, r.head);
const to = @min(@max(r.anchor, r.head), text.len);
@@ -116,9 +124,11 @@ pub fn selectByRegex(e: Editor, t: *Text, snap: []modal.Selection, pri: usize, e
r.anchor = @min(r.anchor, text.len);
r.head = @min(r.head, text.len);
}
- return t.setRanges(e.tab, text, snap, &.{}, pri, expl);
+ t.setRanges(e.tab, text, snap, &.{}, pri, expl);
+ return 0;
}
t.setRanges(e.tab, text, out[0..m], &.{}, 0, true); // helix keeps primary 0 (its own TODO)
+ return m;
}
fn lastMatch(re: *SearchRegex, hay: []const u8, from: usize, to: usize) ?regexp.Regex.Match {
@@ -600,6 +610,9 @@ fn actionPass(e: Editor, t: *Text, action: modal.Normal.Action) edit.Error!void
}
fn startSelRegex(p: *Pardes, pane: *Pane, t: *Text, mode: modal.Normal.RegexMode) edit.Error!void {
+ // A body's prompt is its tag's (Prompt.zig); a tag's or a header's asks
+ // on the notice band.
+ if (t.what == .body) return Prompt.open(p, pane, Prompt.ofMode(mode));
const text = try edit.flatSurface(p.editor(), t);
const got = t.ranges(text, 0, &pane.sel_snap);
pane.nsel_snap = @intCast(got.n);
@@ -1360,11 +1373,18 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error!
.column, .workspace => tagline.exitHeader(p),
.body, .input => tagline.enterTag(p, pane),
},
- .pipe_selection => return panes.startPrompt(p, pane, t, .{ .pipe = .replace }),
- .pipe_selection_to => return panes.startPrompt(p, pane, t, .{ .pipe = .ignore }),
- .insert_output => return panes.startPrompt(p, pane, t, .{ .pipe = .insert }),
- .append_output => return panes.startPrompt(p, pane, t, .{ .pipe = .append }),
- .keep_pipe => return panes.startPrompt(p, pane, t, .{ .pipe = .keep }),
+ inline .pipe_selection, .pipe_selection_to, .insert_output, .append_output, .keep_pipe => |role| {
+ const how: modal.Normal.PipeBehavior = switch (role) {
+ .pipe_selection => .replace,
+ .pipe_selection_to => .ignore,
+ .insert_output => .insert,
+ .append_output => .append,
+ else => .keep,
+ };
+ // A body's in its tag (Prompt.zig), else on the notice band.
+ if (t.what == .body) return Prompt.open(p, pane, Prompt.ofBehavior(how));
+ return panes.startPrompt(p, pane, t, .{ .pipe = how });
+ },
// `/` in a text is its query pane's line 1 (Query.zig); a
// terminal's still asks on the notice band.
.search => if (pane.file != null and t.what == .body)
@@ -1657,7 +1677,7 @@ test "s and S search a multi-line selection as addr does: ^ and $ per line, . wi
}) |c| {
pane.sel_snap[0] = .{ .anchor = 0, .head = text.len };
pane.nsel_snap = 1;
- applySelRegex(p, pane, &pane.body, c.pat, c.mode);
+ _ = applySelRegex(p, pane, &pane.body, c.pat, c.mode);
var out: [Text.max_selections]modal.Selection = undefined;
const got = pane.body.ranges(text, 0, &out);
try std.testing.expectEqual(c.want.len, got.n);
diff --git a/core/panes.zig b/core/panes.zig
index 115323c4..0590a80d 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -1953,7 +1953,7 @@ test "a prompt chip is a band with its caret, still on the grid, and only the ch
for (pane.sel) |selection| try std.testing.expect(selection.state == .none);
}
-test "a prompt is typed on its own line in the notice band and leaves the tag row alone" {
+test "a Save prompt is typed on its own line in the notice band and leaves the tag row alone" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
const pane = try p.setTestFile("one two\n");
@@ -1963,13 +1963,13 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro
const tag_before = try std.testing.allocator.dupe(Cell, p.surface.tag_layers[0].cells);
defer std.testing.allocator.free(tag_before);
- // `s` keeps a prompt on the band (a text's `/` is its query pane's
- // line 1 now, Query.zig).
- p.update(.{ .key = .{ .cp = 's' } });
+ // Save's path keeps a prompt on the band (a body's `s`, `|` and `/`
+ // ask in its tag, Prompt.zig).
+ startPrompt(p, pane, &pane.body, .save);
p.update(.{ .key = .{ .cp = 't', .text = "tw" } });
p.update(.{ .key = .{ .cp = Key.left } });
- try std.testing.expect(pane.prompt == .search and pane.focus == .body);
- try std.testing.expectEqualStrings(config.select_marker ++ "tw", pane.promptText().?);
+ try std.testing.expect(pane.prompt == .save and pane.focus == .body);
+ try std.testing.expectEqualStrings(config.save_marker ++ "/tw", pane.promptText().?);
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
// The tagline is exactly what it was: nothing of the prompt is in it.
@@ -1986,7 +1986,7 @@ test "a prompt is typed on its own line in the notice band and leaves the tag ro
const grid = p.surface.cursor orelse return error.MissingPromptCursor;
try std.testing.expectEqual(p.bodyTop(pane, p.view().rects[0]), grid.y);
- // Submitting searches for what was typed and gives the prompt its line back.
- p.update(.{ .key = .{ .cp = Key.enter } });
+ // Esc gives the prompt its line back.
+ p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expect(pane.prompt == .none and pane.input.own == null);
}
diff --git a/core/root.zig b/core/root.zig
index 36d940b2..09486906 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -92,6 +92,7 @@ pub const keys = @import("keys.zig");
pub const bindings = @import("bindings.zig");
pub const TagState = @import("TagState.zig");
pub const Band = @import("Band.zig");
+pub const Prompt = @import("Prompt.zig");
pub const Addon = @import("Addon.zig");
pub const dump = @import("dump.zig");
pub const lsp = @import("lsp/lsp.zig");
@@ -415,6 +416,7 @@ test {
_ = @import("TagState.zig");
_ = @import("Band.zig");
_ = @import("Field.zig");
+ _ = @import("Prompt.zig");
_ = @import("Effect.zig");
_ = @import("tape.zig");
_ = @import("replica.zig");
diff --git a/test/behaviour/keys.zig b/test/behaviour/keys.zig
index e1f550e3..e8731d2c 100644
--- a/test/behaviour/keys.zig
+++ b/test/behaviour/keys.zig
@@ -14,18 +14,20 @@ test "keys: a prompt's entry and cancellation leave the tag, the body and its cu
const dot = s.at("/pane/{d}/dot", .{n});
try s.replace(tag, " keep");
for ([_]struct { keys: []const u8, shown: []const u8 }{
- .{ .keys = "s", .shown = " /zq" },
- .{ .keys = "|", .shown = " |zq" },
- .{ .keys = alt ++ "|", .shown = " |-zq" },
- .{ .keys = "!", .shown = " !zq" },
- .{ .keys = alt ++ "!", .shown = " !+zq" },
+ .{ .keys = "s", .shown = " s zq" },
+ .{ .keys = "|", .shown = " | zq" },
+ .{ .keys = alt ++ "|", .shown = " A-| zq" },
+ .{ .keys = "!", .shown = " ! zq" },
+ .{ .keys = alt ++ "!", .shown = " A-! zq" },
}) |case| {
try s.write(dot, "6 6");
try s.keys(case.keys);
- // The answer is typed into the prompt's own line, never the tag.
+ // The answer is typed into the tag's head (walk UI), shown in place
+ // of the tag's own text, which it never touches.
try s.keys("zq");
_ = try s.where(case.shown);
- try std.testing.expectEqualStrings("/test.txt keep", try s.read(tag));
+ const head = try s.read(tag);
+ try std.testing.expect(std.mem.startsWith(u8, head, "/test.txt") and std.mem.startsWith(u8, head["/test.txt".len..], case.shown));
try s.keys("\x1b");
try std.testing.expectError(error.NotOnScreen, s.where(case.shown));
try std.testing.expect(std.mem.endsWith(u8, try s.read(s.at("/pane/{d}/ctl", .{n})), " mode:normal "));
@@ -56,8 +58,8 @@ test "keys: a prompt opens whatever the tag already holds" {
try s.keys(key);
try s.keys("zq");
_ = try s.where("zq");
- try std.testing.expectEqualStrings(full, try s.read(tag));
try s.keys("\x1b");
+ try std.testing.expectEqualStrings(full, try s.read(tag));
}
}
diff --git a/test/daemon.py b/test/daemon.py
index f9cbc9e1..4bc2658f 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -340,7 +340,7 @@ class Replica:
"""A replica's connection (abi/wire.zig): length-prefixed
messages, a tag byte and a little-endian u32 length. It is a near
client: its first word after the hello says so."""
- WIRE = 36
+ WIRE = 37
def __init__(self, path, timeout=10):
self.path, self.timeout = path, timeout
diff --git a/test/snapshots/msg.golden b/test/snapshots/msg.golden
index 7f83cacf..6a79cd68 100644
--- a/test/snapshots/msg.golden
+++ b/test/snapshots/msg.golden
@@ -36,14 +36,18 @@
|7:
|8:
|9:
-== snap prompt grid=70x17 cursor=69,3
-|3: 1 EXTERNAL Select /EXT
-== snap prompt-wins grid=70x17 cursor=69,4
-|3: 1 AGAIN --:--:-- reloaded /tmp/pardes-snap/msg/cwd/a.txt
-|4: ~ Select /EXT
+== snap prompt grid=70x17 cursor=38,2
+|2: ^ /tmp/pardes-snap/msg/cwd/a.txt s EXT = Exec Edit x/EXT/ 0 ⏎ sel
+|3: ect · C-r history · esc
+|4: 1 EXTERNAL
+|5: ~
+== snap prompt-wins grid=70x17 cursor=38,2
+|4: 1 AGAIN --:--:-- reloaded /tmp/pardes-snap/msg/cwd/a.txt
== snap esc grid=70x17 cursor=7,4
+|2: /tmp/pardes-snap/msg/cwd/a.txt Save Term Collapse Follow Del
|3: 1 AGAIN
|4: ~
+|5:
== snap msgbuiltin grid=70x17 cursor=29,5
|2: */tmp/pardes-snap/msg/cwd/a.txt Save Term Collapse Follow Del
|3: 1 AGAIN hand-written report
diff --git a/test/snapshots/pipe.golden b/test/snapshots/pipe.golden
index 618a3019..641418f9 100644
--- a/test/snapshots/pipe.golden
+++ b/test/snapshots/pipe.golden
@@ -1,8 +1,8 @@
-== snap prompt grid=180x13 cursor=179,3
+== snap prompt grid=180x13 cursor=49,2
| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit
| New Term Find Grep Joincol Delcol
-| /tmp/pardes-snap/pipe/cwd/pipe.txt Save Term Collapse Follow Del
-| 1 alpha beta |tr a-z A-Z
+|^ /tmp/pardes-snap/pipe/cwd/pipe.txt | tr a-z A-Z = Exec Edit |tr a-z A-Z ⏎ replace · C-r history · esc
+| 1 alpha beta
| 2 gamma delta
== snap filtered grid=180x13 cursor=17,3
|2: */tmp/pardes-snap/pipe/cwd/pipe.txt Save Term Collapse Follow Del
diff --git a/test/snapshots/selregex.golden b/test/snapshots/selregex.golden
index 4e456d99..cc460f03 100644
--- a/test/snapshots/selregex.golden
+++ b/test/snapshots/selregex.golden
@@ -1,18 +1,18 @@
-== snap prompt-armed grid=160x25 cursor=159,3
+== snap prompt-armed grid=160x25 cursor=40,2
| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit
| New Term Find Grep Joincol Delcol
-| /tmp/pardes-snap/selregex/cwd/m.zig Save Term Collapse Follow TreeContext Def Refs Del
-| 1 const one = 1; Select /
+|^ /tmp/pardes-snap/selregex/cwd/m.zig s ⏎ select · C-r history · esc
+| 1 const one = 1;
| 2 const two = 2;
| 3 const three = 3;
| ~
-== snap preview grid=160x25 cursor=159,3
-|3: 1 const one = 1; Select /const
+== snap preview grid=160x25 cursor=45,2
+|2: ^ /tmp/pardes-snap/selregex/cwd/m.zig s const = Exec Edit x/const/ 3 selections in 3 lines ⏎ select · C-r history · esc
== style preview grid=160x25
|0: 0-1 d,#1d2824, 2-159 #b2c3b8,#1d2824,
|1: 0-1 d,#887455, 2-159 #becfc4,#314738,
-|2: 0-1 d,#add38a, 2-31 #becfc4,#314738, 32-37 #dfbce5,#314738, 38-159 #becfc4,#314738,
-|3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#3c614a, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-143 #e5eee5,#0d1410, 144-145 #e5eee5,#1d2824, 146-159 #b2c3b8,#1d2824,
+|2: 0-1 #000000,#add38a, 2-31 #becfc4,#314738, 32-37 #dfbce5,#314738, 38-38 #add38a,#314738,b 39-39 #add38a,#314738, 40-44 #becfc4,#314738, 45-52 #becfc4,#314738,f 53-95 #becfc4,#314738, 96-123 #becfc4,#314738,f 124-159 #becfc4,#314738,
+|3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-10 #f5f7ee,#3c614a, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410,
|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410,
|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410,
|6: 0-0 d,#608269, 1-4 d,#0d1410, 5-159 #59675c,#0d1410,
@@ -35,18 +35,21 @@
|23: 0-0 d,#608269, 1-159 d,#0d1410,
|24: 0-0 d,#608269, 1-159 d,#0d1410,
== snap three-selected grid=160x25 cursor=11,3
-|3: 1 const one = 1;
+|2: /tmp/pardes-snap/selregex/cwd/m.zig Save Term Collapse Follow TreeContext Def Refs Del
== style three-selected grid=160x25
+|2: 0-1 d,#add38a, 2-31 #becfc4,#314738, 32-37 #dfbce5,#314738, 38-159 #becfc4,#314738,
|3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #f5f7ee,#3c614a, 12-12 #f5f7ee,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410,
-== snap narrowed grid=160x25 cursor=159,3
-|3: 1 const one = 1; Select /t
+== snap narrowed grid=160x25 cursor=41,2
+|2: ^ /tmp/pardes-snap/selregex/cwd/m.zig s t = Exec Edit x/t/ 3 selections in 3 lines ⏎ select · C-r history · esc
== style narrowed grid=160x25
-|3: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-147 #e5eee5,#0d1410, 148-149 #e5eee5,#1d2824, 150-159 #b2c3b8,#1d2824,
+|2: 0-1 #000000,#add38a, 2-31 #becfc4,#314738, 32-37 #dfbce5,#314738, 38-38 #add38a,#314738,b 39-39 #add38a,#314738, 40-40 #becfc4,#314738, 41-48 #becfc4,#314738,f 49-87 #becfc4,#314738, 88-115 #becfc4,#314738,f 116-159 #becfc4,#314738,
+|3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-10 #e5eee5,#0d1410, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410,
|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410,
|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #e5eee5,#0d1410, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410,
== snap esc-restores grid=160x25 cursor=11,3
-|3: 1 const one = 1;
+|2: /tmp/pardes-snap/selregex/cwd/m.zig Save Term Collapse Follow TreeContext Def Refs Del
== style esc-restores grid=160x25
+|2: 0-1 d,#add38a, 2-31 #becfc4,#314738, 32-37 #dfbce5,#314738, 38-159 #becfc4,#314738,
|3: 0-0 d,#608269, 1-1 d,#0d1410, 2-4 d,#0d1410,b 5-6 #616f64,#0d1410,b 7-11 #f5f7ee,#3c614a, 12-12 #f5f7ee,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410,
|4: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-18 #e5eee5,#0d1410, 19-19 #f8c082,#0d1410, 20-159 #e5eee5,#0d1410,
|5: 0-0 d,#608269, 1-4 d,#0d1410, 5-6 #59675c,#0d1410, 7-10 #f5f7ee,#243a2d, 11-11 #3c614a,#f5f7ee, 12-12 #3c614a,#0d1410, 13-20 #e5eee5,#0d1410, 21-21 #f8c082,#0d1410, 22-159 #e5eee5,#0d1410,