summaryrefslogtreecommitdiff
path: root/core/Command.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-25 02:03:41 -0300
committerGabriel Schneider <[email protected]>2026-11-25 02:03:41 -0300
commit09729fc927bca5f05f99de7844069cae445598a1 (patch)
treefab8e0b1e187c9b2f8d84a088952b71982c9f644 /core/Command.zig
parentc9a5d230570863beb8183190d01c7e19c7696a14 (diff)
downloadpardes-09729fc927bca5f05f99de7844069cae445598a1.tar.gz
pardes-09729fc927bca5f05f99de7844069cae445598a1.zip
Command: a question waiting on the pane lists its answers as `:`'s first rows, a letter typed only filtering them and Tab or a click giving one; `:open ` lists the files the panes show; and the faults the gates met (walk UI, pick-ui SPEC.md §10.4, item 4 of line E2): with a question waiting on the pane (Messages.waitingAnswers) its answers are the names' first rows, each after its key in the key ink (`r Reload`, `k Keep mine`, `d Diff`), `answers the question` on their right, the last ruled off from the tag's words as theirs is from the commands; typing filters them as the rest (Names.match on the word), so a letter never answers (`:r` is a line, `:reflow` runs reflow); Enter gives one when the current row is an answer Tab or a click put in the field, or its whole word typed, the tag at rest first (Messages.waiting, Messages.answer); a click (B1, TagState.point) on an answer gives it at once, and on a line of C-r's history puts that line in the field (Prompt.history_row marks a history row's index: a click there was read as an index of the rows); a damaged image's cursor past the rows is held to the last (Command.current); THE STAND-IN: this tree has no questions: Messages.zig's block from `---- a stand-in for line C's questions` to `---- the stand-in's end ----` has `Answer`, `waiting`, `waitingAnswers` and `answer` in the shapes of line C's (vxmpyyst), saying none, and root.zig's allowed_vars line `Messages.zig stub_asked` its test's question: THE MERGE WITH C DELETES BOTH and keeps C's; Command.zig's test asks through the stand-in here and, by `comptime @hasDecl(Messages, "stub_asked")`, through a file changed on disk under unsaved text in C's tree (`ask`, as C's own test asks), nothing to edit; THE FAULT THE SOAK MET (item 2's): `:open ` listed the session's recent files, which are its alone (Core.zig `.authority`): random keys typed `:o ` and the session listed them where a client listed none, so the band under the tag took other rows there (pane tag_rows, rows, the view's rects: the witness's names) and a PDF pane's kind diverged after its view (rtt 30: diverged 31, the tape's answers to the addon short after); now the files the panes show, each once (Command.fileOf, firstOf: replicated, 64 at most); THE FAULT THE 40,000-SEED FUZZ MET (in no code of this line: the dump's layout moved, TagState.worn and Prompt.command, and a seed met it): a dump whose fs.Namespace `opens_len` said 98 of its 64 opens was refused (walk.holdTo), and the load's errdefer (dump.zig loadKnowing) tore the namespace down over `opens[0..opens_len]`: index out of bounds, a panic where a refusal was due; Namespace.deinit holds the length to its opens now; a user restoring a damaged dump could have hit it; TEST FIRST: Command.zig "a question waiting on the pane lists its answers first, each after its key, ruled off; a letter typed only filters them; Tab onto one and Enter gives it" (a click too), fs.zig "a namespace a refused dump left saying more opens than it holds is torn down to its last" (shell-test), item 3's test clicks a history line, item 2's lists the open file; core-test 1025/1192 (167 skipped), shell-test 1239/1242, pane-test 182/184, behaviour-test and its replay 274/277 (the failures A's, as on E's tip), process-test 5 of 146 (the base's: find, builtins, leader, tagnav, ttyhelp), term-test 17/17, kitty-test 45/45; the fuzz at 40,000 join and 1,779 image seeds over a session left in `:theme o` after a Tab (TagState.worn set): pass; THE SOAK, 5 clients, FAILS: diverged 32/0/2 at rtt 30/80/207 (seeds 0-2: a PDF pane's kind state after its view, then the tape's answers to it short; the witness names the band's host pane's and the PDF pane's tag_rows, rows and tag_lead, and the view's rects), and inputs `the mouse in a kind's pane` that may_wait does not list; with `:`'s band held at 0 rows (Command.takes, a temporary edit, put back) the same soak is clean: diverged 0 at 30/80/207, no stop off may_wait: the fault is the band's (A's layout term) in a session with a kind's pane and clients, which no input of the soak reached before `:` (typed by its random keys) opened one; not fixed here
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/Command.zig')
-rw-r--r--core/Command.zig265
1 files changed, 209 insertions, 56 deletions
diff --git a/core/Command.zig b/core/Command.zig
index 4a10e869..6814a0e3 100644
--- a/core/Command.zig
+++ b/core/Command.zig
@@ -1,7 +1,8 @@
//! `:` (walk UI, pick-ui SPEC.md §8): a line typed in the focused pane's
//! tag after a `:` key cell, a text prompt of its own (Prompt.zig's
-//! `.command`). Its rows are the tag's own words in the tag's order (`Kill`
-//! after them for a terminal), marked `in the tag` and ruled off, then the
+//! `.command`). Its rows are the answers of a question waiting on the pane
+//! (SPEC §10.4), then the tag's own words in the tag's order (`Kill` after
+//! them for a terminal), marked `in the tag`, each kind ruled off, then the
//! commands a helix hand types, each the pardes word it runs: `write`
//! Save, `quit` Del, `theme X` Theme X, `set` and `toggle` a setting's
//! word, `reload` Get, `goto N` Look `:N`, `open F` Look F, `sort`,
@@ -12,11 +13,11 @@
//! its argument the rows are what it takes, the rest of the line the
//! query: `:theme ` the themes, the whole window wearing the current one
//! (colors.wear); `:set ` the settings and their values now, then `:set
-//! Wrap ` its values; `:open ` the recent files; `:pipe ` the pipes typed
-//! last. Enter runs the line as B2 runs a word: a command as its pardes
-//! word (`:theme`'s the theme the window wears), anything else Exec'd. `:`
-//! on the empty field gives the keyboard to the tag's own text, as `:` did
-//! before there was a field; `:` there gives it back.
+//! Wrap ` its values; `:open ` the files the panes show; `:pipe ` the
+//! pipes typed last. Enter runs the line as B2 runs a word: a command as
+//! its pardes word (`:theme`'s the theme the window wears), anything else
+//! Exec'd. `:` on the empty field gives the keyboard to the tag's own text,
+//! as `:` did before there was a field; `:` there gives it back.
//!
//! A view's own, as its prompt is (TagState.prompt.command): which rows
//! the hits (TagState.hits) are of, and where in the field Tab writes.
@@ -36,6 +37,7 @@ const TagState = @import("TagState.zig");
const Prompt = @import("Prompt.zig");
const Pipe = @import("Pipe.zig");
const colors = @import("colors.zig");
+const Messages = @import("Messages.zig");
const Pardes = pardes.Pardes;
const Pane = panes.Pane;
const File = panes.File;
@@ -44,17 +46,19 @@ const Key = pardes.Key;
/// What the rows (TagState.hits) are of: the names a line starts with
/// (the tag's words, then the commands); a command's argument (themes, by
/// their index in colors.themes; settings, in config.Settings.settings;
-/// the values of `setting`; the recent files, newest first; the pipe
-/// history, newest first); or none, an argument that is no list (`goto`'s
-/// line).
+/// the values of `setting`; the files the panes show, by the pane's slot;
+/// the pipe history, newest first); or none, an argument that is no list
+/// (`goto`'s line).
pub const Rows = enum(u8) { names, themes, settings, values, files, pipes, none };
rows: Rows = .names,
/// `:set X `'s setting, by its index in config.Settings.settings: the
/// values are its.
setting: u8 = 0,
-/// The names' first rows are the tag's words: how many there were when
-/// the field was filtered (the commands' come after them).
+/// The names' first rows are the waiting question's answers, then the
+/// tag's words: how many of each there were when the field was filtered
+/// (the commands' come after them).
+answers: u8 = 0,
words: u8 = 0,
/// Where the query starts in the field: Tab writes the current row from
/// there.
@@ -81,8 +85,9 @@ const typed = [_]Typed{
.{ .name = "toggle", .arg = "setting", .rows = .settings, .doc = "Flip a setting, or step it to its next value: its word bare." },
};
-/// The tag's words `:` lists at most.
+/// The tag's words `:` lists at most, and a question's answers.
const max_words = 32;
+const max_answers = 8;
/// A row's text at most, its name and what it says beside it.
const row_max = 96;
/// A doc's rows, the fewest the names' band has.
@@ -141,6 +146,7 @@ pub fn filter(p: *Pardes, pane: *Pane) void {
const l = read(line);
c.completed = false;
c.from = 0;
+ c.answers = 0;
c.words = 0;
s.rows = .{};
s.nhits = 0;
@@ -165,13 +171,20 @@ pub fn filter(p: *Pardes, pane: *Pane) void {
switch (c.rows) {
.none => {},
.names => {
+ // A question waiting on the pane: its answers first (SPEC
+ // §10.4), a row each, which a letter typed only filters.
+ for (p.messages.waitingAnswers(pane)) |ans| {
+ if (c.answers == max_answers) break;
+ consider(s, q, ans.word, c.answers);
+ c.answers += 1;
+ }
var words = tagWords(pane);
while (words.next()) |w| {
if (c.words == max_words) break;
- consider(s, q, w, c.words);
+ consider(s, q, w, c.answers + c.words);
c.words += 1;
}
- for (typed, 0..) |t, i| consider(s, q, t.name, c.words + i);
+ for (typed, 0..) |t, i| consider(s, q, t.name, c.answers + c.words + i);
},
.themes => for (colors.themes, 0..) |t, i| consider(s, q, t.name, i),
.settings => {
@@ -183,9 +196,12 @@ pub fn filter(p: *Pardes, pane: *Pane) void {
var i: usize = 0;
while (values.next()) |v| : (i += 1) consider(s, q, v, i);
},
+ // The files the panes show, each once: the session's recent files
+ // are its alone (`.authority`), which a client replaying the key
+ // would not list.
.files => {
const dir = panes.paneDir(pane);
- for (p.recent.entries.items, 0..) |e, i| consider(s, q, shownPath(e.path, dir), i);
+ for (0..p.panes.len) |i| if (fileOf(p, i)) |path| if (firstOf(p, i, path)) consider(s, q, shownPath(path, dir), i);
},
.pipes => {
const r = &p.prompt_history.pipe;
@@ -207,20 +223,41 @@ fn valuesOf(k: u8) std.mem.SplitIterator(u8, .sequence) {
return std.mem.splitSequence(u8, words, ", ");
}
-/// A recent file as its row shows it: under the pane's directory, from
-/// there.
+/// The file pane `i` shows, a text's on disk (not a listing or an
+/// output).
+fn fileOf(p: *const Pardes, i: usize) ?[]const u8 {
+ const other = p.panes[i] orelse return null;
+ const f = other.file orelse return null;
+ if (f.output != null or f.listing != null or f.path.len == 0) return null;
+ return f.path;
+}
+
+/// Whether pane `i` is the first that shows `path`.
+fn firstOf(p: *const Pardes, i: usize, path: []const u8) bool {
+ for (0..i) |k| if (fileOf(p, k)) |other| if (std.mem.eql(u8, other, path)) return false;
+ return true;
+}
+
+/// A file as its row shows it: under the pane's directory, from there.
fn shownPath(path: []const u8, dir: []const u8) []const u8 {
const d = std.mem.trimEnd(u8, dir, "/");
if (d.len > 0 and path.len > d.len + 1 and std.mem.startsWith(u8, path, d) and path[d.len] == '/') return path[d.len + 1 ..];
return path;
}
+/// The current row's place in its source: none without rows, the last
+/// for a cursor past them (a damaged image's).
+fn current(s: *const TagState) ?usize {
+ if (s.nhits == 0) return null;
+ return s.hits[@min(s.rows.at, s.nhits - 1)];
+}
+
/// The window wears the current row while the rows are themes; else its
/// own theme.
fn preview(p: *Pardes) void {
const s = &p.view().tag_state;
const c = &s.prompt.command;
- const worn: ?usize = if (c.rows == .themes and s.nhits > 0) s.hits[s.rows.at] else null;
+ const worn: ?usize = if (c.rows == .themes) current(s) else null;
if (worn == null and s.worn == null) return;
colors.wear(p, worn);
}
@@ -263,16 +300,17 @@ fn tagWords(pane: *Pane) Words {
return .{ .words = std.mem.tokenizeAny(u8, tagline.curTail(pane), " \t\n"), .kill = pane.isTerminal() and pane.command == null };
}
-/// What row `at` of the rows stands for, as Tab writes it: a tag's word,
-/// a command's name, a theme's, a setting's word, a value, a recent file,
-/// a pipe; null past them (a damaged image's).
+/// What row `at` of the rows stands for, as Tab writes it: an answer's
+/// word, a tag's word, a command's name, a theme's, a setting's word, a
+/// value, a file a pane shows, a pipe; null past them (a damaged image's).
fn rowOf(p: *Pardes, pane: *Pane, c: *const Command, at: usize) ?[]const u8 {
switch (c.rows) {
.none => return null,
.names => {
- if (at >= c.words) return if (at - c.words < typed.len) typed[at - c.words].name else null;
+ if (answerAt(p, pane, c, at)) |ans| return ans.word;
+ if (typedAt(c, at)) |t| return typed[t].name;
var words = tagWords(pane);
- var i: usize = 0;
+ var i: usize = c.answers;
while (words.next()) |w| : (i += 1) if (i == at) return w;
return null;
},
@@ -284,11 +322,25 @@ fn rowOf(p: *Pardes, pane: *Pane, c: *const Command, at: usize) ?[]const u8 {
while (values.next()) |v| : (i += 1) if (i == at) return v;
return null;
},
- .files => return if (at < p.recent.entries.items.len) shownPath(p.recent.entries.items[at].path, panes.paneDir(pane)) else null,
+ .files => return shownPath(fileOf(p, if (at < p.panes.len) at else return null) orelse return null, panes.paneDir(pane)),
.pipes => return p.prompt_history.pipe.get(@intCast(@min(at + 1, Prompt.Ring.max + 1))),
}
}
+/// The answer row `at` of the names is, if it is one.
+fn answerAt(p: *const Pardes, pane: *const Pane, c: *const Command, at: usize) ?Messages.Answer {
+ if (c.rows != .names or at >= c.answers) return null;
+ const all = p.messages.waitingAnswers(pane);
+ return if (at < all.len) all[at] else null;
+}
+
+/// The command row `at` of the names is, by its index in `typed`.
+fn typedAt(c: *const Command, at: usize) ?usize {
+ if (c.rows != .names or at < @as(usize, c.answers) + c.words) return null;
+ const t = at - c.answers - c.words;
+ return if (t < typed.len) t else null;
+}
+
/// Tab (`by` 1) and S-Tab (-1): the next row, or the last, written into
/// the field from where the query starts, a command's name with a space
/// after it; the rows stay the line's from before.
@@ -307,13 +359,13 @@ fn step(p: *Pardes, pane: *Pane, by: i32) void {
fn fill(p: *Pardes, pane: *Pane) void {
const s = &p.view().tag_state;
const c = &s.prompt.command;
- const at = s.hits[s.rows.at];
+ const at = current(s) orelse return;
const name = rowOf(p, pane, c, at) orelse return;
var line: [Field.max]u8 = undefined;
var w: std.Io.Writer = .fixed(&line);
w.writeAll(s.field.text()[0..@min(c.from, s.field.len)]) catch return;
w.writeAll(name) catch return;
- if (c.rows == .names and at >= c.words) w.writeByte(' ') catch return;
+ if (typedAt(c, at) != null) w.writeByte(' ') catch return;
s.field.set(w.buffered());
c.completed = true;
s.prompt.recall = 0;
@@ -321,12 +373,24 @@ fn fill(p: *Pardes, pane: *Pane) void {
}
/// A click on row `index` of the rows: it is current, written into the
-/// field as Tab writes it.
+/// field as Tab writes it; an answer is given (SPEC §10.4). On a line of
+/// C-r's history, that line in the field, as Up brings it.
pub fn point(p: *Pardes, index: u16) void {
const s = &p.view().tag_state;
const pane = p.panes[TagState.hostOf(p) orelse return] orelse return;
+ if (index & Prompt.history_row != 0) {
+ const back: u8 = @truncate(index);
+ s.field.set(p.prompt_history.command.get(back) orelse return);
+ s.prompt.recall = back;
+ return filter(p, pane);
+ }
if (index >= s.nhits) return;
s.rows.at = index;
+ if (answerAt(p, pane, &s.prompt.command, s.hits[index])) |ans| {
+ TagState.toRest(p);
+ if (p.messages.waiting(pane)) |i| _ = Messages.answer(p, i, ans.key);
+ return;
+ }
fill(p, pane);
}
@@ -398,6 +462,15 @@ fn allDigits(s: []const u8) bool {
/// and what it says run, in pane `id`, as B2 runs a word.
fn run(p: *Pardes, id: usize, pane: *Pane) void {
const s = &p.view().tag_state;
+ // The current row an answer, written into the field by Tab or a click
+ // or typed whole: given, nothing run (a letter typed never answers).
+ if (current(s)) |at| if (answerAt(p, pane, &s.prompt.command, at)) |ans| {
+ if (s.prompt.command.completed or std.mem.eql(u8, s.field.text(), ans.word)) {
+ TagState.toRest(p);
+ if (p.messages.waiting(pane)) |i| _ = Messages.answer(p, i, ans.key);
+ return;
+ }
+ };
var kept: [Field.max]u8 = undefined;
const line = kept[0..s.field.len];
@memcpy(line, s.field.text());
@@ -445,7 +518,7 @@ pub fn count(p: *Pardes, arena: std.mem.Allocator, text: *std.ArrayList(u8)) !vo
.themes => try text.print(arena, " {d} theme{s} · the window wears the current one", .{ s.nhits, if (s.nhits == 1) "" else "s" }),
.settings => try text.print(arena, " {d} setting{s}", .{ s.nhits, if (s.nhits == 1) "" else "s" }),
.values => try text.print(arena, " {d} value{s}", .{ s.nhits, if (s.nhits == 1) "" else "s" }),
- .files => try text.print(arena, " {d} recent file{s}", .{ s.nhits, if (s.nhits == 1) "" else "s" }),
+ .files => try text.print(arena, " {d} file{s} open", .{ s.nhits, if (s.nhits == 1) "" else "s" }),
.pipes => try text.print(arena, " {d} pipe{s}", .{ s.nhits, if (s.nhits == 1) "" else "s" }),
.none => {
const l = read(s.field.text());
@@ -487,15 +560,19 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator, out: []Band.Step) !usize {
const q = if (c.completed) "" else if (c.rows == .names) read(line).name else line[@min(c.from, line.len)..];
const now = if (c.rows == .settings) try pardes.ctl.settingsText(p) else "";
var widest: usize = 0;
- for (s.hits[win.lo..win.hi]) |at| widest = @max(widest, File.displayWidth(tab, rowOf(p, pane, c, at) orelse "") + aliasWidth(c, at));
+ for (s.hits[win.lo..win.hi]) |at| widest = @max(widest, File.displayWidth(tab, rowOf(p, pane, c, at) orelse "") + aliasWidth(p, pane, c, at));
const rows = try arena.alloc(Band.Row, win.hi - win.lo);
for (rows, win.lo..) |*row, i| {
const at = s.hits[i];
const name = rowOf(p, pane, c, at) orelse "";
var text: std.ArrayList(u8) = .empty;
+ // An answer after its key, in the key ink: `r Reload`.
+ const ans = answerAt(p, pane, c, at);
+ if (ans) |x| try text.print(arena, "{c} ", .{x.key});
+ const lead: u16 = @intCast(text.items.len);
try text.appendSlice(arena, name);
- if (c.rows == .names and at >= c.words and typed[at - c.words].alias.len > 0) try text.print(arena, " {s}", .{typed[at - c.words].alias});
- const said = try saidOf(p, arena, pane, c, at, name, now);
+ if (typedAt(c, at)) |t| if (typed[t].alias.len > 0) try text.print(arena, " {s}", .{typed[t].alias});
+ const said = try saidOf(p, arena, c, at, name, now);
if (said.len > 0) {
for (0..widest + 2 - File.displayWidth(tab, text.items)) |_| try text.append(arena, ' ');
try text.appendSlice(arena, said);
@@ -506,25 +583,27 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator, out: []Band.Step) !usize {
var low: [row_max]u8 = undefined;
const t = name[0..@min(name.len, low.len)];
_ = Names.match(q, t, std.ascii.lowerString(&low, t), 0, &marks, &nmarks);
+ for (marks[0..nmarks]) |*m| m.* += lead;
}
- // The tag's last word ruled off from the commands under it.
- const last_word = c.rows == .names and at + 1 == c.words and i + 1 < s.nhits;
- row.* = .{ .text = text.items, .on = i == s.rows.at, .marks = try arena.dupe(u16, marks[0..nmarks]), .index = @intCast(i), .under = last_word };
+ // The answers' last and the tag's last word ruled off from what is
+ // under them.
+ const last = c.rows == .names and i + 1 < s.nhits and (at + 1 == c.answers or at + 1 == @as(usize, c.answers) + c.words);
+ row.* = .{ .text = text.items, .on = i == s.rows.at, .key = if (ans != null) 1 else 0, .marks = try arena.dupe(u16, marks[0..nmarks]), .index = @intCast(i), .under = last };
}
out[0] = .{ .rows = rows };
if (c.rows != .names) return 1;
- out[1] = .{ .rows = try docRows(p, arena, pane, c, s.hits[s.rows.at]), .doc = true };
+ out[1] = .{ .rows = try docRows(p, arena, pane, c, current(s).?), .doc = true };
return 2;
}
/// What row `at` says on its right: a tag's word `in the tag`, what a
/// command takes, the theme in use, a setting's value now (its line of
-/// the settings' text `now`), the value it has, a file open in a pane.
-fn saidOf(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, c: *const Command, at: usize, name: []const u8, now: []const u8) ![]const u8 {
+/// the settings' text `now`), the value it has.
+fn saidOf(p: *Pardes, arena: std.mem.Allocator, c: *const Command, at: usize, name: []const u8, now: []const u8) ![]const u8 {
switch (c.rows) {
.names => {
- if (at < c.words) return "in the tag";
- const t = typed[at - c.words];
+ if (at < c.answers) return "answers the question";
+ const t = typed[typedAt(c, at) orelse return "in the tag"];
return if (t.arg.len > 0) try std.fmt.allocPrint(arena, "<{s}>", .{t.arg}) else "";
},
.themes => return if (p.custom_theme == null and at == p.settings.theme) "in use" else "",
@@ -538,11 +617,7 @@ fn saidOf(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, c: *const Command,
const value = valueNow(p, c.setting, &buf);
return if (std.mem.eql(u8, value, name)) "now" else "";
},
- .files => {
- _ = pane;
- return if (at < p.recent.entries.items.len and p.recent.entries.items[at].open) "open" else "";
- },
- .pipes, .none => return "",
+ .files, .pipes, .none => return "",
}
}
@@ -561,9 +636,11 @@ fn valueNow(p: *Pardes, k: u8, buf: []u8) []const u8 {
return std.fmt.bufPrint(buf, "{s}", .{value}) catch "";
}
-fn aliasWidth(c: *const Command, at: usize) usize {
- if (c.rows != .names or at < c.words) return 0;
- const alias = typed[at - c.words].alias;
+/// The cells a row takes besides its name: an answer's key, a command's
+/// short name.
+fn aliasWidth(p: *const Pardes, pane: *const Pane, c: *const Command, at: usize) usize {
+ if (answerAt(p, pane, c, at) != null) return 2;
+ const alias = typed[typedAt(c, at) orelse return 0].alias;
return if (alias.len == 0) 0 else alias.len + 1;
}
@@ -572,8 +649,13 @@ fn aliasWidth(c: *const Command, at: usize) usize {
fn docRows(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, c: *const Command, at: usize) ![]const Band.Row {
const rows = try arena.alloc(Band.Row, 2);
const none = std.math.maxInt(u16);
- if (at >= c.words) {
- const t = typed[at - c.words];
+ if (answerAt(p, pane, c, at)) |ans| {
+ rows[0] = .{ .text = try std.fmt.allocPrint(arena, "{c} {s}", .{ ans.key, ans.word }), .key = 1, .index = none };
+ rows[1] = .{ .text = "An answer to the question waiting on this pane: ⏎ gives it.", .index = none };
+ return rows;
+ }
+ if (typedAt(c, at)) |k| {
+ const t = typed[k];
const head = try std.fmt.allocPrint(arena, ":{s}{s}{s}{s}", .{ t.name, if (t.alias.len > 0) " " else "", t.alias, if (t.arg.len > 0) try std.fmt.allocPrint(arena, " <{s}>", .{t.arg}) else "" });
rows[0] = .{ .text = head, .key = @intCast(1 + t.name.len), .index = none };
rows[1] = .{ .text = t.doc, .index = none };
@@ -692,7 +774,7 @@ test ": on the empty field gives the keyboard to the tag's own text, and : there
try std.testing.expectEqual(panes.Pane.Focus.body, pane.focus);
}
-test ":theme lists the themes and the whole window wears the current one, none dimmed; Tab steps it on, Esc puts the window's own back, Enter keeps the one worn; :set lists the settings with their values, then a setting's values; :pipe the pipes typed last; :open the recent files" {
+test ":theme lists the themes and the whole window wears the current one, none dimmed; Tab steps it on, Esc puts the window's own back, Enter keeps the one worn; :set lists the settings with their values, then a setting's values; :pipe the pipes typed last; :open the files the panes show" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 });
defer p.deinit();
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
@@ -774,12 +856,11 @@ test ":theme lists the themes and the whole window wears the current one, none d
try std.testing.expect(has(try bandRow(p, a, 0), "▶ tr a-z A-Z"));
p.update(.{ .key = .{ .cp = Key.escape } });
- // :open: the recent files, from the pane's directory.
- p.recent.opened(p.recentGpa(), "/elsewhere/notes.txt");
- typeKeys(p, ":open no");
+ // :open: the files the panes show, from the pane's directory.
+ typeKeys(p, ":open te");
try std.testing.expectEqual(Rows.files, s.prompt.command.rows);
- try std.testing.expect(has(try bandRow(p, a, 0), "▶ /elsewhere/notes.txt"));
- try std.testing.expect(has(try tagOf(p), " = Look no 1 recent file "));
+ try std.testing.expect(has(try bandRow(p, a, 0), "▶ /test.txt"));
+ try std.testing.expect(has(try tagOf(p), " = Look te 1 file open "));
p.update(.{ .key = .{ .cp = Key.escape } });
}
@@ -820,6 +901,78 @@ test ": has a history of its own: Up and Down bring back the lines Enter ran, ne
band = (try Band.of(p, a, pane, p.view().active)).?;
try std.testing.expectEqual(@as(usize, 1), band.steps[0].rows.len);
try std.testing.expectEqualStrings("set Wrap off", band.steps[0].rows[0].text);
+ // A click on it: the line in the field, its rows made for it.
+ TagState.point(p, band.steps[0].rows[0].index);
+ try std.testing.expectEqualStrings("set Wrap off", s.field.text());
+ try std.testing.expectEqual(Rows.values, s.prompt.command.rows);
p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expectEqual(TagState.Kind.rest, s.kind);
}
+
+/// A question waiting on `pane`: in this tree the stand-in's
+/// (Messages.zig), in line C's a file changed on disk under its unsaved
+/// text, as C's own test asks one.
+fn ask(p: *Pardes, pane: *Pane, tmp: *std.testing.TmpDir, disk: []const u8) !void {
+ if (comptime @hasDecl(Messages, "stub_asked")) {
+ Messages.stub_asked = pane.serial;
+ return;
+ }
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.zig", .data = "one\ntwo\n" });
+ var dir: [4096]u8 = undefined;
+ const path = try std.fmt.allocPrint(p.gpa, "{s}/c.zig", .{dir[0..try tmp.dir.realPath(std.testing.io, &dir)]});
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = path;
+ const f = &pane.file.?;
+ f.saved_hash = File.fileHash(f);
+ typeKeys(p, "Gofour\x1b");
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.zig", .data = disk });
+ p.update(.{ .file_changed = .{ .pane = .at(p.view().active), .bytes = disk } });
+}
+
+test "a question waiting on the pane lists its answers first, each after its key, ruled off; a letter typed only filters them; Tab onto one and Enter gives it" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 });
+ defer p.deinit();
+ defer if (comptime @hasDecl(Messages, "stub_asked")) {
+ Messages.stub_asked = 0;
+ };
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const pane = try p.setTestFile("one\ntwo\n");
+ try ask(p, pane, &tmp, "zero\none\ntwo\n");
+ try std.testing.expect(p.messages.waiting(pane) != null);
+ const s = &p.view().tag_state;
+ typeKeys(p, ":");
+ try std.testing.expect(has(try bandRow(p, a, 0), "▶ r Reload "));
+ try std.testing.expect(has(try bandRow(p, a, 0), "answers the question"));
+ try std.testing.expect(has(try bandRow(p, a, 2), " d Diff "));
+ const band = (try Band.of(p, a, pane, p.view().active)).?;
+ try std.testing.expect(band.steps[0].rows[2].under and !band.steps[0].rows[1].under);
+ try std.testing.expect(has(band.steps[0].rows[3].text, "Save"));
+ // A letter typed filters them: it never answers.
+ typeKeys(p, "r");
+ try std.testing.expectEqualStrings("r", s.field.text());
+ try std.testing.expect(p.messages.waiting(pane) != null);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // A click on `Keep mine`: given.
+ typeKeys(p, ":");
+ TagState.point(p, 1);
+ try std.testing.expectEqual(TagState.Kind.rest, s.kind);
+ try std.testing.expect(p.messages.waiting(pane) == null);
+ // Asked again: Tab onto `Keep mine`, Enter: given.
+ try ask(p, pane, &tmp, "zero\nzero\none\ntwo\n");
+ try std.testing.expect(p.messages.waiting(pane) != null);
+ typeKeys(p, ":kee");
+ try std.testing.expect(has(try bandRow(p, a, 0), "▶ k Keep mine"));
+ p.update(.{ .key = .{ .cp = Key.tab } });
+ try std.testing.expectEqualStrings("Keep mine", s.field.text());
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqual(TagState.Kind.rest, s.kind);
+ try std.testing.expect(p.messages.waiting(pane) == null);
+ // None waiting: none listed.
+ typeKeys(p, ":");
+ try std.testing.expect(has(try bandRow(p, a, 0), "▶ Save "));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+}