diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-26 00:03:50 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-26 02:04:52 -0300 |
| commit | 13d234f431a98bf97fcc1caec812f59eff711aa0 (patch) | |
| tree | db88980c1cd3fafb4e56e66ea6387f1f2bdd6eb4 /core | |
| parent | 94f00e966c908d370e34ed5e0496a86b33de26d6 (diff) | |
| download | pardes-13d234f431a98bf97fcc1caec812f59eff711aa0.tar.gz pardes-13d234f431a98bf97fcc1caec812f59eff711aa0.zip | |
tagline, edit, dump, layout: a pane tag reads its path, then its computed words, the words that act now, read-only and made again from its state as the path is, then the user's text (UX DESIGN K'1, K'3, binding; the user: "pardes looked so cramped and full of information with the taglines compared to the other editors", "I liked C and D"); THE OLD WAY: a tag's words were its own text (`tag.own`, or until edited its kind's default `*_tail`: `Save Term Collapse Follow Del`, a speaking file's `Def Refs`, `TreeContext`, `LocationsConfig`, a terminal's `Term Save Mode Filter Collapse Del`), the same in every state, so a file tag held 5 to 9 command words, wrapped to a second row at 84 columns, and `Save` stood there clean; THE CHANGE: tagline.computedWords per K'3's table (a file reading `Keep Del`, `Keep` its walk's word after the path as before; held `Del`, `Undo` while its journal has a step back with something in it (insert mode's `i` alone marks a step of none: a behaviour test caught `Undo` coming, and a 24-column tag wrapping, before a key was typed), `Redo` while it has one forward; unsaved, gone from disk too, `Save Undo Del`; `Diff` first for a diff, a +Pager holding one and the Diff view; `Filter` for a +Pager; a +New never `Save` (the table's `Del; Undo once typed into`); a directory `Get Del`; a command pane `Kill Del` running, `Del` done; queries and the preview unchanged; a kind its own words then `Del` (Kind.reopen, `Term` and `Collapse` gone); a terminal `Del`, its shell's word after it as its text, `Term` until the shell says its name, then `Term+fish`, as before), a comptime table of the 32 file combinations, no allocation; restPrefix = path, computed words and a blank, the prefix every edit must leave as it is (edit.setEditTextSpan, which compared the path alone) and the 9P cleartag's caret goes after; `tag.own` holds only what the user typed (curTail: own, else a terminal's shell word, else none), shown after the computed words and never regenerated; enterTag puts the caret at the start of the user's text, no longer on `Save`; a question waiting at rest (TagState.asks, the test TagState.asking used) replaces the computed words with the own text, as out of rest (D13, D1 unchanged: prefixIn gives the path alone, sync keeps the tag's offsets at rest); `:` lists the computed words, then the own text's, `in the tag`; Follow's `Unfollow` goes in the new page's own text with no second blank; RESTORE: dump.dropOldTags drops an own text equal to its kind's tag before K' (tagline.kindTail, the old defaults kept for it) where a Restore, a start from a dump and an Upgrade load (loadAndRevive; a replica's join loads its authority's, dropped there; a Restore replays through the same path), any other kept whole as the user's text; THE LAYOUT (two faults the lean tags let the random placements find, ninep/tree.zig "random placements ... leave no pane under its tag and two rows"): (1) seed 273 (core-test): `Edit =` gave a full column's +Errors an undo step, `Undo` wrapped its 16-cell tag onto a 5th row, the pane under its minimum, no row to give: layout.minRows now counts a tag with the widest computed words its pane can come to show (tagline.widestWords: `Save Undo Redo` where it saves, a query's frozen words; a reading pane's own, its first edit holds it), so an edit never takes a row its placement did not leave; (2) seed 162 and 192 (shell-test): a walk step in a 12-cell tag whose basename did not fit beside its newest step (`test.txt:1 › …f.txt Keep Del`), the fold had nothing left to cut: tagline.folded then folds that step into the `+N` too (D2's basename stays whole; a hunk in the fold W4 touches); TESTS (FIRST): tagline.zig "a pane tag's computed words are the words that act now, its own text after them (UX K'1, K'3)" (reading, held, typed twice, undone, saved, a .patch, a pager, a pager's diff, a +New before and after typing, a kind), "typing in a tag goes after its computed words, and stays the user's text through a change of state" (`Mine` typed after `Del`, a Backspace on the blank before it refused, the body typed into: `Save Undo Del Mine`, the caret still on `M`), "a dump of a build before UX K' restores a tag's old default own text as none, any other as the user's"; TESTS CHANGED, each for a word gone from a tag: lsp/Ask.zig Def/Refs (the 2-1 chord now on `Def Refs` typed into the tag's own text, kindTail asserts the kind's words), Effect.zig "Save is a word of every pane with text behind it and no other" (kindTail, computedWords `Del` while clean), Core.zig TreeContext (kindTail, the tag holds no TreeContext), Filter (computedWords `Filter Del`), pane-tag Exec (`Term+sh` the text; `Theme dark` and the fallback word found where they are), compact tag commands (`Del Term`), Term+ paths (`Term+/bin/sh`, `Term+sh`), the command pane's and REPL's prefixes (pathPrefix), Dir (`Get Del`), Stream (`More Del`), jj At (pathPrefix), Pipe (`| tr` on the own text `Look here`), Command.zig `:` (typed into first: `Save Undo Del` its tag's rows, 14 commands), Trail.zig (W4's file: tags `/test.txt Del `, `rank.zig Del `; the Fixture 120 to 200 columns, as its 85-cell tmp paths beside a short tag folded the walks these tests read; "too short to halve" 24 to 20 rows), TagState and Band (a tag of two rows: own text given), Messages (the question test at 200 columns, the tag at rest one row), dev/tui/tui.zig (a terminal view's wrapped tag read on across its rows: the shorter prefix cut `w19`), test/mode.zig (`Mode` typed into the terminal tag's own text, kindTail has it), test/panes.zig (an image's pathPrefix); BEHAVIOUR (a helper's edits, each a word moved): tags.zig (a tag's keyboard starts on its own text, so `Save Term`, `Save`, `JumpTrail` are written into the own text where a test clicked or edited them; expected tags `/test.txt Del ...`), keys.zig (a scratch's Save prompt by `SPC f s`, was `::` Tab), modes.zig, mouse.zig (`Keep Del`, the own text swept), panes.zig ("an unsaved file's tag ... Save and Undo come into its words", Collapse by `C-w c`), placement.zig, terminals.zig (`Del Term`), addons_pdf.zig (`PdfSections PdfTint PdfFit Del`), columns_and_tags.zig; addons/fake/fake.out and addons/life/life.out re-recorded (a tag one row shorter: one more body row); PROCESS (a helper's edits): 11 cases clicked a word gone or a row a shorter tag moved (lookpanes, selarg, tagnav, tag, images, collapse, layout-open, ghostty-mid, look-fd-deep, respawn, ttylook: each to the word's new place, the own text or the row it moved to) and 5 more whose clicks had silently stopped doing what their comments say (shrinktag, windowops, ttyedit, tagcmd, chordcut); GOLDENS: 101 re-recorded, every change one of: a tag's words (`Term+bash Save Mode Filter Collapse Del` to `Del Term+bash`), a tag no longer wrapping (its body a row taller, the rows under it up one, one more line at the foot), splits a row smaller where a tag above stopped wrapping, a click at a fixed row landing a body row lower, the computed words' ink in style rows; three now do what their comments say where the old golden recorded a miss (chordcut's end, jumps' look-row, wrap's logical-j); ttyhelp.golden left as the merge's placeholder (M1's; this change moves it too); core-test 1126/1299 (173 skipped: +3), shell-test 1347/1350 (3 skipped), 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, the placeholder; 3 skipped), term-test 17/17, kitty-test 45/45, the gui unit-test 1949/1954 (4 skipped; its one failure colors.zig's whole-ring CPU timing at a load of 8.7, L1's, passing in core-test, and the known BaselineHarnessMismatch); the soak `replicas -- --clients 5 --rtt 30,80,207`: diverged 0, unequal 0, agree/differ 451/0 420/0 623/0, unlisted stops 0, the corpus 22 of 22 scenes the same, no leak; no dump field changes (no fuzz); no frame/perf gate (moved to the programme's end); load 2.6 to 10.5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core')
| -rw-r--r-- | core/Band.zig | 4 | ||||
| -rw-r--r-- | core/Command.zig | 25 | ||||
| -rw-r--r-- | core/Core.zig | 56 | ||||
| -rw-r--r-- | core/Dir.zig | 2 | ||||
| -rw-r--r-- | core/Effect.zig | 19 | ||||
| -rw-r--r-- | core/File.zig | 13 | ||||
| -rw-r--r-- | core/Kind.zig | 4 | ||||
| -rw-r--r-- | core/Messages.zig | 3 | ||||
| -rw-r--r-- | core/Pipe.zig | 13 | ||||
| -rw-r--r-- | core/Stream.zig | 2 | ||||
| -rw-r--r-- | core/TagState.zig | 15 | ||||
| -rw-r--r-- | core/Trail.zig | 8 | ||||
| -rw-r--r-- | core/builtins.zig | 3 | ||||
| -rw-r--r-- | core/dump.zig | 15 | ||||
| -rw-r--r-- | core/edit.zig | 9 | ||||
| -rw-r--r-- | core/jj.zig | 2 | ||||
| -rw-r--r-- | core/layout.zig | 14 | ||||
| -rw-r--r-- | core/lsp/Ask.zig | 10 | ||||
| -rw-r--r-- | core/ninep/pane.zig | 2 | ||||
| -rw-r--r-- | core/tagline.zig | 297 |
20 files changed, 391 insertions, 125 deletions
diff --git a/core/Band.zig b/core/Band.zig index 8ee5c9f0..4b56b0b8 100644 --- a/core/Band.zig +++ b/core/Band.zig @@ -681,6 +681,8 @@ test "a narrow band gives way and keeps its spines: the doc goes, the steps star defer p.deinit(); const pane = try p.setTestFile("one\n"); const id = p.view().active; + // Its own text past a row: the tag takes two (UX K'1). + pane.tag.own = try p.gpa.dupe(u8, "words of the user's own that run on past a row"); p.sync(); const rest = pane.tag_rows; try std.testing.expect(rest > 1); @@ -716,6 +718,8 @@ test "out of rest with no band, the rows a tag keeps from rest stay blank: a spi defer p.deinit(); const pane = try p.setTestFile("one\n"); const id = p.view().active; + // Its own text past a row: the tag takes two (UX K'1). + pane.tag.own = try p.gpa.dupe(u8, "words of the user's own that run on past a row"); p.sync(); const rest = pane.tag_rows; try std.testing.expect(rest > 1); diff --git a/core/Command.zig b/core/Command.zig index 908358de..d0d8d2d3 100644 --- a/core/Command.zig +++ b/core/Command.zig @@ -263,14 +263,16 @@ fn matches(q: []const u8, text: []const u8) bool { return Names.match(q, t, std.ascii.lowerString(&low, t), 0, null, null) != null; } -/// The tag's own words, in its order: its text after the prefix but `|`, -/// then for a terminal `Kill` (its job's), unless the tag has it. +/// The tag's words, in its order: its computed words, then its own text +/// but `|` (UX K'1), then for a terminal `Kill` (its job's), unless the +/// tag has it. const Words = struct { - words: std.mem.TokenIterator(u8, .any), + computed: std.mem.TokenIterator(u8, .any), + own: std.mem.TokenIterator(u8, .any), kill: bool, fn next(w: *Words) ?[]const u8 { - while (w.words.next()) |word| { + while (w.computed.next() orelse w.own.next()) |word| { if (std.mem.eql(u8, word, "|")) continue; if (std.mem.eql(u8, word, "Kill")) w.kill = false; return word; @@ -282,7 +284,7 @@ const Words = struct { }; fn tagWords(pane: *Pane) Words { - return .{ .words = std.mem.tokenizeAny(u8, tagline.curTail(pane), " \t\n"), .kill = pane.isTerminal() and pane.command == null }; + 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 }; } /// What row `at` of the rows stands for, as Tab writes it: an answer's @@ -691,6 +693,9 @@ test ": opens a field in the tag after its key cell: the tag's own words first, defer frame.deinit(); const a = frame.allocator(); const pane = try p.setTestFile("b\na\nc\n"); + // Typed into: its tag's words Save Undo Del (UX K'3). + typeKeys(p, "ix"); + p.update(.{ .key = .{ .cp = Key.escape } }); const rest = try std.testing.allocator.dupe(u8, try tagOf(p)); defer std.testing.allocator.free(rest); typeKeys(p, ":"); @@ -699,19 +704,19 @@ 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), ": 16 commands Tab complete · ⏎ run · C-r history · esc")); + try std.testing.expect(has(try tagOf(p), ": 14 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 ")); try std.testing.expect(has(try bandRow(p, a, 0), "in the tag")); - try std.testing.expect(has(try bandRow(p, a, 1), " Term ")); + try std.testing.expect(has(try bandRow(p, a, 1), " Undo ")); // The doc beside them is the current row's: Save's. try std.testing.expect(has(try bandRow(p, a, 0), "Save in the tag")); const band = (try Band.of(p, a, pane, p.view().active)).?; const first = band.steps[0].rows; - try std.testing.expect(first[4].under and !first[3].under); - try std.testing.expect(has(first[5].text, "write w")); - try std.testing.expect(has(first[7].text, "theme") and has(first[7].text, "<theme>")); + 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>")); // 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 ")); diff --git a/core/Core.zig b/core/Core.zig index f47cc5d8..a22822c2 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -1167,14 +1167,13 @@ fn acknowledgeShellInner(p: *Pardes, id: Pane.Id, executable: []const u8, prompt pane.greeted = false; pane.had_shell = true; pane.fs.unmarked = !prompt_marks; - // The tag's Term word names the shell the host ran, and a click - // on it (`Term+fish`) opens another of the same. + // The tag's text names the shell the host ran (tagline.defaultTail), + // and a click on it (`Term+fish`) opens another of the same. if (pane.command == null) { // A shell given as a path keeps it: its bare name would find // nothing, or another program, on the usual paths. const base = if (pane.shell) |given| (if (std.mem.indexOfScalar(u8, given, '/') != null) given else std.Io.Dir.path.basename(executable)) else std.Io.Dir.path.basename(executable); - const rest = tagline.terminal_pane_tail[" Term".len..]; - if (std.fmt.bufPrint(&pane.shell_tail, " Term+{s}{s}", .{ base, rest })) |tail| { + if (std.fmt.bufPrint(&pane.shell_tail, "Term+{s}", .{base})) |tail| { pane.shell_tail_len = @intCast(tail.len); } else |_| {} } @@ -2018,7 +2017,7 @@ pub fn sync(p: *Pardes) void { const prefix: ?[]const u8 = tagline.prefixIn(p, wa, pane) catch null; // The tag's cursor and selections are offsets in its text at rest: // a head shown over its own text moves none of them (UX D1). - const at_rest = if (pardes.Trail.outOfRest(p, pane)) tagline.restPrefix(p, wa, pane) catch null else prefix; + const at_rest = if (pardes.Trail.outOfRest(p, pane) or pardes.TagState.asks(p, pane)) tagline.restPrefix(p, wa, pane) catch null else prefix; const lead = if (at_rest) |made| made.len else pane.tag_lead; if (lead != pane.tag_lead) { const t = &pane.tag; @@ -2579,9 +2578,10 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" { while (p.nextEffect()) |_| {} // initial shell spawn/geometry p.acknowledgeShell(.at(0), "/bin/sh", false); - // The Term word names the shell the host ran, and opens another of it. + // The Term word names the shell the host ran, and opens another of it: + // the tag's text after its computed Del (UX K'3). const pane = p.panes[0].?; - try std.testing.expectEqualStrings(" Term+sh" ++ tagline.terminal_pane_tail[" Term".len..], tagline.curTail(pane)); + try std.testing.expectEqualStrings("Term+sh", tagline.curTail(pane)); const tag_x = p.view().rects[0].x + TAG_TEXT_INSET; const tag_y = p.view().rects[0].y; @@ -2608,10 +2608,11 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" { // Argument-taking builtins use the same gesture path: a tag sweep is the // complete command line, and Theme consumes its tail without a PTY write. if (pane.tag.own) |own| p.gpa.free(own); - pane.tag.own = try p.gpa.dupe(u8, " Theme dark"); - p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = tag_x + 1, .row = tag_y } }); - p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .drag, .col = tag_x + 10, .row = tag_y } }); - p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = tag_x + 10, .row = tag_y } }); + pane.tag.own = try p.gpa.dupe(u8, "Theme dark"); + const theme_x = tag_x + @as(u16, @intCast(std.mem.indexOf(u8, try tagline.tagText(p, p.scratch.allocator(), pane), "Theme dark").?)); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = theme_x, .row = tag_y } }); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .drag, .col = theme_x + 9, .row = tag_y } }); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = theme_x + 9, .row = tag_y } }); try std.testing.expectEqualStrings("dark", p.theme().name); while (p.nextEffect()) |effect| switch (effect) { .write => return error.ArgumentBuiltinFellThroughToPty, @@ -2627,9 +2628,10 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" { // A word absent from the builtin vocabulary takes the fallback, including // the terminating carriage return expected by the shell prompt. if (pane.tag.own) |own| p.gpa.free(own); - pane.tag.own = try p.gpa.dupe(u8, " DefinitelyNotABuiltin"); - p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = tag_x + 1, .row = tag_y } }); - p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = tag_x + 1, .row = tag_y } }); + pane.tag.own = try p.gpa.dupe(u8, "DefinitelyNotABuiltin"); + const word_x = tag_x + @as(u16, @intCast(std.mem.indexOf(u8, try tagline.tagText(p, p.scratch.allocator(), pane), "Definitely").?)) + 1; + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .press, .col = word_x, .row = tag_y } }); + p.update(.{ .mouse = .{ .button = config.exec_button, .kind = .release, .col = word_x, .row = tag_y } }); var sent: [256]u8 = undefined; var sent_len: usize = 0; while (p.nextEffect()) |effect| switch (effect) { @@ -2701,12 +2703,14 @@ test "TreeContext command and custom tag survive a workspace round trip" { defer p.deinit(); const pane = try p.setTestFile("pub fn main() void {}\n"); try std.testing.expect(!pardes.panes.File.supportsContext(pane)); - try std.testing.expectEqualStrings(tagline.file_pane_tail, tagline.curTail(pane)); + try std.testing.expectEqualStrings(tagline.file_pane_tail, tagline.kindTail(pane)); const path = try p.gpa.dupe(u8, "/test.zig"); p.gpa.free(pane.file.?.path); pane.file.?.path = path; if (!pardes.panes.File.supportsContext(pane)) return error.SkipZigTest; - try std.testing.expectEqualStrings(if (lsp.speaks("/test.zig")) tagline.lsp_context_pane_tail else tagline.context_pane_tail, tagline.curTail(pane)); + // TreeContext is a word of its kind's (`:`'s, UX K'4), not its tag's. + try std.testing.expectEqualStrings(if (lsp.speaks("/test.zig")) tagline.lsp_context_pane_tail else tagline.context_pane_tail, tagline.kindTail(pane)); + try std.testing.expect(std.mem.indexOf(u8, try tagline.tagText(p, p.scratch.allocator(), pane), "TreeContext") == null); try std.testing.expect(!pane.file.?.tree_context); try std.testing.expect(p.executeBuiltinLine(0, "TreeContext on")); try std.testing.expect(pane.file.?.tree_context); @@ -2767,7 +2771,7 @@ test "Filter is ordered after Del and toggles only its terminal or +Pager pane" const pager_id = try pardes.panes.Output.openPager(p, 0, "/tmp"); const pager_pane = p.panes[pager_id].?; try testing.expect(pager_pane.tty_filter); - try testing.expectEqualStrings(tagline.pager_pane_tail, tagline.curTail(pager_pane)); + try testing.expectEqualStrings(" Filter Del", tagline.computedWords(pager_pane)); try testing.expectEqual(@as(u16, 0), pardes.panes.File.gutterWidth(pager_pane)); try testing.expect(p.executeBuiltinLine(pager_id, "Filter")); try testing.expect(!pager_pane.tty_filter); @@ -2797,7 +2801,9 @@ test "compact tag commands stay beside their own prefix across layout changes" { defer gpa.free(above_tag); const below_tag = try tagline.tagText(p, p.scratch.allocator(), below); try std.testing.expect(below_tag.len > above_tag.len); - const tail = tagline.terminal_pane_tail; + // Its computed Del, the blank before its own text (UX K'1), and that + // text: Term, its shell not yet named. + const tail = " Del Term"; try std.testing.expectEqualStrings(tail, above_tag[above_tag.len - tail.len ..]); try std.testing.expectEqual(above.cwdSlice().len + tail.len, above_tag.len); @@ -2809,7 +2815,7 @@ test "compact tag commands stay beside their own prefix across layout changes" { try std.testing.expectEqualStrings(above_tag, try tagline.tagText(p, p.scratch.allocator(), above)); p.update(.{ .resize = .{ .cols = 100, .rows = 30 } }); while (p.nextEffect()) |_| {} - try std.testing.expectEqualStrings(tail, tagline.curTail(below)); + try std.testing.expectEqualStrings("Term", tagline.curTail(below)); try below.appendTag(" lots and lots of typing out here"); try std.testing.expectEqual(above_tag.len, (try tagline.tagText(p, p.scratch.allocator(), above)).len); @@ -3081,7 +3087,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe try std.testing.expect(p.executeBuiltinLine(1, "Repl PY")); var idbuf: [48]u8 = undefined; try std.testing.expectEqualStrings("python-a", exec.replId(&idbuf, p.panes[1].?)); - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagPrefix(p, p.panes[1].?), " python-a")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.pathPrefix(p, p.scratch.allocator(), p.panes[1].?), " python-a")); Sent.drain(p); // A click on the file's body, a single word: typed into the REPL. @@ -3284,7 +3290,7 @@ test "a Term started by a shell's path keeps the path in its Term+ word" { try std.testing.expect(p.executeBuiltinLine(0, "Term /bin/sh")); try std.testing.expect(p.view().active != 0); p.acknowledgeShell(.at(p.view().active), "/bin/sh", false); - try std.testing.expect(std.mem.startsWith(u8, tagline.curTail(p.panes[p.view().active].?), " Term+/bin/sh ")); + try std.testing.expectEqualStrings("Term+/bin/sh", tagline.curTail(p.panes[p.view().active].?)); } test "Tty, Term's old name in saved tags, runs as Term, bare and with its +shell" { @@ -3310,7 +3316,7 @@ test "Term+fish, one word a tag can hold, opens a terminal on that shell" { try std.testing.expect(p.view().active != 0); try std.testing.expectEqualStrings("sh", p.panes[p.view().active].?.shell.?); p.acknowledgeShell(.at(p.view().active), "/bin/sh", false); - try std.testing.expect(std.mem.startsWith(u8, tagline.curTail(p.panes[p.view().active].?), " Term+sh ")); + try std.testing.expectEqualStrings("Term+sh", tagline.curTail(p.panes[p.view().active].?)); p.view().active = 0; // A shell that is not there is said, not quietly replaced, and the // pane that asked gets no shell of its own. @@ -3350,7 +3356,7 @@ test "a command pane shows how its command ended, and the next command there run } var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagPrefix(p, pane), "(make -j8) running")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.pathPrefix(p, p.scratch.allocator(), pane), "(make -j8) running")); // Running, a second command goes to a pane of its own. const other = exec.execute(p, 1, "ls") orelse return error.NoCommandPane; try std.testing.expect(other != dst); @@ -3368,7 +3374,7 @@ test "a command pane shows how its command ended, and the next command there run try std.testing.expect(p.panes[dst] == pane and !pane.command_pty); try std.testing.expect(p.panes[dst] == pane); try std.testing.expect(pane.command_done); - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagPrefix(p, pane), "(make -j8) exit 2")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.pathPrefix(p, p.scratch.allocator(), pane), "(make -j8) exit 2")); // Kill leaves a finished one be. try std.testing.expect(p.executeBuiltinLine(0, "Kill make")); while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane.index() == dst) return error.SignalledAFinishedCommand; @@ -3390,7 +3396,7 @@ test "a command pane shows how its command ended, and the next command there run const ended = std.mem.indexOf(u8, body, "exit 2") orelse return error.ExitLost; const next = std.mem.indexOf(u8, body, "% make test") orelse return error.NoSeparator; try std.testing.expect(said < ended and ended < next); - try std.testing.expect(std.mem.endsWith(u8, try tagline.tagPrefix(p, pane), "(make test) running")); + try std.testing.expect(std.mem.endsWith(u8, try tagline.pathPrefix(p, p.scratch.allocator(), pane), "(make test) running")); // Kill stops a running one: its whole process group, SIGTERM. try std.testing.expect(p.executeBuiltinLine(0, "Kill make")); var signalled = false; diff --git a/core/Dir.zig b/core/Dir.zig index 869a7cd5..b9c8c917 100644 --- a/core/Dir.zig +++ b/core/Dir.zig @@ -360,7 +360,7 @@ test "a look at a directory opens a pane named for it with a /, its entries in c try testing.expectEqual(id, p.view().active); const pane = p.panes[id].?; try testing.expectEqualStrings(".dot sub/ top.txt\n", pane.file.?.content); - try testing.expectEqualStrings(@import("tagline.zig").dir_pane_tail, @import("tagline.zig").curTail(pane)); + try testing.expectEqualStrings(" Get Del", @import("tagline.zig").computedWords(pane)); try testing.expectEqualStrings(s.dir, Pardes.paneDir(pane)); // Edited, still never dirty, and no Save writes it. try testing.expect(p.executeBuiltinLine(id, "Edit ,d")); diff --git a/core/Effect.zig b/core/Effect.zig index 3bca04c9..e9f7a8f3 100644 --- a/core/Effect.zig +++ b/core/Effect.zig @@ -442,8 +442,9 @@ test "Save on an output buffer writes its rows out and leaves the buffer alone" const rows = try gpa.dupe(u8, out.file.?.content); defer gpa.free(rows); - // Save leads its tagline now, and the path is REQUIRED: a bare Save asks - try std.testing.expectEqualStrings(tagline.file_pane_tail, tagline.curTail(out)); + // Save is one of its words (`:`'s, UX K'4), and the path is REQUIRED: a + // bare Save asks + try std.testing.expectEqualStrings(tagline.file_pane_tail, tagline.kindTail(out)); try std.testing.expect(p.executeBuiltinLine(id, "Save")); try std.testing.expect(out.prompt == .save); try edit.insertKey(p.editor(), &out.input, .{ .cp = 'h', .text = "help.txt" }); @@ -626,25 +627,29 @@ test "a save whose pane is gone before the drain writes nothing" { try std.testing.expect(p.fallback.get("/tmp/pardes-gone/recycled.txt") == null); } -test "Save reaches every tagline with text behind it and no other" { +test "Save is a word of every pane with text behind it and no other" { const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); while (p.nextEffect()) |_| {} + // Its kind's words (what `:` lists, UX K'4); its tag's, while clean, + // Del alone (K'3). const out = try p.setTestFile("build.zig:1:1 pub fn main\n"); out.file.?.output = .{ .from = .search }; - try std.testing.expectEqualStrings(tagline.locations_pane_tail, tagline.curTail(out)); + try std.testing.expectEqualStrings(tagline.locations_pane_tail, tagline.kindTail(out)); + try std.testing.expectEqualStrings(" Del", tagline.computedWords(out)); - // A scratch is an output buffer that wears the FILE tails. + // A scratch is an output buffer that has the FILE words. out.file.?.output = .{ .from = .{ .cmd = std.meta.stringToEnum(pardes.Builtin, "New").? } }; - try std.testing.expectEqualStrings(" Save Term Collapse Follow Del", tagline.curTail(out)); + try std.testing.expectEqualStrings(" Save Term Collapse Follow Del", tagline.kindTail(out)); // An image's bytes on disk already are what they are: nothing of the // pane's own is unwritten, so the word is absent and inert. const img_id = p.freeSlot().?; const img = try pardes.Kind.open(p, img_id, pardes.Kind.test_kind.of(p), "/tmp/pardes-tag.ppm", ""); - try std.testing.expectEqualStrings(" Term Collapse Del", tagline.curTail(img)); + try std.testing.expectEqualStrings(" Del", tagline.kindTail(img)); + try std.testing.expectEqualStrings(" Del", tagline.computedWords(img)); try std.testing.expect(p.executeBuiltinLine(img_id, "Save")); try std.testing.expect(img.prompt != .save); var buf: [256]u8 = undefined; diff --git a/core/File.zig b/core/File.zig index 0f9178ac..217531fd 100644 --- a/core/File.zig +++ b/core/File.zig @@ -2191,12 +2191,17 @@ pub fn unchain(pane: *Pane) void { dropUnfollow(pane); } -/// The Unfollow word Follow gave a pane's tag (builtins.Follow), gone. +/// The Unfollow word Follow gave a pane's tag (builtins.Follow), gone, with +/// the blank before it (after it, first in the tag's own text). fn dropUnfollow(pane: *Pane) void { const own = pane.tag.own orelse return; - const at = std.mem.indexOf(u8, own, " Unfollow") orelse return; - const end = at + " Unfollow".len; - if (end < own.len and std.mem.indexOfScalar(u8, " \t\n", own[end]) == null) return; + const word = std.mem.indexOf(u8, own, "Unfollow") orelse return; + const word_end = word + "Unfollow".len; + const blank_after = word_end < own.len and std.mem.indexOfScalar(u8, " \t\n", own[word_end]) != null; + if (word_end < own.len and !blank_after) return; + if (word > 0 and own[word - 1] != ' ') return; + const at = if (word > 0) word - 1 else word; + const end = if (word == 0 and blank_after) word_end + 1 else word_end; const cut = std.mem.concat(pane.gpa, u8, &.{ own[0..at], own[end..] }) catch return; pane.gpa.free(own); pane.tag.own = cut; diff --git a/core/Kind.zig b/core/Kind.zig index 4e1aa469..430f8ba8 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -305,10 +305,10 @@ pub fn reopen(p: *Pardes, id: usize, s: *Slot, bytes: ?[]const u8) bool { if (s.plain) |b| if (b.len > 0) s.gpa.free(b); s.plain = &.{}; } + // Its tag's computed words (UX K'3): its words, then Del. var w: std.Io.Writer = .fixed(&s.tail.bytes); - w.writeAll(" Term") catch {}; for (p.kinds.words[0..p.kinds.nwords]) |*kw| if (kw.kind == k and kw.opens == 0) w.print(" {s}", .{kw.name.slice()}) catch {}; - w.writeAll(" Collapse Del") catch {}; + w.writeAll(" Del") catch {}; s.tail.len = @intCast(w.buffered().len); } s.opened = if (bytes) |b| std.hash.Wyhash.hash(0, b) else 0; diff --git a/core/Messages.zig b/core/Messages.zig index e05961b5..9361a2d7 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -1554,7 +1554,8 @@ test "a question never adds a row to its tag: at every width the asking tag take } test "a file changed on disk under unsaved text asks in its tag and never takes the keyboard: SPC e's keyboard answers, d shows the disk's lines as ghosts, Esc leaves it waiting, B2 on Reload reads it again" { - const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 }); + // Wide: the tag at rest one row (UX K'3), the question whole in it. + const p = try Pardes.init(std.testing.allocator, .{ .cols = 200, .rows = 20 }); defer p.deinit(); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); diff --git a/core/Pipe.zig b/core/Pipe.zig index 1ef2e4ea..e94d2099 100644 --- a/core/Pipe.zig +++ b/core/Pipe.zig @@ -480,8 +480,9 @@ test "| in a tag pipes the tag's own text, and undo there brings it back" { defer p.deinit(); while (p.nextEffect()) |_| {} const pane = try p.setTestFile("body\n"); - for ("::") |c| p.update(.{ .key = .{ .cp = c } }); // the tag (`:` on the empty `:` field), on Save - p.update(.{ .key = .{ .cp = 'e' } }); // Save selected + pane.tag.own = try gpa.dupe(u8, "Look here"); // the user's text (UX K'1) + for ("::") |c| p.update(.{ .key = .{ .cp = c } }); // the tag (`:` on the empty `:` field), on its own text + p.update(.{ .key = .{ .cp = 'e' } }); // Look selected p.update(.{ .key = .{ .cp = '|' } }); try std.testing.expect(pane.focus == .tag and pane.prompt == .pipe and pane.prompt_for == .tag); p.update(.{ .key = .{ .cp = 't', .text = "tr a-z A-Z" } }); @@ -490,13 +491,13 @@ test "| in a tag pipes the tag's own text, and undo there brings it back" { const id = nextPipeEffect(p) orelse return error.MissingPipeEffect; const request = p.pipe.pipeRequest(id) orelse return error.MissingPipeRequest; try std.testing.expectEqual(@as(usize, 1), request.inputs.len); - try std.testing.expectEqualSlices(u8, "Save", request.inputs[0]); - const outputs: []const []const u8 = &.{"SAVE"}; + try std.testing.expectEqualSlices(u8, "Look", request.inputs[0]); + const outputs: []const []const u8 = &.{"LOOK"}; p.update(.{ .pipe_resp = .{ .id = id, .success = true, .outputs = outputs } }); - try std.testing.expect(std.mem.startsWith(u8, pardes.tagline.curTail(pane), " SAVE ")); + try std.testing.expectEqualStrings("LOOK here", pardes.tagline.curTail(pane)); try std.testing.expectEqualStrings("body\n", pane.file.?.content); p.update(.{ .key = .{ .cp = 'u' } }); - try std.testing.expect(std.mem.startsWith(u8, pardes.tagline.curTail(pane), " Save ")); + try std.testing.expectEqualStrings("Look here", pardes.tagline.curTail(pane)); } test "$ keeps the selections the command exits 0 on, and a real shell gives that verdict" { diff --git a/core/Stream.zig b/core/Stream.zig index e9e7793b..c5069ed5 100644 --- a/core/Stream.zig +++ b/core/Stream.zig @@ -1452,7 +1452,7 @@ test "Stream: a Grep stops at its 2000 lines and waits; More in the query pane's p.update(.tick); try testing.expectEqual(@as(usize, soft_cap), qp.query.?.found.items.len); try testing.expect(qp.query.?.capped); - try testing.expectEqualStrings(" More Del", @import("tagline.zig").curTail(qp)); + try testing.expectEqualStrings(" More Del", @import("tagline.zig").computedWords(qp)); pardes.exec.runBuiltin(p, .More, qid, "", null); try shell.finish(p, 20_000); p.update(.tick); diff --git a/core/TagState.zig b/core/TagState.zig index 3bf67e5e..c754e468 100644 --- a/core/TagState.zig +++ b/core/TagState.zig @@ -339,9 +339,16 @@ fn reaches(p: *const Pardes, root: Root, path: []const u8, leaf: bool) bool { /// the keyboard). The pane's state, not the view's keyboard: every view /// shows it; not while the tag has the keyboard, whose own text is edited /// then. +/// A question waits on pane `pane` at rest, its keyboard not in its tag: +/// its tag says it after the path, in place of the tag's computed words +/// and own text (UX D13, K'3). +pub fn asks(p: *const Pardes, pane: *const Pane) bool { + return pane.focus != .tag and pane.prompt != .name and p.messages.waiting(pane) != null; +} + fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { - if (pane.focus == .tag or pane.prompt == .name) return null; - const i = p.messages.waiting(pane) orelse return null; + if (!asks(p, pane)) return null; + const i = p.messages.waiting(pane).?; const said = &p.messages.live[i]; var b: Builder = .{ .arena = arena }; // In the rows the tag takes at rest (UX D13: a question never adds a @@ -350,7 +357,7 @@ fn asking(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head { // always show. const tab = p.settings.tab; const id = panes.paneIdOf(p, pane) orelse return null; - const room = @as(usize, @import("layout.zig").wantedTagRows(p, id)) * tagline.tagWidth(p, id) -| panes.File.displayWidth(tab, try tagline.restPrefix(p, arena, pane)); + const room = @as(usize, @import("layout.zig").wantedTagRows(p, id)) * tagline.tagWidth(p, id) -| panes.File.displayWidth(tab, try tagline.prefixIn(p, arena, pane)); const hint = if (p.view().answering == pane.serial) "· Esc later" else "· SPC e to answer"; var answers: usize = 2; // ` ▸`, then each ` k word ` for (said.asks.answers()) |a| answers += 3 + panes.File.displayWidth(tab, a.word) + 1; @@ -1321,6 +1328,8 @@ test "a tag out of rest keeps exactly its rows at rest: a level shorter than its defer p.deinit(); _ = try p.setTestFile("one\n"); const pane = p.panes[p.view().active].?; + // Its own text past a row: the tag takes two (UX K'1). + pane.tag.own = try p.gpa.dupe(u8, "words of the user's own that run on past a row"); p.sync(); const rows, const tag_rows = .{ pane.rows, pane.tag_rows }; try std.testing.expect(tag_rows > 1); diff --git a/core/Trail.zig b/core/Trail.zig index 2a37d68a..f2b4fef4 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -598,7 +598,7 @@ test "a file's pane is reading, its tag in the reading tint with Keep after its // Under Jumps new-pane nothing reads: the tag as it always was. p.settings.jumps = .@"new-pane"; try std.testing.expect(!reading(p, pane)); - try std.testing.expectEqualStrings("/test.txt Save Term Collapse Follow Del", try tagOf(p, pane)); + try std.testing.expectEqualStrings("/test.txt Del ", try tagOf(p, pane)); try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().tag_active_bg }, try tagGroundOf(p, &arena, 0)); p.settings.jumps = .walk; // Typed into: held from now on, though Undo takes the text back. @@ -650,7 +650,7 @@ const Fixture = struct { for ([_][]const u8{ "search.zig", "rank.zig", "place.zig" }) |name| try f.tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = w.buffered() }); f.dir = f.dir_buf[0..try f.tmp.dir.realPath(std.testing.io, &f.dir_buf)]; - f.p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = rows }); + f.p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = rows }); errdefer f.p.deinit(); _ = try f.p.setTestFile("scratch\n"); f.p.settings.jumps = .@"new-pane"; @@ -753,7 +753,7 @@ test "a Look from inside the reader at a file its held pane shows focuses the he test "the reader of a held pane too short to halve goes to the bottom of the next column, of the previous one from the last" { var f: Fixture = .{ .p = undefined, .tmp = undefined }; - try f.init(24); + try f.init(20); defer f.deinit(); const col = layout.findPane(f.p, f.held).?.col; try std.testing.expect(f.p.view().rects[f.held].h / 2 < f.p.panes[f.held].?.tag_rows + layout.reader_keeps); @@ -830,7 +830,7 @@ test "the session of pick-ui §6.7: four jumps across three files, back by a cli // makes a new reader. pardes.exec.runBuiltin(p, .Keep, r, "Keep", null); p.sync(); - try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, p.panes[r].?), try std.fmt.bufPrint(&buf, "{s}/rank.zig Save", .{f.dir}))); + try std.testing.expect(std.mem.startsWith(u8, try tagOf(p, p.panes[r].?), try std.fmt.bufPrint(&buf, "{s}/rank.zig Del ", .{f.dir}))); f.look(f.held, "place.zig", 20); const fresh = p.view().active; try std.testing.expect(fresh != r and fresh != f.held and p.panes[r] != null); diff --git a/core/builtins.zig b/core/builtins.zig index 7aaeee40..e9df737f 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -1993,7 +1993,8 @@ pub const Follow = struct { made.file.?.follow = true; c.pane.follow_scroll = f.scroll; made.follow_scroll = made.file.?.scroll; - made.appendTag(" Unfollow") catch |err| c.p.reportError(.at(c.id), "Follow", err); + // The new page's own text (UX K'1): a word after its computed ones. + made.appendTag(if (tagline.curTail(made).len == 0) "Unfollow" else " Unfollow") catch |err| c.p.reportError(.at(c.id), "Follow", err); } }; diff --git a/core/dump.zig b/core/dump.zig index 2dde9c8c..2806e445 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -639,6 +639,7 @@ fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previ var on_disk: OnDisk = @splat(false); const p = try loadKnowing(gpa, opts, bytes, ¬es, &on_disk); errdefer p.deinit(); + dropOldTags(p); // The 9P state its requests made was its connections', which do not // come with it (a client's join loads alone, and keeps it). p.fs.forget(gpa); @@ -661,6 +662,20 @@ fn loadAndRevive(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, previ return p; } +/// A build before UX K' kept a tag's command words as its own text: one a +/// dump restores equal to what its kind's tag said then (tagline.kindTail) +/// is dropped, its words computed now (K'1); any other is the user's text, +/// kept as it is. Here, where a Restore, a start from a dump and an +/// Upgrade load (a replica's join loads its authority's, dropped there). +fn dropOldTags(p: *Pardes) void { + for (p.panes) |slot| if (slot) |pane| if (pane.tag.own) |own| { + if (!std.mem.eql(u8, own, pardes.tagline.kindTail(pane))) continue; + p.gpa.free(own); + pane.tag.own = null; + pane.tag.cur_pinned = false; + }; +} + /// A loaded core given to this host (with `revivePane` for each of its /// panes): the store and Recent read (a Restore's carried from the session /// it replaces, with its state file) and its ThemeFile asked for again. An diff --git a/core/edit.zig b/core/edit.zig index e68f8d38..fa442fca 100644 --- a/core/edit.zig +++ b/core/edit.zig @@ -682,9 +682,10 @@ pub fn setEditTextEnd(e: Editor, t: *Text, new: []u8, known_end: ?modal.Cursor) fn setEditTextSpan(e: Editor, t: *Text, new: []u8, known_end: ?modal.Cursor, span: ?panes.File.Span) Error!void { if (t.what == .tag) { // A tag is edited as it is shown, but only what follows its - // prefix is its own: an edit that changed the prefix is refused. - // The shown text stays alive until the next such edit, since every - // caller reads the new text back, as a body's is kept. + // prefix (its path and computed words, UX K'1) is its own: an edit + // that changed the prefix is refused. The shown text stays alive + // until the next such edit, since every caller reads the new text + // back, as a body's is kept. defer retireEditText(e, new); const pane = t.pane() orelse return; // Out of rest the tag shows its head, which is no one's to edit. @@ -692,7 +693,7 @@ fn setEditTextSpan(e: Editor, t: *Text, new: []u8, known_end: ?modal.Cursor, spa t.refused = true; return; } - const prefix = try tagline.pathPrefix(e.p, e.scratch, pane); + const prefix = try tagline.restPrefix(e.p, e.scratch, pane); if (!std.mem.startsWith(u8, new, prefix)) { t.refused = true; return; diff --git a/core/jj.zig b/core/jj.zig index 63488b8c..08c31e5c 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -2567,7 +2567,7 @@ test "At shows a file at a revision beside it, read-only, coloured as its file; try testing.expectEqualStrings(Repo.two, pane.file.?.content); const name = try std.fmt.allocPrint(gpa, "{s}@@-", .{repo.file}); defer gpa.free(name); - try testing.expectEqualStrings(name, try pardes.tagline.tagPrefix(p, pane)); + try testing.expectEqualStrings(name, try pardes.tagline.pathPrefix(p, p.scratch.allocator(), pane)); try testing.expectEqualStrings(repo.file, File.langPath(&pane.file.?)); try testing.expect(pane.colorAlgo() == .source); // Read-only: a key's edit and a whole-text edit (dd) change nothing, and a bare Save says so. diff --git a/core/layout.zig b/core/layout.zig index 3f6bea51..be2d213c 100644 --- a/core/layout.zig +++ b/core/layout.zig @@ -592,12 +592,18 @@ pub const min_body_rows = 2; /// wants a row more. pub fn wantedTagRows(p: *Pardes, id: usize) u16 { const pane = p.panes[id] orelse return BOX_H; + return tagRows(p, id, tagline.computedWords(pane)); +} + +/// The rows pane `id`'s tag at rest takes with computed words `words`. +fn tagRows(p: *Pardes, id: usize, words: []const u8) u16 { + const pane = p.panes[id] orelse return BOX_H; if (pane.collapsed or !pane.tag_expanded) return BOX_H; if (p.view().rects[id].w == 0) return pane.tag_rows; // never laid out var wrap_room: [32 * 1024]u8 = undefined; var wrap_fba = std.heap.FixedBufferAllocator.init(&wrap_room); const wa = wrap_fba.allocator(); - const prefix = tagline.restPrefix(p, wa, pane) catch return pane.tag_rows; + const prefix = tagline.prefixWith(p, wa, pane, words) catch return pane.tag_rows; const whole = std.mem.concat(wa, u8, &.{ prefix, tagline.curTail(pane) }) catch return pane.tag_rows; const shown = tagline.wrapTag(p.settings.tab, wa, whole, tagline.tagWidth(p, id)) catch return pane.tag_rows; return @intCast(@max(BOX_H, @min(shown.rows(), MAX_TAG_ROWS))); @@ -622,7 +628,11 @@ pub fn headRows(p: *Pardes, id: usize) u16 { /// The rows a placement, and a `size`, leave a pane: its tag at its width /// and `min_body_rows`. The one minimum both ask. pub fn minRows(p: *Pardes, id: usize) u16 { - return wantedTagRows(p, id) + min_body_rows; + const pane = p.panes[id] orelse return BOX_H + min_body_rows; + // Its tag with the widest computed words it can come to show (UX + // K'3): an edit that brings Save and Undo never takes a row its + // column did not give. + return tagRows(p, id, tagline.widestWords(p, pane)) + min_body_rows; } /// Whether every column has the rows for each of its unfolded panes' diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig index 0f4f39dc..c60eb72b 100644 --- a/core/lsp/Ask.zig +++ b/core/lsp/Ask.zig @@ -558,17 +558,21 @@ test "Lspwhy after a Hover asks to explain that hover, in its file at its place, try std.testing.expect(seen); } -test "Def and Refs are a speaking file's tag words; gd, gr and a 2-1 chord all run them" { +test "Def and Refs are a speaking file's words, out of its tag (UX K'4); gd, gr and a 2-1 chord on them typed in its tag all run them" { if (!lsp.supports.contains(.definition)) return error.SkipZigTest; const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 24, .tty_only = true }); defer p.deinit(); const pane = try p.setTestFile("const alpha = 1;\nconst beta = alpha;\n"); // A .txt has no server: no Def, no Refs. - try std.testing.expect(std.mem.indexOf(u8, tagline.curTail(pane), "Def") == null); + try std.testing.expect(std.mem.indexOf(u8, tagline.kindTail(pane), "Def") == null); const f = &pane.file.?; p.gpa.free(f.path); f.path = try p.gpa.dupe(u8, "/tmp/x.zig"); - try std.testing.expect(std.mem.endsWith(u8, tagline.curTail(pane), " Def Refs Del")); + try std.testing.expect(std.mem.endsWith(u8, tagline.kindTail(pane), " Def Refs Del")); + // Its tag's computed words have neither: typed into its own text, they + // run as any word there does. + try std.testing.expect(std.mem.indexOf(u8, tagline.computedWords(pane), "Def") == null); + pane.tag.own = try p.gpa.dupe(u8, "Def Refs"); p.sync(); while (p.nextEffect()) |_| {} const Asked = struct { diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig index 093a9223..3627fdfb 100644 --- a/core/ninep/pane.zig +++ b/core/ninep/pane.zig @@ -777,7 +777,7 @@ pub fn applyTagTruncation(p: *Pardes, pane: *Pane) void { pane.tag.own = empty; // what is left is the prefix; the cursor goes after it pane.tag.cur_row = 0; - pane.tag.cur_col = if (tagline.pathPrefix(p, p.scratch.allocator(), pane)) |prefix| @intCast(prefix.len) else |_| 0; + pane.tag.cur_col = if (tagline.restPrefix(p, p.scratch.allocator(), pane)) |prefix| @intCast(prefix.len) else |_| 0; pane.tag.vsel.active = false; pane.tag.nsel = 0; pf.tag_rewrite = true; diff --git a/core/tagline.zig b/core/tagline.zig index 0ec26d2f..3a306f04 100644 --- a/core/tagline.zig +++ b/core/tagline.zig @@ -17,6 +17,8 @@ const Text = panes.Text; const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; const Pardes = pardes.Pardes; +/// The words a pane of each kind had in its tag before UX K' (its own +/// text until edited then): what `kindTail` says. pub const pane_tail = " " ++ config.pane_builtins_str; pub const file_pane_tail = " " ++ config.file_pane_builtins_str; fn withFileCommands(comptime tail: []const u8, comptime words: []const u8) []const u8 { @@ -41,6 +43,71 @@ pub const query_live_tail = " Del"; pub const query_frozen_tail = " Save Undock Del"; /// ...and while its Grep waits at 2000 lines for More (Stream.zig). pub const query_capped_tail = " More Del"; + +/// A file's computed words (UX K'3) by which of `Diff`, `Filter`, `Save`, +/// `Undo` and `Redo` act now (bit 0 to 4), each after a blank, `Del` last. +const file_words = words: { + const names = [_][]const u8{ "Diff", "Filter", "Save", "Undo", "Redo" }; + var table: [1 << names.len][]const u8 = undefined; + for (&table, 0..) |*words, bits| { + words.* = ""; + for (names, 0..) |name, i| if (bits >> i & 1 == 1) { + words.* = words.* ++ " " ++ name; + }; + words.* = words.* ++ " Del"; + } + break :words table; +}; + +/// A pane's computed words at rest (UX K'3): the words that act now, each +/// after a blank, read-only and made again from its state, as its path is. +/// The tag's own text (the user's) follows them. +pub fn computedWords(pane: *const Pane) []const u8 { + // A kind's: its addon's words, then Del (Kind.reopen). + if (pane.addon) |k| if (k.tail.len > 0) return k.tail.slice(); + if (pane.query) |q| return if (q.frozen) query_frozen_tail else if (q.capped) query_capped_tail else query_live_tail; + if (pane.file) |*f| { + if (f.output) |out| if (out.from == .preview) return query_live_tail; + if (f.listing != null) return " Get Del"; + const j = &f.history.journal; + var bits = fileBits(pane, f); + if (!dirty(pane)) bits &= ~@as(usize, 4); + // A step back with something in it: insert mode's mark is a step + // of none until a key types (Text.Journal.mark keeps one such, on + // top), and Undo would act on nothing. + if (j.done == 0 or (j.done == 1 and j.steps.items[0].n == 0)) bits &= ~@as(usize, 8); + if (j.done == j.steps.items.len) bits &= ~@as(usize, 16); + return file_words[bits]; + } + if (pane.command != null) return if (pane.command_done) " Del" else " Kill Del"; + return " Del"; +} + +/// The computed words pane `pane` can come to show (K'3: Save, Undo and +/// Redo come and go with its edits, a query's as it freezes): what a +/// placement leaves its tag the rows for (layout.minRows), so an edit +/// never takes a row its column did not give. A reading pane's are its +/// own (its first edit holds it): its walk folds to the rows it has with +/// them (`folded`). +pub fn widestWords(p: *const Pardes, pane: *const Pane) []const u8 { + if (pardes.Trail.reading(p, pane)) return computedWords(pane); + if (pane.query != null) return query_frozen_tail; + if (pane.file) |*f| if (f.listing == null and (if (f.output) |out| out.from != .preview else true)) + return file_words[fileBits(pane, f)]; + return computedWords(pane); +} + +/// A file's computed words that its kind can show (file_words' bits): +/// Diff for a diff (a .patch, a +Pager holding one, the Diff view), +/// Filter for a pager, Save where it saves (never a +New's, K'3: SPC f s +/// asks it a path), Undo and Redo. +fn fileBits(pane: *const Pane, f: *const panes.File.State) usize { + const diff = if (f.pager) f.pager_diff else pane.colorAlgo() == .diff or + (if (f.output) |out| std.meta.eql(out.from, panes.Output.Origin{ .cmd = .Diff }) else false); + const scratch = if (f.output) |out| std.meta.eql(out.from, panes.Output.Origin{ .cmd = .New }) else false; + const saves = panes.Output.fileTraits(f.output).saves and !scratch; + return @as(usize, @intFromBool(diff)) | @as(usize, @intFromBool(f.pager)) << 1 | @as(usize, @intFromBool(saves)) << 2 | 8 | 16; +} /// A file with changes it has not saved. pub fn dirty(pane: *const panes.Pane) bool { const f = pane.file orelse return false; @@ -120,9 +187,9 @@ fn shownDir(arena: std.mem.Allocator, pane: *Pane) ![]const u8 { return pardes.ctlfs.events.shown(dir, out); } -/// The computed start of a pane's tag -- its path and dirty marker, a -/// PDF's page, a terminal's directory -- without the space that parts it -/// from the tag's own text. It is never stored, and never edited. +/// The computed start of a pane's tag -- its path, a PDF's page, a +/// terminal's directory -- without its computed words (restPrefix). It is +/// never stored, and never edited. pub fn pathPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]const u8 { // Out of rest (UX D1) the owner's word and the newest step's, each with // its ` › `, before the head: the path, the forward steps and Keep @@ -240,7 +307,9 @@ pub fn folded(p: *const Pardes, pane: *const Pane) Fold { const name = if (pane.prompt == .name) pane.input.own orelse f.path else f.path; const keep = pardes.Trail.reading(p, pane); const tail = curTail(pane); - const bare = panes.File.displayWidth(tab, name) + @as(usize, if (keep) " Keep".len else 0) + panes.File.displayWidth(tab, tail); + // Its computed words and the blank before its own text (restPrefix). + const words = panes.File.displayWidth(tab, computedWords(pane)) + 1; + const bare = panes.File.displayWidth(tab, name) + @as(usize, if (keep) " Keep".len else 0) + words + panes.File.displayWidth(tab, tail); var whole: usize = pardes.Trail.shown_steps; while (whole > 1 and rowsOf(bare + walkCells(t, whole, tab), width) > rowsOf(bare, width)) whole -= 1; const r = p.view().rects[id]; @@ -249,34 +318,38 @@ pub fn folded(p: *const Pardes, pane: *const Pane) Fold { // one the layout has given its width and not yet its height (the band // host's floor, layout.floorRows, wraps its tag at rest then). if (!keep or !walked or pane.prompt == .name or pane.collapsed or !pane.tag_expanded or r.w == 0 or r.h == 0) return .{ .whole = whole }; - // Its first line: the prefix, the space restPrefix gives a tail - // without one, the tail's first line; and the rows its others take. + // Its first line: the prefix, its computed words and their blank, the + // own text's first line; and the rows its others take. const first = std.mem.indexOfScalar(u8, tail, '\n') orelse tail.len; var below: usize = 0; if (first < tail.len) { var lines = std.mem.splitScalar(u8, tail[first + 1 ..], '\n'); while (lines.next()) |line| below += rowsOf(panes.File.displayWidth(tab, line), width); } - const gap: usize = @intFromBool(tail.len > 0 and std.mem.indexOfScalar(u8, " \t\n", tail[0]) == null); - const rest = " Keep".len + gap + panes.File.displayWidth(tab, tail[0..first]); + const rest = " Keep".len + words + panes.File.displayWidth(tab, tail[0..first]); const path = panes.File.displayWidth(tab, name); const rows = r.h -| layout.min_body_rows; if (@min(rowsOf(walkCells(t, whole, tab) + path + rest, width) + below, pardes.MAX_TAG_ROWS) <= rows) return .{ .whole = whole }; // The newest step alone, then as much of the path's end as fits, after - // a `…` cell. + // a `…` cell; where its basename does not fit beside the newest step + // (a column too narrow for its tag's words), that step folds into the + // `+N` too. const room = (rows -| below) * width; - const used = walkCells(t, 1, tab) + rest; - if (used + path <= room) return .{ .whole = 1, .squeezed = true }; - const drop = used + path + 1 - room; const base = if (std.mem.lastIndexOfScalar(u8, name, '/')) |slash| slash + 1 else 0; - var cut: usize = 0; - var cells: usize = 0; - while (cut < base and cells < drop) { - const next = modal.nextGrapheme(name, cut); - cells += panes.File.displayWidth(tab, name[cut..next]); - cut = next; + var shown: usize = 1; + while (true) : (shown -= 1) { + const used = walkCells(t, shown, tab) + rest; + if (used + path <= room) return .{ .whole = shown, .squeezed = true }; + const drop = used + path + 1 - room; + var cut: usize = 0; + var cells: usize = 0; + while (cut < base and cells < drop) { + const next = modal.nextGrapheme(name, cut); + cells += panes.File.displayWidth(tab, name[cut..next]); + cut = next; + } + if (shown == 0 or cells >= drop) return .{ .whole = shown, .cut = @min(cut, base), .squeezed = true }; } - return .{ .whole = 1, .cut = @min(cut, base), .squeezed = true }; } /// The cells a walk's words take at rest with its newest `whole` back @@ -334,38 +407,52 @@ pub fn tagPrefix(p: *Pardes, pane: *Pane) ![]u8 { /// The prefix as the tag shows it, built in `arena`. pub fn prefixIn(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 { - // Out of rest the head follows: its words end in their own space. - if (pardes.Trail.outOfRest(p, pane)) return arena.dupe(u8, try pathPrefix(p, arena, pane)); + // Out of rest the head follows: its words end in their own space; a + // question at rest follows the path, in place of the computed words. + if (pardes.Trail.outOfRest(p, pane) or TagState.asks(p, pane)) return arena.dupe(u8, try pathPrefix(p, arena, pane)); return restPrefix(p, arena, pane); } -/// The prefix as the tag has it at rest, whatever its state: what its own -/// text follows, so what its cursor and selections are offsets after -/// (Core.sync's `tag_lead`), and the rows it takes at rest -/// (layout.wantedTagRows). +/// The prefix as the tag has it at rest, whatever its state: its path, +/// its computed words (UX K'1) and a blank, read-only, which its own text +/// follows: what its cursor and selections are offsets after (Core.sync's +/// `tag_lead`), what an edit must leave as it is (edit.zig), and the rows +/// it takes at rest (layout.wantedTagRows). The blank is the prefix's: +/// with the own text's first word against `Del`, Look and Exec would see +/// one word. pub fn restPrefix(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 { - const prefix = try restPath(p, arena, pane); - // The space between the prefix and the tag's own text is the text's - // (every default starts with one), but the prefix is computed, so it - // cannot trust the text to keep it: with it deleted, Look and Exec - // would see the path and the first word as one. The prefix brings its - // own then. - const tail = curTail(pane); - if (tail.len > 0 and std.mem.indexOfScalar(u8, " \t\n", tail[0]) == null) - return std.fmt.allocPrint(arena, "{s} ", .{prefix}); - return arena.dupe(u8, prefix); + return prefixWith(p, arena, pane, computedWords(pane)); } -/// The tag's own text: what the user made of it, or until then the -/// default a pane of its kind starts with. +/// The prefix at rest with computed words `words` (restPrefix's own, or +/// the widest its pane can come to show, widestWords). +pub fn prefixWith(p: *const Pardes, arena: std.mem.Allocator, pane: *Pane, words: []const u8) ![]u8 { + return std.mem.concat(arena, u8, &.{ try restPath(p, arena, pane), words, " " }); +} + +/// The tag's own text: the user's (UX K'1), everything typed into the tag +/// after its computed words, kept as typed; until then a terminal's word +/// for its shell, none for the rest. pub fn curTail(pane: *const Pane) []const u8 { return pane.tag.own orelse defaultTail(pane); } +/// A tag's own text until it is edited: a terminal's word for its shell, +/// `Term` until the shell says its name, then `Term+<shell>` +/// (Core.acknowledgeShell; a click opens another of it), as before UX +/// K'; none for the rest. pub fn defaultTail(pane: *const Pane) []const u8 { - // A kind's: Term, its words for its panes, Collapse Del (Kind.open). - if (pane.addon) |k| if (k.tail.len > 0) return k.tail.slice(); - if (pane.query) |q| return if (q.frozen) query_frozen_tail else if (q.capped) query_capped_tail else query_live_tail; + if (!pane.isTerminal() or pane.command != null) return ""; + return if (pane.shell_tail_len > 0) pane.shell_tail[0..pane.shell_tail_len] else "Term"; +} + +/// The words a pane of its kind had in its tag before UX K', its own text +/// until edited then: an own text a dump restores equal to it is dropped +/// (dump.zig dropOldTags). +pub fn kindTail(pane: *const Pane) []const u8 { + // A kind's: its words (Kind.reopen). + if (pane.addon) |k| return k.tail.slice(); + if (pane.query != null) return computedWords(pane); if (pane.file) |file| if (file.output) |out| if (out.from == .preview) return query_live_tail; if (pane.file) |file| if (file.listing != null) return dir_pane_tail; if (pane.file) |file| if (file.pager) return if (file.pager_diff) pager_diff_pane_tail else pager_pane_tail; @@ -378,7 +465,7 @@ pub fn defaultTail(pane: *const Pane) []const u8 { if (panes.File.supportsContext(pane)) return if (speaks) lsp_context_pane_tail else context_pane_tail; if (pane.file != null) return if (speaks) lsp_pane_tail else file_pane_tail; if (pane.command != null) return command_pane_tail; - if (pane.isTerminal()) return if (pane.shell_tail_len > 0) pane.shell_tail[0..pane.shell_tail_len] else terminal_pane_tail; + if (pane.isTerminal()) return terminal_pane_tail; return pane_tail; } @@ -399,18 +486,14 @@ pub fn tagText(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) ![]u8 { /// Give the keyboard to the tag in normal mode (`:`), its cursor where /// the tag last had it. The first time there is nothing to remember, and -/// it starts on Save, so that `:` and the execute key write the file. +/// it starts on the user's text (UX K'1), after the computed words: what +/// is typed goes there. pub fn enterTag(p: *Pardes, pane: *Pane) void { const t = &pane.tag; const whole = tagText(p, p.scratch.allocator(), pane) catch |err| return p.reportError(.at(p.view().active), "tag", err); if (!t.cur_pinned) { - // Save is looked for in the tag's own text, after the prefix. - const lead = whole.len - curTail(pane).len; - const tail = whole[lead..]; - var words = std.mem.tokenizeAny(u8, tail, " \t\n"); - const at = lead + while (words.next()) |word| { - if (std.mem.eql(u8, word, "Save")) break @intFromPtr(word.ptr) - @intFromPtr(tail.ptr); - } else tail.len - std.mem.trimStart(u8, tail, " ").len; + const tail = curTail(pane); + const at = whole.len - std.mem.trimStart(u8, tail, " ").len; const cursor = modal.positionAt(whole, @min(at, whole.len)); t.cur_row = @intCast(cursor.row); t.cur_col = @intCast(cursor.col); @@ -741,3 +824,119 @@ test "a pane tag wraps a long line onto rows, and offsets map both ways" { try std.testing.expectEqual(@as(usize, 10), shown.toReal(11)); // the 'e' of Del try std.testing.expectEqual(@as(usize, 11), shown.fromReal(10)); } + +/// What pane `pane`'s tag says after its path: its computed words, the +/// blank before its own text, and that text. +fn afterPath(p: *Pardes, pane: *Pane) ![]const u8 { + const a = p.scratch.allocator(); + const whole = try tagText(p, a, pane); + return whole[(try pathPrefix(p, a, pane)).len..]; +} + +fn typeKeys(p: *Pardes, keys: []const u8) void { + for (keys) |ch| p.update(.{ .key = .{ .cp = ch, .text = &[_]u8{ch} } }); +} + +test "a pane tag's computed words are the words that act now, its own text after them (UX K'1, K'3)" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30, .tty_only = true }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + const f = &pane.file.?; + p.sync(); + // A file reading (its jumps walk): Keep (its walk's, after its path), + // Del. + try std.testing.expectEqualStrings("/test.txt Keep Del ", try tagText(p, p.scratch.allocator(), pane)); + // Held and clean, no undo step: Del alone. + pane.trail.held = true; + try std.testing.expectEqualStrings(" Del ", try afterPath(p, pane)); + // Typed into twice: unsaved, an undo step: Save Undo Del. + typeKeys(p, "ix"); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + typeKeys(p, "iy"); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expectEqualStrings(" Save Undo Del ", try afterPath(p, pane)); + // Undone once: a step each way, Redo after Undo. + typeKeys(p, "u"); + try std.testing.expectEqualStrings(" Save Undo Redo Del ", try afterPath(p, pane)); + // Saved: clean, Save gone. + f.saved_revision = f.revision; + try std.testing.expectEqualStrings(" Undo Redo Del ", try afterPath(p, pane)); + // A diff, a pager, a pager holding a diff: Diff, Filter first. + const path = f.path; + f.path = @constCast("/x.patch"); + try std.testing.expectEqualStrings(" Diff Undo Redo Del", computedWords(pane)); + f.path = path; + f.pager = true; + try std.testing.expectEqualStrings(" Filter Undo Redo Del", computedWords(pane)); + f.pager_diff = true; + try std.testing.expectEqualStrings(" Diff Filter Undo Redo Del", computedWords(pane)); + f.pager = false; + f.pager_diff = false; + // A +New: Del, and Undo once it is typed into (it saves nowhere). + p.newScratchBelow(0); + const scratch = p.panes[p.view().active].?; + try std.testing.expect(scratch != pane); + try std.testing.expectEqualStrings(" Del ", try afterPath(p, scratch)); + typeKeys(p, "iz"); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expectEqualStrings(" Undo Del ", try afterPath(p, scratch)); + // A kind's own words, then Del; a pane of no kind: Del. + const doc_id = p.freeSlot().?; + const doc = try pardes.Kind.open(p, doc_id, pardes.Kind.test_kind.of(p), "/tmp/words.ppm", ""); + try std.testing.expect(std.mem.endsWith(u8, computedWords(doc), " Del")); + try std.testing.expect(std.mem.indexOf(u8, computedWords(doc), "Collapse") == null); +} + +test "typing in a tag goes after its computed words, and stays the user's text through a change of state (UX K'1)" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30, .tty_only = true }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + pane.trail.held = true; + p.sync(); + // `:` `:` gives the keyboard to the tag, on its own text, after Del. + enterTag(p, pane); + p.sync(); + typeKeys(p, "iMine"); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expectEqualStrings("Mine", pane.tag.own.?); + try std.testing.expectEqualStrings(" Del Mine", try afterPath(p, pane)); + // An edit of the computed words is refused: a Backspace at the start + // of the user's text, on the blank before it. + pane.tag.cur_col = @intCast((try restPrefix(p, p.scratch.allocator(), pane)).len); + typeKeys(p, "i"); + p.update(.{ .key = .{ .cp = pardes.Key.backspace } }); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + try std.testing.expectEqualStrings("Mine", pane.tag.own.?); + try std.testing.expectEqualStrings(" Del Mine", try afterPath(p, pane)); + // The body changed: Save Undo come in, the user's text after them, + // the tag's caret on the same character of it. + pane.focus = .body; + typeKeys(p, "ix"); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + p.sync(); + try std.testing.expectEqualStrings(" Save Undo Del Mine", try afterPath(p, pane)); + try std.testing.expectEqualStrings("Mine", pane.tag.own.?); + const whole = try tagText(p, p.scratch.allocator(), pane); + try std.testing.expectEqual(@as(u8, 'M'), whole[@intCast(pane.tag.cur_col)]); +} + +test "a dump of a build before UX K' restores a tag's old default own text as none, any other as the user's (UX K'1)" { + const dump = @import("dump.zig"); + const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30, .tty_only = true }); + defer p.deinit(); + const pane = try p.setTestFile("one\n"); + // What a tag of its kind said before (its own text, once edited). + pane.tag.own = try p.gpa.dupe(u8, kindTail(pane)); + try dump.dumpState(p); + const dropped = try dump.restore(p, p.dump_out.?, "old"); + defer dropped.deinit(); + try std.testing.expect(dropped.panes[0].?.tag.own == null); + try std.testing.expectEqualStrings("/test.txt Keep Del ", try tagText(dropped, dropped.scratch.allocator(), dropped.panes[0].?)); + // Edited around: kept whole, after the computed words. + p.gpa.free(pane.tag.own.?); + pane.tag.own = try p.gpa.dupe(u8, " Save Term Collapse Follow Del Mine"); + try dump.dumpState(p); + const kept = try dump.restore(p, p.dump_out.?, "custom"); + defer kept.deinit(); + try std.testing.expectEqualStrings(" Save Term Collapse Follow Del Mine", kept.panes[0].?.tag.own.?); +} |
