diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-26 05:06:32 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-26 05:06:38 -0300 |
| commit | 8250d4afc108e690a6377b40a3887c80ccca3f3c (patch) | |
| tree | ad7ee1c2362b127b759199b782ab1b1b2ec41c39 /core/Command.zig | |
| parent | ac39b5e4f80e1903abccd1e003850e9691e61022 (diff) | |
| download | pardes-8250d4afc108e690a6377b40a3887c80ccca3f3c.tar.gz pardes-8250d4afc108e690a6377b40a3887c80ccca3f3c.zip | |
Command, docs: every word that left a tag still runs from `:`, its rows listing after the tag's words the words of the pane's kind the tag does not show now, marked `for this pane`, and the docs that show tags show the lean ones (UX DESIGN K'4, binding: "every one keeps a key, the `:` line, and a typed word"); THE OLD WAY: `:`'s rows were the tag's words (`in the tag`), then the commands; since K'1 and K'3 a clean file's tag holds `Del` alone, so `Save`, `Term`, `Collapse`, `Follow`, `Def`, `Refs`, `TreeContext`, `Mode`, `Filter` and a file's `Undo`/`Redo` were in no row a hand could find from `:`, and the cheatsheet, the guide, the docs' README and the tutor still drew the old tags (`Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Fonts Config History Debug Exit`, `Save Term Collapse Follow Del`, a terminal's `Term+bash Save Mode Filter Collapse Del`, a command pane's `Kill Save Collapse Del`) and told the hand to click `Collapse` in a tag; THE CHANGE: Command.Others, the words of tagline.kindTail (the tag a pane of its kind had before K', kept for this and for dropOldTags) the tag does not show now, then a file's `Undo` and `Redo` (not a query's: its text is its rows), each a row after the tag's words, said `for this pane` beside it and in its doc row, the last ruled off as the tag's last is; Command.others counts them beside Command.words (a view's state: the dump fuzz and the soak), the commands' rows after them, all of them bounded by max_words (32); Enter runs the line as B2 runs a word, as before, so any builtin, Joincol too, runs from `:`; the docs: docs/typ/cheatsheet.typ and guide.typ draw the window row `Find Grep Newcol Help Exit`, a column's tag `New Term Joincol Delcol`, a file's `Save Undo Del`, a terminal's `Del Term+bash`, a PDF's `PdfSections PdfTint PdfFit Del`, a command pane done `Del`, and say in a line each where the rest went (the words that act now; the others from `:` and typed; the lone column's `New Term` at the window row's left, a second column bringing the column row); docs/typ/README's tag() example `Save Undo Del`; core/tutor.txt's tag lines the same, its step 1 `: :` to the tag after its words and `i Help`, step 2 `Collapse` from `:` (`Coll`, Enter) instead of a click on a word that is gone; config.zig's docs check (doc_typ.tag) takes the window row's and the column tags' words and K'3's pane tags at rest (`Keep Del`, `Del`, `Save Undo Del`, `Undo Del`, `Kill Del`, `Get Del`, `Filter Del`, `Del Term`), a kind's its addon's words then `Del`; A FAULT OF THE CHANGE BEFORE THIS ONE, found by its shot of the comparison video's found moment (84x20 tty: `New Term Find Grep Newcol Help Exit` run together at the window row's left): tagline.windowRow made room for a server's progress after the window's words whether or not the row had it (zls's `lsp zls ready — <the session's directory>` stays live while the server runs), so a long one pushed the words left against the column's while draw.zig, finding no room, drew no progress; THE FIX: windowRow counts the progress only where the row holds it beside the column's words (the one rule draw reads too); a user hit it in any window narrower than its words, the column's and the progress; TESTS (FIRST): tagline.zig "a server's progress goes after the window's words where the row has room for it, and moves them by nothing where it has not (UX K'2)" (84 columns: a progress too long leaves the words at 56, a short one moves them left by its 9 cells and the 2 between; without the fix `expected 56, found 12`), Command.zig ": lists the words of the pane's kind its tag does not show now, `for this pane`: Save while the file is clean, Collapse, Undo; Enter runs any builtin as B2 does, Joincol too (UX K'4)" (a clean file reading: `Del` in the tag, ruled off; `Save Term Collapse Follow Undo Redo` for this pane, `Redo` ruled off; `write` after them; `Coll` filters to Collapse with its doc for this pane; `:Joincol` Enter from two columns leaves one); TESTS CHANGED: Command.zig's first `:` test (a typed-into file: 18 commands, its kind's `Term Collapse Follow Redo` for this pane between its tag's `Save Undo Del` and `write`); GOLDENS: none moved (process-test with --update re-recorded none; ttyhelp is the next change's: its `:` and tutor text are on no snap); GATES (after the fix): core-test 1132/1305 (173 skipped: +2), shell-test 1353/1356 (3 skipped: +2), pane-test 183/184 (1 skipped), behaviour-test 280/280 and --replay 20 seeds of 70 steps 0 failures, process-test 1 of 147 failed (ttyhelp, re-recorded by the next change; 3 skipped), term-test 17/17, kitty-test 45/45; the dump fuzz at 40,000 join seeds twice and 1,779 image seeds 11/11 (Command gained a field: a view's state is in the dump; run before the fix, which changes no field); the soak `replicas -- --clients 5 --rtt 30,80,207` (after the fix): diverged 0, unequal 0, agree/differ 531/0 392/0 680/0, unlisted stops 0, the corpus 22 of 22 scenes the same, no leak; the gui unit-test on the next change (its code is this one's: it changes one golden); no frame/perf gate (the coordinator's, at the programme's end); load 1.6 to 8.5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/Command.zig')
| -rw-r--r-- | core/Command.zig | 128 |
1 files changed, 110 insertions, 18 deletions
diff --git a/core/Command.zig b/core/Command.zig index d0d8d2d3..f41d0639 100644 --- a/core/Command.zig +++ b/core/Command.zig @@ -2,8 +2,9 @@ //! tag after a `:` key cell, a text prompt of its own (Prompt.zig's //! `.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` +//! them for a terminal), marked `in the tag`, then the words of the pane's +//! kind its tag does not show now (UX K'4), marked `for this pane`, 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` Find F, `sort`, //! `reflow` and `pipe` a pipe of the selections. The field filters them by @@ -57,10 +58,11 @@ rows: Rows = .names, /// values are its. setting: u8 = 0, /// 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). +/// tag's words, then the pane's others: how many of each there were when +/// the field was filtered (the commands' come after them). answers: u8 = 0, words: u8 = 0, +others: u8 = 0, /// Where the query starts in the field: Tab writes the current row from /// there. from: u16 = 0, @@ -86,7 +88,8 @@ 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, and a question's answers. +/// The tag's words and the pane's others `:` 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. @@ -149,6 +152,7 @@ pub fn filter(p: *Pardes, pane: *Pane) void { c.from = 0; c.answers = 0; c.words = 0; + c.others = 0; s.rows = .{}; s.nhits = 0; s.ntotal = 0; @@ -195,7 +199,13 @@ pub fn filter(p: *Pardes, pane: *Pane) void { consider(s, q, w, c.answers + c.words); c.words += 1; } - for (typed, 0..) |t, i| consider(s, q, t.name, c.answers + c.words + i); + var others = otherWords(pane); + while (others.next()) |w| { + if (c.words + c.others == max_words) break; + consider(s, q, w, c.answers + c.words + c.others); + c.others += 1; + } + for (typed, 0..) |t, i| consider(s, q, t.name, c.answers + c.words + c.others + i); }, .themes => for (colors.themes, 0..) |t, i| consider(s, q, t.name, i), .settings => { @@ -287,6 +297,37 @@ fn tagWords(pane: *Pane) Words { return .{ .computed = std.mem.tokenizeAny(u8, tagline.computedWords(pane), " "), .own = std.mem.tokenizeAny(u8, tagline.curTail(pane), " \t\n"), .kill = pane.isTerminal() and pane.command == null }; } +/// The words of the pane's kind its tag does not show now (UX K'4): those +/// its tag had before K' (tagline.kindTail: Save while clean, Term, +/// Collapse, Follow, Def, Refs, TreeContext, Mode, Filter, ...), then a +/// file's Undo and Redo (u, U); each runs from `:` as it ran from the tag. +const Others = struct { + pane: *Pane, + kind: std.mem.TokenIterator(u8, .scalar), + edits: u8, + + fn next(o: *Others) ?[]const u8 { + while (true) { + const word = o.kind.next() orelse edit: { + const all = [_][]const u8{ "Undo", "Redo" }; + if (o.edits == all.len) return null; + o.edits += 1; + break :edit all[o.edits - 1]; + }; + var shown = tagWords(o.pane); + while (shown.next()) |w| { + if (std.mem.eql(u8, w, word)) break; + } else return word; + } + } +}; + +fn otherWords(pane: *Pane) Others { + // A query's text is its rows (Query.zig): none of a file's edits. + const edits = pane.file != null and pane.query == null; + return .{ .pane = pane, .kind = std.mem.tokenizeScalar(u8, tagline.kindTail(pane), ' '), .edits = if (edits) 0 else 2 }; +} + /// 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). @@ -299,6 +340,8 @@ fn rowOf(p: *Pardes, pane: *Pane, c: *const Command, at: usize) ?[]const u8 { var words = tagWords(pane); var i: usize = c.answers; while (words.next()) |w| : (i += 1) if (i == at) return w; + var others = otherWords(pane); + while (others.next()) |w| : (i += 1) if (i == at) return w; return null; }, .themes => return if (at < colors.themes.len) colors.themes[at].name else null, @@ -322,8 +365,9 @@ fn answerAt(p: *const Pardes, pane: *const Pane, c: *const Command, at: usize) ? /// 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; + const before = @as(usize, c.answers) + c.words + c.others; + if (c.rows != .names or at < before) return null; + const t = at - before; return if (t < typed.len) t else null; } @@ -571,9 +615,9 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator, out: []Band.Step) !usize { _ = Names.match(q, t, std.ascii.lowerString(&low, t), 0, &marks, &nmarks); for (marks[0..nmarks]) |*m| m.* += lead; } - // 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); + // The answers' last, the tag's last word and the pane's last other + // 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 or at + 1 == @as(usize, c.answers) + c.words + c.others); 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 }; @@ -582,14 +626,14 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator, out: []Band.Step) !usize { 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 +/// What row `at` says on its right: a tag's word `in the tag`, the pane's +/// others `for this pane`, what a command takes, the theme in use, a setting's value now (its line of /// 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.answers) return "answers the question"; - const t = typed[typedAt(c, at) orelse return "in the tag"]; + const t = typed[typedAt(c, at) orelse return wordSaid(c, at)]; 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 "", @@ -607,6 +651,11 @@ fn saidOf(p: *Pardes, arena: std.mem.Allocator, c: *const Command, at: usize, na } } +/// What a word row says: in the tag, or one of the pane's others. +fn wordSaid(c: *const Command, at: usize) []const u8 { + return if (at < @as(usize, c.answers) + c.words) "in the tag" else "for this pane"; +} + /// Setting `k`'s value now, as its word is written: `on`, `walk`. fn valueNow(p: *Pardes, k: u8, buf: []u8) []const u8 { const st = config.Settings.settings[@min(k, config.Settings.settings.len - 1)]; @@ -648,7 +697,7 @@ fn docRows(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, c: *const Command, return rows; } const name = rowOf(p, pane, c, at) orelse ""; - rows[0] = .{ .text = try std.fmt.allocPrint(arena, "{s} in the tag", .{name}), .key = @intCast(name.len), .index = none }; + rows[0] = .{ .text = try std.fmt.allocPrint(arena, "{s} {s}", .{ name, wordSaid(c, at) }), .key = @intCast(name.len), .index = none }; rows[1] = .{ .text = if (std.meta.stringToEnum(pardes.Builtin, name)) |b| builtins.registry.doc(b).text else "A word of this pane's tag: ⏎ runs it, as B2 on it does.", .index = none }; return rows; } @@ -704,7 +753,7 @@ test ": opens a field in the tag after its key cell: the tag's own words first, try std.testing.expectEqual(Prompt.Op.command, s.prompt.op); try std.testing.expectEqual(panes.Pane.Focus.body, pane.focus); // The head: its key cell, the field, the count, the hints. - try std.testing.expect(has(try tagOf(p), ": 14 commands Tab complete · ⏎ run · C-r history · esc")); + try std.testing.expect(has(try tagOf(p), ": 18 commands Tab complete · ⏎ run · C-r history · esc")); // The rows: the tag's words in its order, `in the tag`, the last ruled // off; then the commands, each what it takes. try std.testing.expect(has(try bandRow(p, a, 0), "▶ Save ")); @@ -715,8 +764,11 @@ test ": opens a field in the tag after its key cell: the tag's own words first, const band = (try Band.of(p, a, pane, p.view().active)).?; const first = band.steps[0].rows; try std.testing.expect(first[2].under and !first[1].under); - try std.testing.expect(has(first[3].text, "write w")); - try std.testing.expect(has(first[5].text, "theme") and has(first[5].text, "<theme>")); + // Then its kind's words the tag does not show (UX K'4), ruled off too. + try std.testing.expect(has(first[3].text, "Term for this pane")); + try std.testing.expect(first[6].under and has(first[6].text, "Redo")); + try std.testing.expect(has(first[7].text, "write w")); + try std.testing.expect(has(first[9].text, "theme") and has(first[9].text, "<theme>")); // Typing filters both, by the scorer, in their order. typeKeys(p, "th"); try std.testing.expect(has(try tagOf(p), ": th = Exec th 1 command ")); @@ -995,3 +1047,43 @@ test "a question waiting on the pane lists its answers first, each after its key try std.testing.expect(has(try bandRow(p, a, 0), "▶ Save ")); p.update(.{ .key = .{ .cp = Key.escape } }); } + +test ": lists the words of the pane's kind its tag does not show now, `for this pane`: Save while the file is clean, Collapse, Undo; Enter runs any builtin as B2 does, Joincol too (UX K'4)" { + 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); + defer frame.deinit(); + const a = frame.allocator(); + const pane = try p.setTestFile("one\n"); + const id = p.view().active; + // A file reading, clean: its tag's word `Del` (`Keep` is its walk's, + // after its path); the words its kind had before UX K' and a file's + // edits are the rest, in that order. + typeKeys(p, ":"); + const s = &p.view().tag_state; + try std.testing.expectEqual(@as(u8, 1), s.prompt.command.words); + try std.testing.expectEqual(@as(u8, 6), s.prompt.command.others); + const rows = (try Band.of(p, a, pane, id)).?.steps[0].rows; + try std.testing.expect(has(rows[0].text, "Del in the tag") and rows[0].under); + try std.testing.expect(has(rows[1].text, "Save for this pane")); + try std.testing.expect(has(rows[3].text, "Collapse for this pane")); + try std.testing.expect(has(rows[5].text, "Undo for this pane")); + try std.testing.expect(has(rows[6].text, "Redo for this pane") and rows[6].under); + try std.testing.expect(has(rows[7].text, "write w")); + // Its doc is the builtin's, said for this pane. + typeKeys(p, "Coll"); + try std.testing.expect(has(try bandRow(p, a, 0), "▶ Collapse ")); + try std.testing.expect(has(try bandRow(p, a, 0), "Collapse for this pane")); + p.update(.{ .key = .{ .cp = Key.escape } }); + // Enter runs the line as B2 runs a word: Joincol, in no pane's tag, + // from two columns folds this one into the one on its right. + try std.testing.expect(p.executeBuiltinLine(id, "Newcol")); + tagline.exitHeader(p); + p.view().active = id; + p.sync(); + try std.testing.expectEqual(@as(usize, 2), p.view().ncol); + typeKeys(p, ":Joincol"); + p.update(.{ .key = .{ .cp = Key.enter } }); + try std.testing.expectEqual(@as(usize, 1), p.view().ncol); + try std.testing.expectEqualStrings("one\n", pane.file.?.content); +} |
