summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Band.zig13
-rw-r--r--core/Command.zig147
-rw-r--r--core/Core.zig250
-rw-r--r--core/Dir.zig2
-rw-r--r--core/Effect.zig25
-rw-r--r--core/File.zig57
-rw-r--r--core/Handover.zig4
-rw-r--r--core/Jump.zig2
-rw-r--r--core/Kind.zig59
-rw-r--r--core/Messages.zig3
-rw-r--r--core/Names.zig47
-rw-r--r--core/Output.zig9
-rw-r--r--core/Pick.zig518
-rw-r--r--core/Pipe.zig13
-rw-r--r--core/Query.zig63
-rw-r--r--core/Store.zig2
-rw-r--r--core/Stream.zig29
-rw-r--r--core/TagState.zig15
-rw-r--r--core/Term.zig2
-rw-r--r--core/Trail.zig12
-rw-r--r--core/builtins.zig3
-rw-r--r--core/colors.zig15
-rw-r--r--core/config.zig29
-rw-r--r--core/draw.zig53
-rw-r--r--core/dump.zig50
-rw-r--r--core/edit.zig33
-rw-r--r--core/fs.zig10
-rw-r--r--core/jj.zig4
-rw-r--r--core/keys.zig4
-rw-r--r--core/layout.zig91
-rw-r--r--core/look.zig54
-rw-r--r--core/lsp/Ask.zig10
-rw-r--r--core/lsp/lsp.zig6
-rw-r--r--core/mouse.zig55
-rw-r--r--core/ninep/cols.zig24
-rw-r--r--core/ninep/ctl.zig18
-rw-r--r--core/ninep/pane.zig2
-rw-r--r--core/ninep/pty.zig1
-rw-r--r--core/replica.zig6
-rw-r--r--core/root.zig39
-rw-r--r--core/syntax.zig731
-rw-r--r--core/tagline.zig551
-rw-r--r--core/tutor.txt21
43 files changed, 2589 insertions, 493 deletions
diff --git a/core/Band.zig b/core/Band.zig
index 8ee5c9f0..d60e9831 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -40,6 +40,9 @@ pub const Row = struct {
on: bool = false,
/// Its first `key` bytes are a key: the key ink, bold.
key: u8 = 0,
+ /// Its first `kind` bytes are a symbol's kind mark (`t`, `f`, `m`):
+ /// the keyword's ink (UX DESIGN N4).
+ kind: u8 = 0,
/// Its first `chord` bytes are a chord (Help's `SPC h t`): the key ink
/// at the text's weight.
chord: u8 = 0,
@@ -53,8 +56,9 @@ pub const Row = struct {
index: u16 = 0,
/// Marked in a picker's list: `•` before it.
mark: bool = false,
- /// Its first `pre` bytes are a place (`file:line`, `@p3`): the name's
- /// tint; the `faint` bytes after them dimmed (a path's directory).
+ /// Its first `pre` bytes are a place (`file:line`, `@p3`) or a kind
+ /// mark: the name's tint; the `faint` bytes after them dimmed (a path's
+ /// directory, a symbol's qualifier).
pre: u16 = 0,
faint: u16 = 0,
/// Said at the row's right end in the dim ink, two cells off its text
@@ -644,6 +648,7 @@ fn cutRow(arena: std.mem.Allocator, tab: u16, row: Row, room: u16) !Row {
fit.text = try std.mem.concat(arena, u8, &.{ row.text[0..cut], if (room > 0) "…" else "" });
for (row.marks) |m| if (m < cut) try marks.append(arena, m);
fit.key = @intCast(@min(row.key, cut));
+ fit.kind = @intCast(@min(row.kind, cut));
fit.pre = @intCast(@min(row.pre, cut));
fit.faint = @intCast(@min(row.faint, cut -| fit.pre));
}
@@ -681,6 +686,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 +723,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..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 => {
@@ -263,14 +273,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 +294,38 @@ 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 };
+}
+
+/// 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
@@ -297,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,
@@ -320,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;
}
@@ -569,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 };
@@ -580,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 "",
@@ -605,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)];
@@ -646,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;
}
@@ -691,6 +742,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 +753,22 @@ 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), ": 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 "));
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);
+ // 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 "));
@@ -990,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);
+}
diff --git a/core/Core.zig b/core/Core.zig
index 9cd58c50..3a2e1f51 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -1004,24 +1004,11 @@ fn setLastDumpInner(p: *Pardes, path: []const u8) void {
ctlfs.events.notePath(p, "dump", path);
}
-/// The workspace tag's `Restore <path>` names `path` from now on: the
-/// default's does by itself, and one the tag was edited around (its own
-/// text) has the old path swapped, never left pointing at a dump that is
-/// not the last.
+/// The window row's `Restore <path>` names `path` from now on: a computed
+/// word (UX K'2, tagline.headerWords), never the user's text.
pub fn pointRestoreAt(p: *Pardes, path: []const u8) void {
const copy = p.gpa.dupe(u8, path) catch |err| return p.reportError(.at(p.view().active), "Restore", err);
- if (p.last_dump) |old| {
- if (p.global_tag.own) |own| swap: {
- const a = p.scratch.allocator();
- const was = std.fmt.allocPrint(a, "Restore {s}", .{old}) catch break :swap;
- if (std.mem.indexOf(u8, own, was) == null) break :swap;
- const now = std.fmt.allocPrint(a, "Restore {s}", .{path}) catch break :swap;
- const swapped = std.mem.replaceOwned(u8, p.gpa, own, was, now) catch break :swap;
- p.gpa.free(own);
- p.global_tag.own = swapped;
- }
- p.gpa.free(old);
- }
+ if (p.last_dump) |old| p.gpa.free(old);
p.last_dump = copy;
}
@@ -1170,14 +1157,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 |_| {}
}
@@ -1347,6 +1333,8 @@ pub fn toView(p: *Pardes, k: View.Id) void {
if (k.index() == p.live) return;
const taped = pardes.tape.enter(p, .{ .to_view = k });
defer pardes.tape.leave(p, taped);
+ // A terminal the going view sizes takes the size its inputs left it.
+ p.sizeTerminals();
Views.to(p, k.index());
}
@@ -1665,6 +1653,7 @@ pub fn settle(p: *Pardes) void {
// ...and the last line of an open closed with no newline after it.
ctlfs.runClosedLines(p);
while (p.nextQueued()) |ev| p.update(ev);
+ p.sizeTerminals();
while (p.nextEffect()) |e| p.perform(e);
turn.bump(&turn.epoch);
}
@@ -1845,7 +1834,9 @@ fn updateInner(p: *Pardes, ev: Event) void {
pardes.panes.Query.produceAll(p, ev == .tick, ev == .key);
pardes.Pick.produceAll(p, ev == .tick);
_ = p.scratch.reset(.{ .retain_with_limit = memory.limits.scratch_kept });
- p.sync();
+ // Laid out; its terminals are sized when the burst it came in is
+ // (`settle`, `sizeTerminals`).
+ p.layOut();
p.fsReport();
ctlfs.events.announce(p);
}
@@ -1967,8 +1958,41 @@ pub fn saveRecent(p: *Pardes) void {
}
/// Recompute geometry, push grid-size changes to each emulator and pty,
-/// fire deferred greetings.
+/// fire deferred greetings: a step of its own (a 9P request's, a view's).
pub fn sync(p: *Pardes) void {
+ p.layOut();
+ p.sizeTerminals();
+}
+
+/// Each terminal's emulator and pty at the size its pane is laid out to,
+/// once a step and its burst of inputs (`settle`), never once a key: a
+/// size the keys of one burst give and take back (a level borrowing a
+/// shell's rows, the next key giving them back) reaches neither. Every
+/// reflow clears the prompt line under the cursor for the shell to draw
+/// again (ghostty's Screen.resize, `shell_redraws_prompt`), and the shell,
+/// told twice, reads its size once, finds the one it had and draws
+/// nothing: the prompt was gone until it next printed one. The emulator's
+/// own size says what it was given; the view that sizes a terminal
+/// (`sizes`) has its size.
+pub fn sizeTerminals(p: *Pardes) void {
+ for (p.panes, 0..) |slot, id| {
+ const pane = slot orelse continue;
+ const state = pane.terminal orelse continue;
+ if (!p.sizes(pane)) continue;
+ const grid = pardes.Term.grid(state);
+ if (grid.cols == pane.cols and grid.len == pane.rows) continue;
+ pane.resizeGrid(p, pane.cols, pane.rows);
+ p.shell_rows.markStale(pane); // reflow moved every row
+ p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = pane.cols, .rows = pane.rows } });
+ pane.fs.winsize = null;
+ }
+}
+
+/// The step's geometry: each pane's rect, tag rows and size (a terminal's
+/// emulator and pty follow once a burst: `sizeTerminals`), its bands, and
+/// the deferred greetings. What a step lays out in its middle, to read the
+/// geometry after (a picker's first preview), is laid out with this.
+pub fn layOut(p: *Pardes) void {
const v = p.view();
while (p.unplaced.findFirstSet()) |id| {
p.unplaced.unset(id);
@@ -1981,7 +2005,9 @@ pub fn sync(p: *Pardes) void {
// A file opened or closed this step: the kept list follows.
p.saveRecent();
tagline.flattenHeaders(p);
- if (p.headerColumn() != null and layout.columnBarHeight(p) == 0) {
+ // A column's tag with no row to be in lets the keyboard go; a lone
+ // column's keeps it in the window row (UX K'2).
+ if (p.headerColumn() != null and layout.columnBarHeight(p) == 0 and !layout.columnInWindowRow(p)) {
tagline.exitHeader(p);
}
pardes.panes.reapPanes(p);
@@ -2021,7 +2047,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;
@@ -2083,14 +2109,6 @@ pub fn sync(p: *Pardes) void {
if ((cols != pane.cols or rows != pane.rows) and (r.h > pane.tag_rows or (pane.isTerminal() and !pane.collapsed and r.h > 0)) and
(!pane.isTerminal() or p.sizes(pane)))
{
- // doc panes have no pty/emulator grid to reflow; just record
- // the size so bodyText renders the right number of rows
- if (pane.isTerminal()) {
- pane.resizeGrid(p, cols, rows);
- p.shell_rows.markStale(pane); // reflow moved every row
- p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = cols, .rows = rows } });
- pane.fs.winsize = null;
- }
pane.cols = cols;
pane.rows = rows;
if (pane.file) |*file| file.syntax_dirty = true;
@@ -2544,25 +2562,30 @@ test "topbar hover highlights exactly the executable word" {
defer frame.deinit();
_ = try p.render(frame.allocator());
- p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 1, .row = 0 } });
- _ = frame.reset(.retain_capacity);
- const hovered = try p.render(frame.allocator());
- for (0.."Newcol".len) |col| {
- const cell = hovered.at(TAG_TEXT_INSET + @as(u16, @intCast(col)), 0);
- try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, cell.style.bg);
- try std.testing.expectEqual(Color{ .rgb = p.theme().sel_fg }, cell.style.fg);
- }
- try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(TAG_TEXT_INSET + 6, 0).style.bg);
+ // Each side of the window row (UX K'2): the lone column's `New`, then
+ // the window's `Find`.
+ const words = tagline.windowRow(p).words;
+ for ([_]struct { at: u16, len: u16 }{ .{ .at = TAG_TEXT_INSET, .len = "New".len }, .{ .at = words, .len = "Find".len } }) |word| {
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = word.at + 1, .row = 0 } });
+ _ = frame.reset(.retain_capacity);
+ const hovered = try p.render(frame.allocator());
+ for (0..word.len) |col| {
+ const cell = hovered.at(word.at + @as(u16, @intCast(col)), 0);
+ try std.testing.expectEqual(Color{ .rgb = p.theme().sel_bg }, cell.style.bg);
+ try std.testing.expectEqual(Color{ .rgb = p.theme().sel_fg }, cell.style.fg);
+ }
+ try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, hovered.at(word.at + word.len, 0).style.bg);
- p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = TAG_TEXT_INSET + 6, .row = 0 } });
- _ = frame.reset(.retain_capacity);
- const whitespace = try p.render(frame.allocator());
- try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(TAG_TEXT_INSET + 1, 0).style.bg);
+ p.update(.{ .mouse = .{ .button = .none, .kind = .motion, .col = word.at + word.len, .row = 0 } });
+ _ = frame.reset(.retain_capacity);
+ const whitespace = try p.render(frame.allocator());
+ try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, whitespace.at(word.at + 1, 0).style.bg);
+ }
p.update(.pointer_leave);
_ = frame.reset(.retain_capacity);
const left = try p.render(frame.allocator());
- try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(TAG_TEXT_INSET + 1, 0).style.bg);
+ try std.testing.expectEqual(Color{ .rgb = p.chromeTheme().tag_bg }, left.at(words + 1, 0).style.bg);
}
test "pane-tag Exec prefers Term and argument builtins before shell fallback" {
@@ -2573,9 +2596,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;
@@ -2602,10 +2626,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,
@@ -2621,9 +2646,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) {
@@ -2695,12 +2721,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);
@@ -2761,7 +2789,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);
@@ -2791,7 +2819,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);
@@ -2803,7 +2833,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);
@@ -3075,7 +3105,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.
@@ -3278,7 +3308,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" {
@@ -3304,7 +3334,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.
@@ -3344,7 +3374,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);
@@ -3362,7 +3392,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;
@@ -3384,7 +3414,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;
@@ -3745,18 +3775,17 @@ test "tabbed file aligns syntax cursor and mouse at the nearest insertion gap" {
try std.testing.expect(look.expandedSel(p, pane, .{ .state = .dragging, .c0 = separator, .c1 = separator, .r0 = BOX_H, .r1 = BOX_H }) == null);
}
-test "the workspace tag's Restore word names the last dump, the tag edited around it or not, across a Restore too" {
+test "the window row's Restore word names the last dump, the user's text after it, across a Restore too (UX K'2)" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true });
defer p.deinit();
p.setLastDump("/tmp/a.zon");
- // The tag edited: its own text holds the Restore word as it was then.
- p.global_tag.own = try p.gpa.dupe(u8, try std.fmt.allocPrint(p.scratch.allocator(), "{s} Mine", .{tagline.headerDefault(p, .workspace)}));
+ p.global_tag.own = try p.gpa.dupe(u8, "Mine");
p.setLastDump("/tmp/b.zon");
- try std.testing.expect(std.mem.indexOf(u8, p.global_tag.own.?, "Restore /tmp/b.zon Mine") != null);
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Restore /tmp/b.zon Mine", tagline.topbar(p));
try dump.dumpState(p);
const restored = try dump.restore(p, p.dump_out.?, "/tmp/c.zon");
defer restored.deinit();
- try std.testing.expect(std.mem.indexOf(u8, restored.global_tag.own.?, "Restore /tmp/c.zon Mine") != null);
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Restore /tmp/c.zon Mine", tagline.topbar(restored));
try std.testing.expectEqualStrings("/tmp/c.zon", restored.last_dump.?);
}
@@ -3765,27 +3794,45 @@ test "editable workspace and column tags are typed into and persist" {
defer p.deinit();
_ = try p.setTestFile("untouched\n");
p.presented();
- try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y);
+ // One column: its tag in the window row, no column row (UX K'2).
+ try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y);
+ const words = tagline.windowRow(p).words;
// a sweep over a header is its selection, the caret where it ended
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = 0 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = TAG_TEXT_INSET + 6, .row = 0 } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET + 6, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = words, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .drag, .col = words + 6, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = words + 6, .row = 0 } });
try std.testing.expect(p.global_tag.vsel.active and p.global_tag.vsel.col == 0 and p.global_tag.cur_col == 6);
- // A clicked header is in normal mode: `a` types after the sweep's
- // last character, the blank it ended on.
+ // A clicked header is in normal mode: `a` types after the sweep's last
+ // character, in the computed words: refused, they are no one's.
p.update(.{ .key = .{ .cp = 'a', .text = "a" } });
p.update(.{ .key = .{ .cp = 'H', .text = "Help " } });
- try std.testing.expect(std.mem.startsWith(u8, p.global_tag.own.?, "Newcol Help Joincol"));
+ try std.testing.expect(p.global_tag.own == null);
p.update(.{ .key = .{ .cp = Key.escape } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = TAG_TEXT_INSET, .row = TOPBAR_H } });
- p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = TAG_TEXT_INSET, .row = TOPBAR_H } });
+ // After them, the user's text.
+ const end: u16 = @intCast(words + "Find Grep Newcol Help Exit ".len);
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = end, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = end, .row = 0 } });
+ p.update(.{ .key = .{ .cp = 'i', .text = "i" } });
+ p.update(.{ .key = .{ .cp = 'H', .text = "Help " } });
+ try std.testing.expectEqualStrings("Help ", p.global_tag.own.?);
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Help ", tagline.topbar(p));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // The column's tag, at the window row's left: typed into, it has the
+ // user's text and the column row comes for it; emptied, it goes.
+ const own: u16 = TAG_TEXT_INSET + "New Term ".len;
+ p.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = own, .row = 0 } });
+ p.update(.{ .mouse = .{ .button = .left, .kind = .release, .col = own, .row = 0 } });
+ try std.testing.expectEqual(@as(?usize, 0), p.headerColumn());
p.update(.{ .key = .{ .cp = 'i', .text = "i" } });
p.update(.{ .key = .{ .cp = 'é', .text = "é" } });
- try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "éNew"));
+ try std.testing.expectEqualStrings("New Term é", tagline.columnTag(p, 0));
+ try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y);
p.update(.{ .key = .{ .cp = Key.backspace } });
- try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "New"));
+ try std.testing.expectEqualStrings("New Term ", tagline.columnTag(p, 0));
+ try std.testing.expectEqual(TOPBAR_H, p.view().rects[0].y);
+ try std.testing.expectEqual(@as(?usize, 0), p.headerColumn());
p.update(.{ .paste = "Grep " });
- try std.testing.expect(std.mem.startsWith(u8, tagline.columnTag(p, 0), "Grep New"));
+ try std.testing.expectEqualStrings("New Term Grep ", tagline.columnTag(p, 0));
try std.testing.expectEqualStrings("untouched\n", p.panes[0].?.file.?.content);
try dump.dumpState(p);
const restored = try dump.restore(p, p.dump_out.?, "test");
@@ -3797,7 +3844,7 @@ test "editable workspace and column tags are typed into and persist" {
try dump.dumpState(p);
const empty = try dump.restore(p, p.dump_out.?, "test");
defer empty.deinit();
- try std.testing.expectEqualStrings("", tagline.columnTag(empty, 0));
+ try std.testing.expectEqualStrings("New Term ", tagline.columnTag(empty, 0));
}
test "column tag first-cell execution keeps New local to the clicked column" {
@@ -3825,6 +3872,7 @@ test "a screen too short for the column row releases a column tag's focus withou
defer p.deinit();
const pane = try p.setTestFile("unchanged body\n");
p.view().col_tags[0].own = try p.gpa.dupe(u8, "New Help");
+ p.sync();
p.presented();
const shown = p.view().rects[0];
try std.testing.expectEqual(TOPBAR_H + COLBAR_H, shown.y);
@@ -3838,7 +3886,7 @@ test "a screen too short for the column row releases a column tag's focus withou
try std.testing.expect(p.view().header == null and p.headerColumn() == null);
p.update(.{ .resize = .{ .cols = 60, .rows = 12 } });
try std.testing.expectEqual(shown, p.view().rects[0]);
- try std.testing.expectEqualStrings("New Help", tagline.columnTag(p, 0));
+ try std.testing.expectEqualStrings("New Term New Help", tagline.columnTag(p, 0));
try std.testing.expectEqualStrings("unchanged body\n", pane.file.?.content);
}
@@ -4186,6 +4234,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" {
defer p.deinit();
p.update(.{ .resize = .{ .cols = 80, .rows = 24 } });
p.update(.{ .key = .{ .cp = 'n', .alt = true } }); // a shell under the doc
+ p.sync(); // its emulator sized as its step's end sizes it, before its shell speaks
const shell = p.view().active;
const sp = p.panes[shell].?;
try std.testing.expect(sp.isTerminal());
@@ -4252,6 +4301,7 @@ test "entering tty walks the shell cursor to the column clicked past the prompt"
defer p.deinit();
p.update(.{ .resize = .{ .cols = 80, .rows = 24 } });
p.update(.{ .key = .{ .cp = 'n', .alt = true } });
+ p.sync(); // its emulator sized as its step's end sizes it, before its shell speaks
const shell = p.view().active;
const sp = p.panes[shell].?;
p.update(.{ .output = .{
@@ -4297,3 +4347,33 @@ test "entering tty walks the shell cursor to the column clicked past the prompt"
test "every allocation failure during boot is a clean OutOfMemory" {
try std.testing.checkAllAllocationFailures(std.testing.allocator, bootAndTearDown, .{});
}
+
+test "a level that borrows a shell's rows and gives them back in one burst of keys resizes neither its emulator nor its pty: its prompt line stays (M1's ttyhelp row 3)" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell's emulator
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 31, .boot = .tty });
+ defer p.deinit();
+ const shell = p.panes[0].?;
+ // bash's prompt as pardes's marks draw it (dev/Shell.zig bash_rc),
+ // the cursor at its input.
+ p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } });
+ const below = p.view().cols[0].panes[1];
+ p.view().active = below;
+ p.settle();
+ const rows = shell.rows;
+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena.deinit();
+ const body_layer = @import("body_layer.zig");
+ try std.testing.expect(std.mem.startsWith(u8, try body_layer.bodyText(p.settings.tab, arena.allocator(), shell), "$ "));
+ // `?`'s level takes rows of the shell's (layout.floorRows), `tutor`
+ // narrows it to one leaf and gives them back: keys of one burst, one
+ // settle after them, as a frontend takes a read of them.
+ p.update(.{ .key = .{ .cp = ' ', .text = " " } });
+ p.update(.{ .key = .{ .cp = '?', .text = "?" } });
+ try std.testing.expect(shell.rows < rows);
+ for ("tutor") |c| p.update(.{ .key = .{ .cp = c, .text = &.{c} } });
+ try std.testing.expectEqual(rows, shell.rows);
+ // Its pty told nothing: no SIGWINCH for a size it had.
+ while (p.nextEffect()) |e| try std.testing.expect(e != .resize_pty);
+ p.settle();
+ try std.testing.expect(std.mem.startsWith(u8, try body_layer.bodyText(p.settings.tab, arena.allocator(), shell), "$ "));
+}
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..6146df69 100644
--- a/core/Effect.zig
+++ b/core/Effect.zig
@@ -64,6 +64,10 @@ pub const Effect = union(enum) {
/// `arg` up to 128 bytes, or for `explain` the query it explains,
/// `<kind> <arg>`.
lsp: struct { id: u32, kind: lsp.Kind, pane: Pane.Id, offset: u32, arg: Buf(160) },
+ /// A file opened in pane `pane` (File.open, a session's revived pane):
+ /// the server its language speaks to started and told of it, off the
+ /// loop (dev/Lsp.zig open), so its first query finds it ready.
+ lsp_open: struct { pane: Pane.Id },
/// Snapshot the matching request with pipeRequest(id), then run it away
/// from the UI/event loop and answer with pipe_resp.
pipe: struct { id: u32 },
@@ -216,6 +220,8 @@ fn performInner(p: *Pardes, e: Effect) void {
},
.lsp => |q| p.tape.host(p, .lsp, .{.{ .id = q.id, .kind = q.kind, .pane = q.pane, .offset = q.offset, .arg = q.arg.slice() }}) orelse
p.update(.{ .lsp_resp = .{ .id = q.id, .rows = "" } }),
+ // No workers here (a test, a board): no server starts before a query.
+ .lsp_open => |o| _ = p.tape.host(p, .lsp_open, .{o.pane}),
.pipe => |q| p.tape.host(p, .pipe, .{q.id}) orelse
p.update(.{ .pipe_resp = .{ .id = q.id, .success = false, .outputs = &.{} } }),
// No workers here (a test, a board): it runs on the loop.
@@ -442,8 +448,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 +633,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 e246285c..d54d5011 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -60,35 +60,39 @@ pub const History = struct {
}
};
-/// Owned syntax results: a text's declarations at a revision.
+/// Owned syntax results: a text's declarations and symbols at a revision.
pub const ContextCache = struct {
/// Its revision is dumped and digested: a worker's parse is an input,
/// which a client joined since never saw, and a step reads what it
- /// left (Query.ownerDecls). The declarations are made again from the
- /// text at a load (`reload`), with the allocator that made them.
- pub const replica = .{ .local = .{"allocator"}, .derived = .{"declarations"} };
+ /// left (Query.ownerDecls, the Symbols source). The declarations and
+ /// symbols are made again from the text at a load (`reload`), with the
+ /// allocator that made them.
+ pub const replica = .{ .local = .{"allocator"}, .derived = .{ "declarations", "symbols" } };
allocator: ?std.mem.Allocator = null,
declarations: []syntax.ContextDeclaration = &.{},
+ symbols: []syntax.Symbol = &.{},
revision: ?u32 = null,
pub fn deinit(self: *ContextCache) void {
- if (self.allocator) |gpa| gpa.free(self.declarations);
+ if (self.allocator) |gpa| {
+ gpa.free(self.declarations);
+ gpa.free(self.symbols);
+ }
self.* = .{};
}
- /// A loaded text's (its revision the dump's): its declarations parsed
- /// again where they are of the text it has.
+ /// A loaded text's (its revision the dump's): its context parsed
+ /// again where it is of the text it has.
pub fn reload(self: *ContextCache, gpa: std.mem.Allocator, path: []const u8, content: []const u8, revision: u32) void {
const at = self.revision orelse return;
if (at != revision) return;
- const declarations = syntax.contextDeclarations(gpa, path, content) catch return;
- self.replace(gpa, declarations, at);
+ self.replace(gpa, syntax.context(gpa, path, content) catch return, at);
}
- /// Takes ownership of declarations allocated by gpa.
- pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, declarations: []syntax.ContextDeclaration, revision: u32) void {
+ /// Takes ownership of a context allocated by gpa.
+ pub fn replace(self: *ContextCache, gpa: std.mem.Allocator, made: syntax.Context, revision: u32) void {
self.deinit();
- self.* = .{ .allocator = gpa, .declarations = declarations, .revision = revision };
+ self.* = .{ .allocator = gpa, .declarations = made.declarations, .symbols = made.symbols, .revision = revision };
}
};
@@ -922,7 +926,13 @@ pub fn open(p: *Pardes, id: usize, path: []const u8, line: usize) !*Pane {
pane.body.cur_pinned = true;
pane.body.cur_row = @intCast(scroll);
p.installPane(id, pane);
- if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
+ if (filesystem.localPath(path) != null) {
+ p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
+ // Its language's server started now, off the loop: the first
+ // question asked of it finds it ready. Not a picker's preview's,
+ // which opens no pane (Pick.preview).
+ p.emit(.{ .lsp_open = .{ .pane = .at(id) } });
+ }
return pane;
}
@@ -2191,12 +2201,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;
@@ -2490,8 +2505,7 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void {
pub fn refreshContext(p: *Pardes, pane: *Pane, f: *State) void {
if (!f.tree_context or !supportsContext(pane) or f.context.revision == f.revision) return;
// The file's declarations, in its lines (the layer's are none of it).
- const declarations = syntax.contextDeclarations(p.tree_sitter_gpa, f.path, fileText(f, p.scratch.allocator()) catch return) catch return;
- f.context.replace(p.tree_sitter_gpa, declarations, f.revision);
+ f.context.replace(p.tree_sitter_gpa, syntax.context(p.tree_sitter_gpa, f.path, fileText(f, p.scratch.allocator()) catch return) catch return, f.revision);
}
pub fn refreshHighlights(p: *Pardes) void {
@@ -3614,12 +3628,13 @@ test "context cache frees each allocation with its original allocator" {
defer std.testing.expect(second.deinit() == .ok) catch @panic("second allocator leaked");
var cache: ContextCache = .{};
defer cache.deinit();
- cache.replace(first.allocator(), try first.allocator().alloc(syntax.ContextDeclaration, 1), 1);
- cache.replace(second.allocator(), try second.allocator().alloc(syntax.ContextDeclaration, 2), 2);
+ cache.replace(first.allocator(), .{ .declarations = try first.allocator().alloc(syntax.ContextDeclaration, 1), .symbols = try first.allocator().alloc(syntax.Symbol, 1) }, 1);
+ cache.replace(second.allocator(), .{ .declarations = try second.allocator().alloc(syntax.ContextDeclaration, 2), .symbols = try second.allocator().alloc(syntax.Symbol, 2) }, 2);
try std.testing.expectEqual(@as(?u32, 2), cache.revision);
cache.deinit();
try std.testing.expect(cache.allocator == null);
try std.testing.expectEqual(@as(usize, 0), cache.declarations.len);
+ try std.testing.expectEqual(@as(usize, 0), cache.symbols.len);
}
/// The inks of row `row`'s first `n` text cells of pane `id` as `s` draws them.
diff --git a/core/Handover.zig b/core/Handover.zig
index 6f7340b2..f60ce72b 100644
--- a/core/Handover.zig
+++ b/core/Handover.zig
@@ -628,6 +628,10 @@ test "a column let go over another window goes beside the column the pointer is
const gpa = std.testing.allocator;
const from = try twoPanes(gpa);
defer from.deinit();
+ // A column's grip is in the column row, which a second column brings
+ // (UX K'2).
+ try std.testing.expect(from.executeBuiltinLine(0, "Newcol"));
+ from.sync();
const r = from.view().rects[0];
const c = layout.findPane(from, 0).?.col;
from.update(.{ .mouse = .{ .button = .left, .kind = .press, .col = from.view().col_x[c], .row = from.topBarHeight() } });
diff --git a/core/Jump.zig b/core/Jump.zig
index 3632a039..143aa9b5 100644
--- a/core/Jump.zig
+++ b/core/Jump.zig
@@ -472,6 +472,8 @@ test "Ctrl-o pops the walk one word at a time (UX L'1): after SPC f f words, Ent
defer p.deinit();
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
+ // A work tree of its own: Find searches it, not the one the test runs in.
+ try tmp.dir.createDir(std.testing.io, ".git", .default_dir);
var text: [60 * 16]u8 = undefined;
var w: std.Io.Writer = .fixed(&text);
for (1..61) |n| try w.print("{s} {d}\n", .{ if (n % 12 == 4) "in_word" else "line", n });
diff --git a/core/Kind.zig b/core/Kind.zig
index 4e1aa469..4841a55c 100644
--- a/core/Kind.zig
+++ b/core/Kind.zig
@@ -137,7 +137,7 @@ pub const Slot = struct {
// jobs' inputs, its file's hash, a placeholder's record), and what
// a frame makes (the thumb, the pointer, whether one was drawn: a
// view's, never a step's).
- .local = .{ "ops", "st", "gpa", "arena", "plain", "file", "opened", "reloads", "jobs", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "used" },
+ .local = .{ "ops", "st", "gpa", "arena", "plain", "file", "opened", "reloads", "jobs", "record", "thumb_at", "thumb_span", "pointer", "painted", "over", "used", "drawn_from", "size" },
};
/// Its kind's code here; null in a placeholder (`live` false: its kind
/// not in the registry, its record kept for the day it comes) or a
@@ -215,6 +215,13 @@ pub const Slot = struct {
/// A client's join: its plain kind's file, until the pane is opened
/// from it (dump.plainHere).
file: ?[]u8 = null,
+ /// This process's draws made before it (`drawn` then): an answer to
+ /// one of them is another slot's, of a pane that showed something
+ /// else (a picker's preview of the row before), and is dropped.
+ drawn_from: u32 = 0,
+ /// Its file's bytes, as a picker's line naming it says them until its
+ /// kind's picture is drawn (Pick.preview).
+ size: u64 = 0,
/// Debug: the kind's allocations, which paint must leave as they are.
/// The slot's allocator's, as the slot is: a client's rollback puts
/// the list back with the slot that holds it (on the page allocator,
@@ -259,16 +266,12 @@ fn caps(p: *const Pardes, s: *const Slot) Caps {
/// word opened) from `bytes`: made whatever the kind says, with what it
/// refused in `slot.refused` for the caller to say.
pub fn open(p: *Pardes, id: usize, k: u8, path: ?[]const u8, bytes: ?[]const u8) !*Pane {
- const e = &p.kinds.kinds[k];
- // A plain kind's slot and block are the core's (a client's epoch).
- const gpa = if (e.caps.plain) p.gpa else p.image_gpa;
- const s = try gpa.create(Slot);
- s.* = .{ .ops = p.kinds.ops[k], .live = true, .gpa = gpa, .arena = .init(gpa), .version = e.version, .gen = e.gen, .name = e.name };
+ const s = try newSlot(p, k, path orelse "");
errdefer {
+ const gpa = s.gpa;
s.free();
gpa.destroy(s);
}
- s.path = try gpa.dupe(u8, path orelse "");
const pane = try p.newDocPane(id);
pane.addon = s;
_ = reopen(p, id, s, bytes);
@@ -278,6 +281,23 @@ pub fn open(p: *Pardes, id: usize, k: u8, path: ?[]const u8, bytes: ?[]const u8)
return pane;
}
+/// A slot of kind `k` for `path`, its kind's state not made yet (`reopen`
+/// makes it): a pane's, or a picker's preview's in the pane it lands in
+/// (Pick.preview), that pane's own text set aside meanwhile.
+pub fn newSlot(p: *Pardes, k: u8, path: []const u8) !*Slot {
+ const e = &p.kinds.kinds[k];
+ // A plain kind's slot and block are the core's (a client's epoch).
+ const gpa = if (e.caps.plain) p.gpa else p.image_gpa;
+ const s = try gpa.create(Slot);
+ s.* = .{ .ops = p.kinds.ops[k], .live = true, .gpa = gpa, .arena = .init(gpa), .version = e.version, .gen = e.gen, .name = e.name, .drawn_from = drawn };
+ errdefer {
+ s.free();
+ gpa.destroy(s);
+ }
+ s.path = try gpa.dupe(u8, path);
+ return s;
+}
+
/// `open` of the file at `path`, read here (a file that cannot be read
/// is no bytes: its kind may refuse it). The slot stays ours across the
/// read: another request may make a pane meanwhile.
@@ -305,10 +325,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;
@@ -418,9 +438,10 @@ pub fn close(p: *Pardes, pane: *Pane) void {
/// The pane's body painted over the `cols` x `rows` cells at (x, y):
/// its cells into `s`, its placements after the frame's others. A pane
/// whose kind has no code here, or a placeholder, says why in a line.
-pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pane, id: usize, x: u16, y: u16, cols: u16, rows: u16) void {
- const slot = pane.addon orelse return;
- if (cols == 0 or rows == 0) return;
+/// False when its kind painted nothing (its picture not drawn yet).
+pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pane, id: usize, x: u16, y: u16, cols: u16, rows: u16) bool {
+ const slot = pane.addon orelse return true;
+ if (cols == 0 or rows == 0) return true;
const th = p.theme();
const fg: surface.Color = if (th.fg) |f| .{ .rgb = f } else .default;
const bg: surface.Color = if (th.bg) |b| .{ .rgb = b } else .default;
@@ -431,17 +452,17 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa
const why = if (caps(p, slot).plain) "it is not in its addons nor the session's library at its path here, or it broke its promise here" else "its state is not plain (PA_PLAIN), so it runs in the session alone";
var line: [200]u8 = undefined;
_ = s.print(x, y, cols, std.fmt.bufPrint(&line, "addon {s} {d} does not run in this client: {s}", .{ slot.nameOf(), slot.version, why }) catch &line, .{ .fg = fg, .bg = bg });
- return;
+ return true;
} else if (slot.ops == null) {
var line: [160]u8 = undefined;
const why = if (slot.refused.len > 0) slot.refused.slice() else "Addon load <path>";
// Its kind here, it waits for its file (`<path> is not here`).
const text = if (p.kinds.byName(slot.nameOf()) != null) why else std.fmt.bufPrint(&line, "addon {s} {d} is not loaded: {s}", .{ slot.nameOf(), slot.version, why }) catch &line;
_ = s.print(x, y, cols, text, .{ .fg = fg, .bg = bg });
- return;
+ return true;
} else for (0..8) |_| {
if (ready.items.len > 0) deliver(p, slot, pane, id);
- frame.cells = (paint(p, slot, id, arena, cols, rows, &frame) orelse return);
+ frame.cells = (paint(p, slot, id, arena, cols, rows, &frame) orelse return true);
// No workers here (a test's, a bench's core): a draw that paint
// asked was done at once, and is this frame's, painted again.
if (drawer != null) break;
@@ -450,9 +471,11 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa
} else break;
}
if (frame.gpu.len != 0) s.gpu_frames[id] = .{ .bytes = frame.gpu, .serial = pane.serial, .dst = .{ .x = x, .y = y, .w = cols, .h = rows } };
+ var painted = frame.gpu.len != 0 or frame.n > 0;
for (0..@min(rows, frame.rows)) |r| for (0..@min(cols, frame.cols)) |col| {
const cell = &frame.cells[r * frame.cols + col];
if (cell.flags & c.PA_PAINTED == 0) continue;
+ painted = true;
const len = @min(cell.len, 7);
s.set(x + @as(u16, @intCast(col)), y + @as(u16, @intCast(r)), if (len == 0) " " else cell.text[0..len], styleOf(cell, fg, bg));
};
@@ -471,6 +494,7 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa
.art = slot.art,
});
}
+ return painted;
}
/// A frame of a kind's pane: its cells, `cols` a row, and its placements.
@@ -1012,6 +1036,9 @@ const Call = struct {
return o;
};
const p = cl.p orelse return o;
+ // A picker's preview shows its file and does nothing more: what its
+ // kind says, looks at or runs meanwhile is dropped (Pick.showKind).
+ if (pardes.Pick.previewing(p, cl.id)) return o;
if (o.said.len > 0) if (o.err) p.reportFailure(cl.id, o.said) else p.setMessage(.at(cl.id), o.said);
if (o.pane_name.len > 0) textPane(p, cl.id, cl.slot, o.pane_name, o.pane_text);
if (o.look.len > 0) @import("look.zig").lookAt(p, cl.id, o.look);
@@ -1289,7 +1316,7 @@ fn deliver(p: *const Pardes, slot: *Slot, pane: *const Pane, id: usize) void {
}
_ = ready.orderedRemove(i);
defer j.drop();
- if (pane.serial != j.serial or slot.gen != j.gen or slot.ops != j.ops) continue;
+ if (pane.serial != j.serial or slot.gen != j.gen or slot.ops != j.ops or j.token & ~c.PA_DRAWN <= slot.drawn_from) continue;
var cl: Call = .{ .p = null, .id = id, .slot = slot, .quiet = true, .core = p };
const prev = cl.begin("job_done");
const before = if (checked) usedHash(slot);
diff --git a/core/Messages.zig b/core/Messages.zig
index eca5ec9f..fb2c3cde 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -1566,7 +1566,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/Names.zig b/core/Names.zig
index d063bd17..9105e3c4 100644
--- a/core/Names.zig
+++ b/core/Names.zig
@@ -50,6 +50,9 @@ pub const Cand = struct {
/// What the row is of: a line of the owner (Symbols, 1-based), a
/// pane's serial (Panes); 0 for a path.
ref: u32 = 0,
+ /// Its group: the hits stay in their groups' order, scored within
+ /// each (a Symbols row's kind, UX DESIGN N3); 0 for every other source.
+ group: u8 = 0,
};
pub const Hit = struct { cand: u32, score: i32 };
@@ -128,7 +131,9 @@ pub fn typed(n: *Names, gpa: std.mem.Allocator, text: []const u8) void {
// only those are scored again (and then the ones not yet scored).
const grew = n.query_len > 0 and std.mem.startsWith(u8, q, n.queryText()) and std.mem.indexOfScalar(u8, q[n.query_len..], ' ') == null;
n.query_len = @intCast(q.len);
- @memcpy(n.query_buf[0..q.len], q);
+ // Its own query typed again, to score names that came after it
+ // (Pick.declsArrived), is the buffer itself.
+ std.mem.copyForwards(u8, n.query_buf[0..q.len], q);
n.reach = max_rows;
if (grew) {
const pending = n.pending.items[n.pending_at..];
@@ -187,9 +192,17 @@ pub fn reachTo(n: *Names, rows: usize) void {
n.gen +%= 1;
}
-/// Hit `a` goes before `b`: the higher score, then the shorter key, then
-/// the candidate added first.
+/// Hit `a` goes before `b`: the lower group, then `better`.
fn before(cands: []const Cand, a: Hit, b: Hit) bool {
+ const ga = cands[a.cand].group;
+ const gb = cands[b.cand].group;
+ if (ga != gb) return ga < gb;
+ return better(cands, a, b);
+}
+
+/// Hit `a` matched better than `b`: the higher score, then the shorter
+/// key, then the candidate added first.
+fn better(cands: []const Cand, a: Hit, b: Hit) bool {
if (a.score != b.score) return a.score > b.score;
const la = cands[a.cand].key_len;
const lb = cands[b.cand].key_len;
@@ -230,6 +243,22 @@ fn sink(heap: []Hit, cands: []const Cand, from: usize) void {
}
}
+/// The row of the hit the query matched best, wherever its group puts it:
+/// where a list's cursor starts (UX DESIGN N3); 0 for an empty query,
+/// whose rows are the source's order. Its rows up to it are sorted once
+/// `reachTo` has gone past it.
+pub fn bestRow(n: *const Names) usize {
+ const hits = n.hits.items;
+ if (hits.len == 0 or std.mem.trim(u8, n.queryText(), " ").len == 0) return 0;
+ var top = hits[0];
+ for (hits[1..]) |h| if (better(n.cands.items, h, top)) {
+ top = h;
+ };
+ var at: usize = 0;
+ for (hits) |h| at += @intFromBool(before(n.cands.items, h, top));
+ return at;
+}
+
/// The row of hit `i` and, in `marks`, the bytes of it the query matched.
pub fn row(n: *const Names, i: usize, marks: []u16, nmarks: *usize) []const u8 {
const c = n.cands.items[n.hits.items[i].cand];
@@ -435,3 +464,15 @@ test "Names keeps its best `reach` hits first in a full sort's order, the rest a
n.reachTo(max_rows + 500);
try std.testing.expectEqualSlices(Hit, all[0 .. max_rows + 500], n.hits.items[0 .. max_rows + 500]);
}
+
+test "Names takes its own query typed again: names added after it (a Symbols picker's declarations from a worker, Pick.declsArrived) are scored against it" {
+ const gpa = std.testing.allocator;
+ var n: Names = .{};
+ defer n.deinit(gpa);
+ n.typed(gpa, "zzlast");
+ for ([_][]const u8{ "fn f0001() void {", "fn zzlastfn() void {" }) |cand| try n.add(gpa, cand, 0, cand.len, 0, 0);
+ n.typed(gpa, n.queryText());
+ while (n.busy()) n.rescore(gpa);
+ try std.testing.expectEqualStrings("zzlast", n.queryText());
+ try std.testing.expectEqual(@as(usize, 1), n.hits.items.len);
+}
diff --git a/core/Output.zig b/core/Output.zig
index 8807e55d..f0b32c4e 100644
--- a/core/Output.zig
+++ b/core/Output.zig
@@ -191,11 +191,15 @@ pub fn traits(o: Origin) Traits {
};
}
+/// A list laid out as Locations (each place's lines from its file, in
+/// their order): not a file's symbols, a row each in their own order (UX
+/// DESIGN N: types, functions, fields, the rest).
pub fn usesLocationsConfig(from: Origin) bool {
const tr = traits(from);
return tr.steps and !tr.commands and from != .kind and
!std.meta.eql(from, Origin{ .query = .completion }) and
- !std.meta.eql(from, Origin{ .query = .callstack });
+ !std.meta.eql(from, Origin{ .query = .callstack }) and
+ !std.meta.eql(from, Origin{ .query = .document_symbols });
}
pub fn fileTraits(out: ?State) Traits {
@@ -237,6 +241,8 @@ pub fn isResultRow(file: *const File.State, row: usize) bool {
return !locations.isContextLine(modal.lineSlice(file.content, row));
}
+/// A language server's places in the order of their places; a file's
+/// symbols stay in theirs (lsp_client: types, functions, fields, the rest).
fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?usize) !?usize {
switch (from) {
.search => {},
@@ -251,7 +257,6 @@ fn sortResults(arena: std.mem.Allocator, from: Origin, content: []u8, anchor: ?u
.outgoing_calls,
.supertypes,
.subtypes,
- .document_symbols,
.workspace_symbols,
.diagnostics,
.workspace_diagnostics,
diff --git a/core/Pick.zig b/core/Pick.zig
index 7c40a234..c05ed084 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -182,11 +182,11 @@ pub fn deinit(pk: *Pick, gpa: std.mem.Allocator) void {
/// Whether a search a builtin asks for from pane `id` is a picker in the
/// tag (SPEC §14.3 phase 4): in a session whose jumps walk, from the
-/// keyboard or a click (kbdin's and mousein's too), never a script's word
-/// (a 9P exec's: the query pane, whose rows it reads back, and whose `not
-/// found` it hears).
+/// keyboard or a click (kbdin's and mousein's too, which run as theirs:
+/// ninep/ctl.zig writeKbdin), never a script's word (a 9P exec's: the query
+/// pane, whose rows it reads back, and whose `not found` it hears).
pub fn asked(p: *const Pardes) bool {
- return p.settings.jumps == .walk and (!p.fs.serving or p.fs.typed);
+ return p.settings.jumps == .walk and !p.fs.serving;
}
/// Picker `id`, kept or live.
@@ -226,7 +226,8 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []
const pk = make(p, source) catch |err| return p.reportError(.at(from), "pick", err);
pk.word.set(if (word.len > 0) word else words.get(source).word);
pk.keys.set(words.get(source).keys);
- pk.dir.set(Pardes.paneDir(asker));
+ // Find and Grep from the work tree's root (W8), as other finders search.
+ pk.dir.set(if (source == .find or source == .grep) workTree(p, Pardes.paneDir(asker)) else Pardes.paneDir(asker));
pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err);
hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "pick", err);
if (p.paneBySerial(pk.landing)) |host| pk.cap = p.view().rects[host].h * 2 / 5;
@@ -237,6 +238,35 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: []
if (source == .themes and query.len == 0 and p.custom_theme == null) p.view().tag_state.rows.at = @intCast(p.settings.theme);
}
+/// The work tree `dir` is in: the nearest directory at or above it that
+/// holds a `.jj` or a `.git` (a git worktree's is a file); `dir` itself
+/// when none does. Find and Grep search from it, their rows' paths
+/// relative to it, wherever in the tree the asking pane is.
+fn workTree(p: *Pardes, dir: []const u8) []const u8 {
+ var d = dir;
+ while (true) {
+ var buf: [4096]u8 = undefined;
+ for ([_][]const u8{ ".jj", ".git" }) |name| {
+ const marker = std.fmt.bufPrint(&buf, "{s}/{s}", .{ std.mem.trimEnd(u8, d, "/"), name }) catch return dir;
+ if (exec.kindOf(p.tape, marker) != null) return d;
+ }
+ d = std.Io.Dir.path.dirname(d) orelse return dir;
+ }
+}
+
+/// Where a Grep's query `q` searches and for what (SPEC §5.1): a leading
+/// directory, the root's or absolute, then a blank, narrows it to that
+/// directory (`src/torque Macro`), the rest the pattern; else all of it
+/// from the root. The directory joined in `buf`.
+fn grepScope(p: *Pardes, pk: *const Pick, q: []const u8, buf: *[4096]u8) struct { dir: []const u8, pat: []const u8 } {
+ const root = pk.dir.slice();
+ const sp = std.mem.indexOfScalar(u8, q, ' ') orelse return .{ .dir = root, .pat = q };
+ const lead = q[0..sp];
+ const dir = if (lead[0] == '/') lead else std.fmt.bufPrint(buf, "{s}/{s}", .{ std.mem.trimEnd(u8, root, "/"), lead }) catch return .{ .dir = root, .pat = q };
+ if (exec.kindOf(p.tape, dir) != .directory) return .{ .dir = root, .pat = q };
+ return .{ .dir = dir, .pat = std.mem.trimStart(u8, q[sp + 1 ..], " ") };
+}
+
/// A new picker in the ring, the oldest kept one dropped for it.
fn make(p: *Pardes, source: Source) !*Pick {
var slot: ?usize = null;
@@ -452,12 +482,17 @@ pub fn filter(p: *Pardes, pk: *Pick) void {
const q = std.mem.trim(u8, p.view().tag_state.field.text(), " ");
p.view().tag_state.rows.at = 0;
pk.shown = no_row;
- if (fuzzy(pk)) return pk.names.typed(p.gpa, q);
+ if (fuzzy(pk)) {
+ pk.names.typed(p.gpa, q);
+ return toBest(p, pk);
+ }
if (pk.source == .grep) {
pk.found.clearRetainingCapacity();
pk.found_bytes.clearRetainingCapacity();
- if (q.len > 0) {
- Stream.query(p, pk.id, .grep, q, pk.dir.slice(), if (p.fs.serving) .now else .typed) catch |err| return p.reportError(.at(p.view().active), "pick", err);
+ var buf: [4096]u8 = undefined;
+ const at = grepScope(p, pk, q, &buf);
+ if (at.pat.len > 0) {
+ Stream.query(p, pk.id, .grep, at.pat, at.dir, if (p.fs.serving) .now else .typed) catch |err| return p.reportError(.at(p.view().active), "pick", err);
if (p.fs.serving) Stream.step(p);
} else if (p.stream.target == pk.id) _ = p.stream.stop();
return;
@@ -501,7 +536,12 @@ fn allPanes(p: *const Pardes, pk: *const Pick, out: *[pardes.MAX_PANES]usize) []
/// The disk engine's rows for picker `target` (Stream.receive).
pub fn take(p: *Pardes, target: u32, kind: Stream.Kind, rows: []const u8) bool {
const pk = byId(p, target) orelse return false;
- Query.take(p, pk, kind, rows);
+ // A Grep narrowed to a directory (grepScope): its rows' paths from the
+ // root, as an unnarrowed one's are.
+ var buf: [4096]u8 = undefined;
+ const searched = p.stream.dir.items;
+ const under = if (kind == .grep and !std.mem.eql(u8, searched, pk.dir.slice())) std.fmt.bufPrint(&buf, "{s}/", .{relative(searched, pk.dir.slice())}) catch "" else "";
+ Query.take(p, pk, kind, rows, under);
// A listing's names, scored as they come.
if (kind == .files) pk.names.rescore(p.gpa);
return true;
@@ -514,15 +554,31 @@ pub fn declsArrived(p: *Pardes, serial: u32) void {
Query.gather(p, &pk.names, .symbols, pk.dir.slice(), null, p.paneBySerial(serial));
pk.names.typed(p.gpa, pk.names.queryText());
pk.names.rescore(p.gpa);
+ if (live(p) == pk) toBest(p, pk);
};
}
+/// The live picker's cursor on its best match, wherever its group puts it
+/// (UX DESIGN N3: a Symbols list stays grouped while typed), its rows
+/// sorted as far as the band shows past it.
+fn toBest(p: *Pardes, pk: *Pick) void {
+ const at = pk.names.bestRow();
+ pk.names.reachTo(at + Band.Cursor.shown);
+ p.view().tag_state.rows.at = @intCast(@min(at, std.math.maxInt(u16)));
+}
+
/// After every step: each live picker's names scored on (a frame's count),
/// and on a frame of its own after the cursor stood, the preview of the
/// current row.
pub fn produceAll(p: *Pardes, tick: bool) void {
for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) {
- if (pk.names.busy()) pk.names.rescore(p.gpa);
+ if (pk.names.busy()) {
+ // A cursor on the best match follows it while the rest are
+ // scored.
+ const on_best = live(p) == pk and p.view().tag_state.rows.at == pk.names.bestRow();
+ pk.names.rescore(p.gpa);
+ if (on_best) toBest(p, pk);
+ }
// A theme's preview in the step of the key that moved to it.
if (pk.source == .themes) pardes.colors.previewTheme(p, refAt(p, pk));
if (tick) preview(p, pk);
@@ -584,7 +640,7 @@ const Target = union(enum) { none, place: struct { path: []const u8, at: look.Sp
/// Row `i` as the band shows it and what it points at, its text in
/// `arena`.
-const Row = struct { text: []const u8, key: u8 = 0, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none, meta: []const u8 = "" };
+const Row = struct { text: []const u8, key: u8 = 0, kind: u8 = 0, pre: u16 = 0, faint: u16 = 0, quiet: [2]u16 = .{ 0, 0 }, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none, meta: []const u8 = "" };
fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.mem.Allocator.Error!Row {
const dir = pk.dir.slice();
@@ -626,7 +682,8 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.me
var marks: std.ArrayList(u16) = .empty;
var c = fd.col;
while (c < fd.end and c >= lead and pre.len + 1 + c - lead < text.len) : (c += 1) try marks.append(arena, @intCast(pre.len + 1 + c - lead));
- const path = try std.Io.Dir.path.join(arena, &.{ dir, name });
+ // (Under an absolute leading directory, grepScope's, an absolute path.)
+ const path = if (name.len > 0 and name[0] == '/') name else try std.Io.Dir.path.join(arena, &.{ dir, name });
return .{ .text = text, .pre = @intCast(pre.len), .marks = marks.items, .target = .{ .place = .{ .path = path, .at = .{ .line = fd.line, .col = fd.col + 1 } } } };
}
var marks: [Names.max_query * 4]u16 = undefined;
@@ -639,15 +696,32 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) std.me
var namebuf: [4096]u8 = undefined;
const name = if (text.len > 1 and text[0] == '"' and text[text.len - 1] == '"') look.unquoted(&namebuf, text[1 .. text.len - 1]) else text;
row.faint = @intCast(if (std.mem.lastIndexOfScalar(u8, text, '/')) |k| k + 1 else 0);
- row.target = .{ .place = .{ .path = try std.Io.Dir.path.join(arena, &.{ dir, name }), .at = .{ .line = 1, .col = 1 } } };
+ // A text at its first line; a kind's file whole, as a Look of
+ // its name opens it (a place in it is its kind's address).
+ const at: look.Spot = if (p.kinds.forPath(name) != null) .{} else .{ .line = 1, .col = 1 };
+ row.target = .{ .place = .{ .path = try std.Io.Dir.path.join(arena, &.{ dir, name }), .at = at } };
},
.panes => {
row.pre = cand.key -| 1;
row.dim = p.paneBySerial(cand.ref) == null;
row.target = .{ .pane = cand.ref };
},
+ // ` 12 m Counts.lines : usize = 0` (Query.gather): the line its
+ // meta, the mark in the keyword's ink, the qualifier and what
+ // follows the name dim (UX DESIGN N4).
.symbols => {
- row.pre = 6;
+ const line = 8;
+ if (text.len <= line or cand.key < line) return row;
+ row.text = text[line..];
+ row.meta = std.mem.trimStart(u8, text[0..6], " ");
+ const marks_in = try arena.alloc(u16, row.marks.len);
+ for (marks_in, row.marks) |*m, at| m.* = at -| line;
+ row.marks = marks_in;
+ const name_at = cand.key - line;
+ row.kind = @intCast(name_at - 1);
+ row.pre = @intCast(name_at);
+ row.faint = cand.base;
+ if (name_at + cand.key_len < row.text.len) row.quiet = .{ @intCast(name_at + cand.key_len), @intCast(row.text.len) };
const owner = p.panes[p.paneBySerial(pk.owner) orelse return row] orelse return row;
const f = owner.file orelse return row;
row.target = .{ .place = .{ .path = f.path, .at = .{ .line = cand.ref } } };
@@ -837,7 +911,7 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step {
const rows = try arena.alloc(Band.Row, w.hi - w.lo);
for (rows, w.lo..) |*row, i| {
const r = try rowAt(p, pk, arena, i);
- row.* = .{ .text = r.text, .key = r.key, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .marks = r.marks, .index = @intCast(i), .meta = r.meta };
+ row.* = .{ .text = r.text, .key = r.key, .kind = r.kind, .on = i == s.rows.at, .mark = marked(pk, idOf(pk, i)) != null, .dim = r.dim, .pre = r.pre, .faint = r.faint, .quiet = r.quiet, .marks = r.marks, .index = @intCast(i), .meta = r.meta };
}
// A place's text (a Grep's line, a list's): its `path:line` in the dim
// ink and the text after it in one column, the widest place shown
@@ -925,7 +999,11 @@ pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize {
/// The landing pane's body showing the current row's place (SPEC §5.3):
/// a file at its line, the query's matches lit for a Grep. Its own text is
/// set aside the first time, put back when the picker rolls up. A file an
-/// open pane shows is taken from it; any other is read.
+/// open pane shows is taken from it; any other is read. A file a kind
+/// takes (an addon's: a picture, a PDF), as a Look would open it
+/// (look.resolve), shows through that kind (showKind); any other that is
+/// not text (a NUL in its first 8000 bytes) as one line naming it,
+/// `blob.bin · binary · 3.0 kB`, never its bytes.
fn preview(p: *Pardes, pk: *Pick) void {
const s = &p.view().tag_state;
// No row yet: none shown, so the first to come is (a Find's listing
@@ -944,45 +1022,27 @@ fn preview(p: *Pardes, pk: *Pick) void {
const pane = p.panes[id].?;
const f = if (pane.file) |*file| file else return;
if (f.twin != 0) return;
- if (!std.mem.eql(u8, f.path, place.path)) {
+ const showing = if (pane.addon) |k| k.path else f.path;
+ if (!std.mem.eql(u8, showing, place.path)) {
if (exec.kindOf(p.tape, place.path)) |kind| if (kind != .file) return;
- const bytes = openText(p, place.path) orelse (p.tape.site(.preview, p.gpa, filesystem.read, .{ p, place.path }) catch return);
- if (std.mem.indexOfScalar(u8, bytes[0..@min(bytes.len, 8000)], 0) != null) {
- p.gpa.free(bytes);
- return;
+ const read = openText(p, place.path) orelse (p.tape.site(.preview, p.gpa, filesystem.read, .{ p, place.path }) catch return);
+ if (pane.addon != null) Kind.close(p, pane);
+ if (p.kinds.forPath(place.path)) |k| {
+ defer p.gpa.free(read);
+ return showKind(p, pk, id, k, place.path, read);
}
- const path = p.gpa.dupe(u8, place.path) catch {
- p.gpa.free(bytes);
- return;
+ const bytes = if (std.mem.indexOfScalar(u8, read[0..@min(read.len, 8000)], 0) == null) read else named: {
+ defer p.gpa.free(read);
+ break :named nameLine(p.gpa, place.path, "binary", read.len, "") catch return;
};
- if (pk.aside == null and !pk.made) {
- const history = File.History.create(p.gpa) catch {
- p.gpa.free(bytes);
- p.gpa.free(path);
- return;
- };
- pk.aside = pane.file;
- pane.file = .{ .path = path, .content = bytes, .output = .{ .from = .preview }, .history = history };
- } else {
- const pf = &pane.file.?;
- p.gpa.free(pf.path);
- pf.path = path;
- File.setContent(p, pf, bytes);
- pf.saved_revision = pf.revision;
- pf.scroll = 0;
- pf.scroll_row = 0;
- pf.syntax_dirty = true;
- pane.places.clear(p.gpa);
- }
- pane.hscroll = 0;
- pk.previewed = true;
- p.sync();
+ showText(p, pk, id, place.path, bytes);
}
+ if (pane.addon != null) return;
// The body under the band from the first place it shows (previewing):
// laid out again before the place is put in its rows.
if (!pk.previewed) {
pk.previewed = true;
- p.sync();
+ p.layOut();
}
const keyboard = p.view().active;
defer p.view().active = keyboard;
@@ -998,7 +1058,85 @@ fn preview(p: *Pardes, pk: *Pick) void {
}
look.focusPaneLine(p, id, at, .third);
// A Grep's matches in the file lit, as its own pane would have them.
- if (pk.source == .grep) pane.places.search(p, pane, .list, pk.id, std.mem.trim(u8, s.field.text(), " "), true, null, false);
+ if (pk.source == .grep) {
+ var buf: [4096]u8 = undefined;
+ pane.places.search(p, pane, .list, pk.id, grepScope(p, pk, std.mem.trim(u8, s.field.text(), " "), &buf).pat, true, null, false);
+ }
+}
+
+/// Landing pane `id`'s text `bytes` (taken) as `path`: its own text set
+/// aside the first time, a preview's text after that changed in place.
+fn showText(p: *Pardes, pk: *Pick, id: usize, path_: []const u8, bytes: []u8) void {
+ const pane = p.panes[id].?;
+ const path = p.gpa.dupe(u8, path_) catch {
+ p.gpa.free(bytes);
+ return;
+ };
+ if (pk.aside == null and !pk.made) {
+ const history = File.History.create(p.gpa) catch {
+ p.gpa.free(bytes);
+ p.gpa.free(path);
+ return;
+ };
+ pk.aside = pane.file;
+ pane.file = .{ .path = path, .content = bytes, .output = .{ .from = .preview }, .history = history };
+ } else {
+ const pf = &pane.file.?;
+ p.gpa.free(pf.path);
+ pf.path = path;
+ File.setContent(p, pf, bytes);
+ pf.saved_revision = pf.revision;
+ pf.scroll = 0;
+ pf.scroll_row = 0;
+ pf.syntax_dirty = true;
+ pane.places.clear(p.gpa);
+ }
+ pane.hscroll = 0;
+ pk.previewed = true;
+ p.layOut();
+}
+
+/// Landing pane `id` showing the file at `path` through kind `k`, as a
+/// Look would open it in a pane of its own: a slot of that kind over the
+/// pane's text, which stays under it, unseen, until the next row or the
+/// roll-up takes the slot away (Kind.close). Its kind does the work it
+/// does for its own pane (an image decoded on a worker; a draw of a row
+/// passed by dropped, Kind.Slot.drawn_from), and nothing more: what it
+/// says, looks at or runs is not done while it previews (Kind.Call.end).
+/// Until its picture is drawn, the line naming it (draw.zig); one its kind
+/// refuses is that line as text, saying why.
+fn showKind(p: *Pardes, pk: *Pick, id: usize, k: u8, path: []const u8, bytes: []const u8) void {
+ const pane = p.panes[id].?;
+ const slot = Kind.newSlot(p, k, path) catch |err| return p.reportError(.at(id), "pick", err);
+ slot.size = bytes.len;
+ pane.addon = slot;
+ pk.previewed = true;
+ if (!Kind.reopen(p, id, slot, bytes) and slot.refused.len > 0) {
+ const line = nameLine(p.gpa, path, slot.nameOf(), bytes.len, slot.refused.slice()) catch return Kind.close(p, pane);
+ Kind.close(p, pane);
+ return showText(p, pk, id, path, line);
+ }
+ p.layOut();
+}
+
+/// The one line a file shows while a picker previews it and none of its
+/// text is shown: its name, what it is (`binary`, a kind's name), its size
+/// and why when it says why: `photo.png · image · 1.2 MB`.
+pub fn nameLine(gpa: std.mem.Allocator, path: []const u8, what: []const u8, size: u64, why: []const u8) ![]u8 {
+ var out: std.Io.Writer.Allocating = .init(gpa);
+ errdefer out.deinit();
+ const w = &out.writer;
+ try w.print("{s} · {s} · ", .{ std.Io.Dir.path.basename(path), what });
+ if (size < 1000) try w.print("{d} B", .{size}) else {
+ const units = [_][]const u8{ "kB", "MB", "GB", "TB", "PB", "EB" };
+ var unit: u64 = 1000;
+ var u: usize = 0;
+ while (size / unit >= 1000 and u + 1 < units.len) : (u += 1) unit *= 1000;
+ const tenths = size / (unit / 10);
+ try w.print("{d}.{d} {s}", .{ tenths / 10, tenths % 10, units[u] });
+ }
+ if (why.len > 0) try w.print(" · {s}", .{why});
+ return out.toOwnedSlice();
}
/// The text of `path` as an open pane has it, copied: no read for it.
@@ -1019,6 +1157,9 @@ fn restore(p: *Pardes, pk: *Pick) void {
const id = p.paneBySerial(pk.landing) orelse return;
for (p.panes) |slot| if (slot) |tp| if (tp.places.from == pk.id) tp.places.clear(p.gpa);
if (pk.made) {
+ // A kind's file shown: its slot closed first, as a pane's text
+ // closing is no file closed (no Recent row).
+ if (p.panes[id].?.addon != null) Kind.close(p, p.panes[id].?);
pk.made = false;
p.removePane(id, p.paneBySerial(pk.owner)) catch |err| p.reportError(.at(id), "pick", err);
return;
@@ -1030,6 +1171,7 @@ fn restore(p: *Pardes, pk: *Pick) void {
fn putBack(p: *Pardes, pk: *Pick) void {
const id = p.paneBySerial(pk.landing) orelse return;
const pane = p.panes[id].?;
+ if (pane.addon != null) Kind.close(p, pane);
if (pk.made) return;
const own = pk.aside orelse {
// Its own file previewed: its caret and top as they were.
@@ -1045,7 +1187,7 @@ fn putBack(p: *Pardes, pk: *Pick) void {
pane.body.cur_row = pk.aside_row;
pane.body.cur_col = pk.aside_col;
pane.body.vsel.active = false;
- p.sync();
+ p.layOut();
}
/// The live picker rolled up (Esc, or the tag put to rest by anything):
@@ -1415,6 +1557,7 @@ fn refine(p: *Pardes, pk: *Pick, drop: bool) void {
if (drop and (if (pk.marks.items.len > 0) marked(pk, h.cand) != null else h.cand == current)) continue;
const c = pk.names.cands.items[h.cand];
next.add(p.gpa, pk.names.bytes.items[c.start..][0..c.len], c.key, c.key_len, c.base, c.ref) catch break;
+ next.cands.items[next.cands.items.len - 1].group = c.group;
}
} else {
var arena = std.heap.ArenaAllocator.init(p.gpa);
@@ -1514,7 +1657,7 @@ fn keep(p: *Pardes, pk: *Pick) void {
const row = rowAt(p, pk, arena.allocator(), i) catch break;
switch (row.target) {
.place => |t| if (pk.source == .symbols)
- out.writer.print("{s}:{d} {s}\n", .{ std.Io.Dir.path.basename(t.path), t.at.line, std.mem.trimStart(u8, row.text, " 0123456789") }) catch break
+ out.writer.print("{s}:{d} {s}\n", .{ std.Io.Dir.path.basename(t.path), t.at.line, row.text }) catch break
else
out.writer.print("{s}\n", .{row.text}) catch break,
else => out.writer.print("{s}\n", .{row.text}) catch break,
@@ -1999,6 +2142,9 @@ pub fn execWord(p: *Pardes, txt: []const u8) bool {
}
fn testFile(p: *Pardes, tmp: *std.testing.TmpDir, name: []const u8, text: []const u8) ![]u8 {
+ // The directory a work tree of its own, as a project is: Find and Grep
+ // search it, not the tree the test runs in.
+ tmp.dir.createDir(std.testing.io, ".git", .default_dir) catch |err| if (err != error.PathAlreadyExists) return err;
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = text });
var base_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;
const dir = base_buf[0..try tmp.dir.realPath(std.testing.io, &base_buf)];
@@ -3283,3 +3429,275 @@ test "Ctrl-r in a picker unrolls its source's earlier queries (UX L2's last line
p.update(.{ .key = .{ .cp = Key.escape } });
p.update(.{ .key = .{ .cp = Key.escape } });
}
+
+/// A Symbols picker opened from a file pane whose path is `name` and text
+/// `text`, its symbols parsed (small: here and now), and the pane.
+fn openSymbols(p: *Pardes, name: []const u8, text: []const u8) !*Pane {
+ const pane = try p.setTestFile(text);
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try p.gpa.dupe(u8, name);
+ open(p, p.view().active, .symbols, "", "", "");
+ settle(p);
+ return pane;
+}
+
+/// The live picker's rows, `meta text` a line each.
+fn rowLines(p: *Pardes, a: std.mem.Allocator) ![]const u8 {
+ const pk = live(p).?;
+ var out: std.ArrayList(u8) = .empty;
+ for (0..count(p, pk)) |i| {
+ const r = try rowAt(p, pk, a, i);
+ try out.print(a, "{s: >2} {s}\n", .{ r.meta, r.text });
+ }
+ return out.items;
+}
+
+const counts_zig =
+ \\const std = @import("std");
+ \\pub const Counts = struct {
+ \\ lines: usize = 0,
+ \\ words: usize = 0,
+ \\ pub const zero: Counts = .{};
+ \\ pub fn add(c: *Counts, text: []const u8) void {
+ \\ const local = text.len;
+ \\ c.lines += local;
+ \\ }
+ \\};
+ \\const Mode = enum { fast, slow };
+ \\var hits: u32 = 0;
+ \\pub fn count(text: []const u8) Counts {
+ \\ return .{ .lines = text.len };
+ \\}
+ \\test "count.add" {}
+ \\
+;
+
+test "Symbols (UX DESIGN N): a Zig file's rows types, functions, fields, then the rest, each in the text's order with the field empty; a row its kind's mark, its name qualified, what its first line says after it, its line the meta; the mark in the keyword's ink, the qualifier and the rest dim" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ _ = try openSymbols(p, "/w6/counts.zig", counts_zig);
+ try std.testing.expectEqualStrings(
+ \\ 2 t Counts = struct
+ \\11 t Mode = enum { fast, slow }
+ \\ 6 f Counts.add (c: *Counts, text: []const u8) void
+ \\13 f count (text: []const u8) Counts
+ \\ 3 m Counts.lines : usize = 0
+ \\ 4 m Counts.words : usize = 0
+ \\11 m Mode.fast
+ \\11 m Mode.slow
+ \\ 1 n std = @import("std")
+ \\ 5 c Counts.zero : Counts = .{}
+ \\12 v hits : u32 = 0
+ \\16 · "count.add"
+ \\
+ , try rowLines(p, a));
+ // The qualifier dim, `Counts.`; a name holding a `.` none of it.
+ try std.testing.expectEqual(@as(u16, "Counts.".len), (try rowAt(p, live(p).?, a, 4)).faint);
+ try std.testing.expectEqual(@as(u16, 0), (try rowAt(p, live(p).?, a, 11)).faint);
+ // Drawn: `m Counts.lines : usize = 0` (not the cursor's row).
+ const pane = p.panes[p.paneBySerial(live(p).?.landing).?].?;
+ _ = try p.render(a);
+ const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
+ const roles = &p.chromeTheme().roles;
+ const inks = roles.on(if (Trail.reading(p, pane)) .reading_focused else .focused);
+ var found = false;
+ for (0..layer.rows) |y| {
+ const cells = layer.cells[y * layer.cols ..][0..layer.cols];
+ var text: std.ArrayList(u8) = .empty;
+ var at: std.ArrayList(usize) = .empty;
+ for (cells, 0..) |c, x| {
+ try at.append(a, text.items.len);
+ try text.appendSlice(a, c.grapheme());
+ _ = x;
+ }
+ const from = std.mem.indexOf(u8, text.items, "m Counts.lines") orelse continue;
+ var x: usize = 0;
+ while (at.items[x] < from) x += 1;
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chrome().on(.focus).kind }, cells[x].style.fg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cells[x + 2].style.fg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = inks.text }, cells[x + 9].style.fg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cells[x + 16].style.fg);
+ // Its line at the row's right end, dim.
+ const three = std.mem.lastIndexOfScalar(u8, text.items, '3').?;
+ var m: usize = 0;
+ while (at.items[m] < three) m += 1;
+ try std.testing.expect(m > x + 30);
+ try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cells[m].style.fg);
+ found = true;
+ }
+ try std.testing.expect(found);
+}
+
+test "Symbols (UX DESIGN N3): typed, the rows stay grouped, scored within each group, and the cursor starts on the best match wherever its group puts it; the name alone is matched, never the signature" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const pane = try openSymbols(p, "/w6/counts.zig", counts_zig);
+ for ("count") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ settle(p);
+ const rows = try rowLines(p, a);
+ try std.testing.expect(std.mem.startsWith(u8, rows,
+ \\ 2 t Counts = struct
+ \\13 f count (text: []const u8) Counts
+ \\ 6 f Counts.add (c: *Counts, text: []const u8) void
+ \\ 3 m Counts.lines : usize = 0
+ \\ 4 m Counts.words : usize = 0
+ \\
+ ));
+ // `count` matched best: the cursor on it, not on the first row, and
+ // the count says where it is.
+ const s = &p.view().tag_state;
+ try std.testing.expectEqual(@as(u16, 1), s.rows.at);
+ const h = (try head(p, a, p.panes[p.paneBySerial(live(p).?.landing).?].?)).?;
+ try std.testing.expect(std.mem.indexOf(u8, h.text, "2/7") != null);
+ // Enter lands on its line.
+ _ = pane;
+ // `u8` is in signatures only: nothing matches.
+ for (0..5) |_| p.update(.{ .key = .{ .cp = pardes.Key.backspace } });
+ for ("u8") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?));
+}
+
+test "Symbols (UX DESIGN N): a C++ file's rows by its kind table, members named in their class and namespace, a function's locals none" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ _ = try openSymbols(p, "/w6/parser.cc",
+ \\#define LIMIT 4
+ \\namespace torque {
+ \\class Parser : public Base {
+ \\ public:
+ \\ Parser();
+ \\ int Parse(int depth) const { return depth; }
+ \\ int depth_;
+ \\};
+ \\enum class Kind { kA, kB };
+ \\int Parser::Run(int n) { int local = n; return local; }
+ \\static int counter = 0;
+ \\const int limit = 4;
+ \\using Alias = int;
+ \\}
+ \\
+ );
+ try std.testing.expectEqualStrings(
+ \\ 3 t torque.Parser : public Base
+ \\ 9 t torque.Kind
+ \\13 t torque.Alias = int
+ \\ 5 f torque.Parser.Parser ()
+ \\ 6 f torque.Parser.Parse (int depth) const
+ \\10 f torque.Parser::Run (int n)
+ \\ 7 m torque.Parser.depth_
+ \\ 9 m torque.Kind.kA
+ \\ 9 m torque.Kind.kB
+ \\ 1 · LIMIT 4
+ \\ 2 n torque
+ \\11 v torque.counter = 0
+ \\12 c torque.limit = 4
+ \\
+ , try rowLines(p, frame.allocator()));
+}
+
+test "Symbols: every row is ordinary text: no header rows, the cursor steps onto each in turn, the band shows each row's text, and C-q keeps them in a +Search with the mark a word" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ _ = try openSymbols(p, "/w6/counts.zig", counts_zig);
+ const pk = live(p).?;
+ const n = count(p, pk);
+ try std.testing.expectEqual(@as(usize, 12), n);
+ const s = &p.view().tag_state;
+ for (0..n) |i| {
+ try std.testing.expectEqual(@as(u16, @intCast(i)), s.rows.at);
+ const r = try rowAt(p, pk, a, i);
+ const host = p.paneBySerial(pk.landing).?;
+ const band = (try Band.of(p, a, p.panes[host].?, host)).?;
+ var shown = false;
+ for (0..band.height) |y| {
+ const ln = try band.line(a, p.settings.tab, @intCast(y));
+ shown = shown or std.mem.indexOf(u8, ln.text, r.text) != null;
+ }
+ try std.testing.expect(shown);
+ p.update(.{ .key = .{ .cp = pardes.Key.down } });
+ }
+ p.update(.{ .key = .{ .cp = 'q', .ctrl = true } });
+ var kept: ?[]const u8 = null;
+ for (p.panes) |slot| if (slot) |tp| if (tp.file) |f| if (std.mem.startsWith(u8, f.content, "Symbols ")) {
+ kept = f.content;
+ };
+ try std.testing.expect(std.mem.indexOf(u8, kept.?, "\ncounts.zig:3 m Counts.lines : usize = 0\n") != null);
+ try std.testing.expect(std.mem.indexOf(u8, kept.?, "\ncounts.zig:2 t Counts = struct\n") != null);
+}
+
+test "Find and Grep search the work tree (W8): from a pane deep in a repo Find lists the files from its root and `sub/name` narrows it, a leading directory narrows Grep, and outside a repo they search the pane's directory" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ p.stream.engine = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ for ([_][]const u8{ "src/deep", "sub", "other" }) |d| try tmp.dir.createDirPath(std.testing.io, d);
+ const deep = try testFile(p, &tmp, "src/deep/x.txt", "deep\n");
+ defer p.gpa.free(deep);
+ for ([_][2][]const u8{ .{ "sub/name.txt", "needle one\n" }, .{ "other/name.txt", "needle two\n" } }) |f| p.gpa.free(try testFile(p, &tmp, f[0], f[1]));
+ const root = std.Io.Dir.path.dirname(std.Io.Dir.path.dirname(std.Io.Dir.path.dirname(deep).?).?).?;
+ _ = try p.setTestFile("held\n");
+ const asker = p.view().active;
+ Trail.keep(p.panes[asker].?);
+ p.gpa.free(p.panes[asker].?.file.?.path);
+ p.panes[asker].?.file.?.path = try p.gpa.dupe(u8, deep);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ // Find from src/deep: the root's files, by their paths from it.
+ open(p, asker, .find, "", "", "");
+ var pk = live(p).?;
+ try std.testing.expectEqualStrings(root, pk.dir.slice());
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 3), count(p, pk));
+ for ("sub/name") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 1), count(p, pk));
+ try std.testing.expectEqualStrings("sub/name.txt", (try rowAt(p, pk, a, 0)).text);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // Grep: the whole tree, then `sub needle` in sub/ alone, its row's
+ // path from the root, landing on the file there.
+ open(p, asker, .grep, "", "", "");
+ pk = live(p).?;
+ for ("needle") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ // (Its typing paused: the search starts.)
+ p.clock.now_ns = p.stream.due_ns.?;
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 2), count(p, pk));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ open(p, asker, .grep, "", "", "");
+ pk = live(p).?;
+ for ("sub needle") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ // (Its typing paused: the search starts.)
+ p.clock.now_ns = p.stream.due_ns.?;
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 1), count(p, pk));
+ const row = try rowAt(p, pk, a, 0);
+ try std.testing.expect(std.mem.startsWith(u8, row.text, "sub/name.txt:1 needle one"));
+ try std.testing.expectEqualStrings(try std.Io.Dir.path.join(a, &.{ root, "sub/name.txt" }), row.target.place.path);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // Outside a repo (`/`, the test text's directory, holds no .jj nor
+ // .git): the pane's directory, as before.
+ p.gpa.free(p.panes[asker].?.file.?.path);
+ p.panes[asker].?.file.?.path = try p.gpa.dupe(u8, "/held.txt");
+ open(p, asker, .find, "", "", "");
+ try std.testing.expectEqualStrings("/", live(p).?.dir.slice());
+ p.update(.{ .key = .{ .cp = Key.escape } });
+}
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/Query.zig b/core/Query.zig
index f3673dd6..f9651faf 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -530,8 +530,9 @@ fn makeNameRows(p: *Pardes, id: usize) !void {
f.pager_spans = spans.toOwnedSlice(p.gpa) catch &.{};
q.total = q.names.hits.items.len;
q.more = q.names.busy() or p.stream.busyFor(rp.serial);
- // The best is current until a step or a click moves it.
- q.current = if (shown > 0) 0 else null;
+ // The best is current until a step or a click moves it: in a grouped
+ // list (Symbols) wherever its group puts it.
+ q.current = if (shown > 0) @min(q.names.bestRow(), shown - 1) else null;
countCurrent(q);
showCurrent(p.settings.tab, rp);
if (q.current == null) blankPreview(p, id) else showTarget(p, id);
@@ -771,23 +772,54 @@ pub fn gather(p: *Pardes, names: *Names, source: Source, dir: []const u8, self:
const oid = owner_id orelse return;
const owner = p.panes[oid].?;
const f = if (owner.file) |*file| file else return;
- const decls = ownerDecls(f) orelse {
+ if (f.context.revision != f.revision) {
// Parsed on the worker; listed when it is done (declsArrived).
Stream.parseFor(p, oid);
return;
- };
- for (decls) |d| {
- const header = f.content[d.start_byte..@min(d.header_end_byte, f.content.len)];
- const first = std.mem.trim(u8, header[0 .. std.mem.indexOfScalar(u8, header, '\n') orelse header.len], " \t\r");
- var buf: [256 + 16]u8 = undefined;
- const row = std.fmt.bufPrint(&buf, "{d: >6} {s}", .{ d.start_line + 1, first[0..@min(first.len, 240)] }) catch continue;
- names.add(gpa, row, 8, row.len - 8, 0, @intCast(d.start_line + 1)) catch break;
}
+ // The file's text, which was parsed (the `Changes` layer's lines
+ // are none of it).
+ const text = File.fileText(f, p.scratch.allocator()) catch return;
+ const symbols = f.context.symbols;
+ // A row a symbol, ` 12 m Counts.lines : usize = 0`: its
+ // line, its mark, its name qualified by the ones it is in, then
+ // what its first line says after the name; types, functions,
+ // fields, then the rest, each in the text's order (UX DESIGN N).
+ // The qualified name alone is matched, its own name the
+ // basename.
+ for (0..4) |group| for (symbols) |sym| {
+ if (sym.kind.group() != group or sym.kind == .scope or sym.end > text.len) continue;
+ var buf: [512]u8 = undefined;
+ var row: std.Io.Writer = .fixed(&buf);
+ row.print("{d: >6} {s} ", .{ sym.line + 1, sym.kind.mark() }) catch continue;
+ const key_at = row.end;
+ qualify(&row, symbols, text, sym.parent, 4) catch continue;
+ // The name its basename: the qualifier dim (Pick.rowAt).
+ const base = row.end - key_at;
+ row.writeAll(text[sym.name_start..sym.name_end]) catch continue;
+ const key_len = row.end - key_at;
+ const rest = text[sym.name_end..@max(sym.name_end, sym.end)];
+ var detail = std.mem.trim(u8, rest[0 .. std.mem.indexOfScalar(u8, rest, '\n') orelse rest.len], " \t\r");
+ detail = std.mem.trimEnd(u8, std.mem.trimEnd(u8, detail, "{,;"), " \t");
+ if (detail.len > 0) row.print(" {s}", .{detail[0..@min(detail.len, buf.len - row.end -| 2)]}) catch {};
+ names.add(gpa, row.buffered(), key_at, key_len, @intCast(base), sym.line + 1) catch break;
+ names.cands.items[names.cands.items.len - 1].group = @intCast(group);
+ };
},
else => {},
}
}
+/// The names of the symbols `parent` (an index + 1) is in, outermost
+/// first, each with its `.`: `Outer.Inner.` (the `depth` innermost).
+fn qualify(w: *std.Io.Writer, symbols: []const syntax.Symbol, text: []const u8, parent: u32, depth: u8) std.Io.Writer.Error!void {
+ if (parent == 0 or parent > symbols.len or depth == 0) return;
+ const up = symbols[parent - 1];
+ if (up.name_end > text.len) return;
+ try qualify(w, symbols, text, up.parent, depth - 1);
+ try w.print("{s}.", .{text[up.name_start..up.name_end]});
+}
+
/// What a Panes row of a closed pane ends with.
const closed_word = " (closed)";
@@ -1269,7 +1301,7 @@ fn countGrepCurrent(q: *Query) void {
/// picker (Pick.zig: the same fields): a Grep's lines (`path:line:col-end
/// code`, relative to the pane's directory) kept as found, a listing's
/// names added to what Find scores.
-pub fn take(p: *Pardes, q: anytype, kind: Stream.Kind, rows: []const u8) void {
+pub fn take(p: *Pardes, q: anytype, kind: Stream.Kind, rows: []const u8, under: []const u8) void {
var lines = std.mem.splitScalar(u8, rows, '\n');
while (lines.next()) |ln| {
if (ln.len == 0) continue;
@@ -1286,13 +1318,14 @@ pub fn take(p: *Pardes, q: anytype, kind: Stream.Kind, rows: []const u8) void {
const name = if (ln[0] == '"') look.unquoted(&namebuf, t.path) else t.path;
const found: Found = .{
.path = std.math.cast(u32, q.found_bytes.items.len) orelse return,
- .path_len = std.math.cast(u16, name.len) orelse continue,
+ .path_len = std.math.cast(u16, under.len + name.len) orelse continue,
.line = std.math.cast(u32, t.at.line) orelse continue,
.col = std.math.cast(u32, t.at.col -| 1) orelse continue,
.end = std.math.cast(u32, if (t.at.end_col > 0) t.at.end_col else t.at.col) orelse continue,
- .code = std.math.cast(u32, q.found_bytes.items.len + name.len) orelse return,
+ .code = std.math.cast(u32, q.found_bytes.items.len + under.len + name.len) orelse return,
.code_len = std.math.cast(u32, code.len) orelse continue,
};
+ q.found_bytes.appendSlice(p.gpa, under) catch return;
q.found_bytes.appendSlice(p.gpa, name) catch return;
q.found_bytes.appendSlice(p.gpa, code) catch return;
q.found.append(p.gpa, found) catch return;
@@ -1703,7 +1736,7 @@ fn displayPreview(p: *Pardes, qid: usize, path: []const u8, at: look.Spot) void
pane.hscroll = 0;
// another file: its own places, found below
pane.places.clear(p.gpa);
- p.sync();
+ p.layOut();
}
look.clearNavigationSelection(p, pane);
if (at.line == 0 or at.line > File.nlines(p.gpa, f)) {
@@ -2808,7 +2841,7 @@ test "Grep: a row whose numbers a Found cannot hold (a column past u32) is passe
defer p.deinit();
var q: Query = .{ .owner = 0 };
defer q.deinit(p.gpa);
- take(p, &q, .grep, "a:5000000000:b:3:1-4 hit\nok.txt:2:3-5 hit\nb:7:4294967297 hit\n");
+ take(p, &q, .grep, "a:5000000000:b:3:1-4 hit\nok.txt:2:3-5 hit\nb:7:4294967297 hit\n", "");
// Taken or passed over, each: never cast (main: Query.zig:1267).
try std.testing.expect(q.found.items.len <= 3);
}
diff --git a/core/Store.zig b/core/Store.zig
index 1328af38..8a1c3987 100644
--- a/core/Store.zig
+++ b/core/Store.zig
@@ -223,7 +223,7 @@ pub fn reopen(s: *Store, p: *Pardes, serial: u32, from: usize) bool {
};
p.view().active = free;
if (layout.findPane(p, free)) |f| p.setActiveColumn(f.col);
- p.sync();
+ p.layOut();
return true;
}
diff --git a/core/Stream.zig b/core/Stream.zig
index e9e7793b..4691e192 100644
--- a/core/Stream.zig
+++ b/core/Stream.zig
@@ -67,10 +67,11 @@ pub const Batch = struct {
end: ?End = null,
/// A parse's own time on the worker (`parse_ns`).
took_ns: u64 = 0,
- /// A parse's answer (`parseFor`): the declarations of pane `serial`'s
- /// text at `revision`.
+ /// A parse's answer (`parseFor`): the declarations and symbols of pane
+ /// `serial`'s text at `revision`.
parsed: ?struct { serial: u32, revision: u32 } = null,
decls: []syntax.ContextDeclaration = &.{},
+ symbols: []syntax.Symbol = &.{},
/// A paint's answer (`paintAhead`): the colours of pane `serial`'s text
/// at `revision` from byte `start`, one syntax.Syn a byte.
painted: ?struct { serial: u32, revision: u32, start: usize } = null,
@@ -83,6 +84,7 @@ pub const Batch = struct {
pub fn deinit(b: *const Batch, gpa: std.mem.Allocator) void {
gpa.free(b.rows);
gpa.free(b.decls);
+ gpa.free(b.symbols);
gpa.free(b.styles);
}
};
@@ -480,9 +482,9 @@ pub fn parseFor(p: *Pardes, id: usize) void {
fn parseWork(io: std.Io, job: *TextJob, ctx: ?*anyopaque, sink: Sink) void {
const began = std.Io.Clock.awake.now(io);
- const decls: []syntax.ContextDeclaration = syntax.declarationsApart(job.out, job.path, job.source, &job.stop) catch @constCast(&[_]syntax.ContextDeclaration{});
+ const made: syntax.Context = syntax.contextApart(job.out, job.path, job.source, &job.stop) catch .{};
const took: u64 = @intCast(@max(0, began.durationTo(std.Io.Clock.awake.now(io)).nanoseconds));
- _ = sink(ctx, .{ .gen = job.gen, .decls = decls, .parsed = .{ .serial = job.serial, .revision = job.revision }, .end = .done, .took_ns = took });
+ _ = sink(ctx, .{ .gen = job.gen, .decls = made.declarations, .symbols = made.symbols, .parsed = .{ .serial = job.serial, .revision = job.revision }, .end = .done, .took_ns = took });
}
fn now() u64 {
@@ -717,7 +719,7 @@ pub fn receive(p: *Pardes, b: *const Batch) void {
const id = p.paneBySerial(s.target) orelse return;
const q = p.panes[id].?.query orelse return;
q.capped = s.state == .capped;
- panes.Query.take(p, q, s.kind, b.rows);
+ panes.Query.take(p, q, s.kind, b.rows, "");
}
/// A parse's answer: its task joined; the declarations kept as the pane's
@@ -732,12 +734,15 @@ fn receiveParse(p: *Pardes, b: *const Batch, serial: u32, revision: u32) void {
t.job.deinit();
};
s.parse_ns = b.took_ns;
- if (p.paneBySerial(serial)) |id| if (p.panes[id].?.file) |*f| if (f.revision == revision and b.decls.len > 0) {
- if (p.tree_sitter_gpa.dupe(syntax.ContextDeclaration, b.decls)) |copy| {
- f.context.replace(p.tree_sitter_gpa, copy, revision);
- panes.Query.declsArrived(p, serial);
- panes.Pick.declsArrived(p, serial);
- } else |_| {}
+ if (p.paneBySerial(serial)) |id| if (p.panes[id].?.file) |*f| if (f.revision == revision and (b.decls.len > 0 or b.symbols.len > 0)) kept: {
+ const decls = p.tree_sitter_gpa.dupe(syntax.ContextDeclaration, b.decls) catch break :kept;
+ const symbols = p.tree_sitter_gpa.dupe(syntax.Symbol, b.symbols) catch {
+ p.tree_sitter_gpa.free(decls);
+ break :kept;
+ };
+ f.context.replace(p.tree_sitter_gpa, .{ .declarations = decls, .symbols = symbols }, revision);
+ panes.Query.declsArrived(p, serial);
+ panes.Pick.declsArrived(p, serial);
};
p.needs_frame = true;
// A `Churn` waiting on these declarations (jj.zig).
@@ -1452,7 +1457,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/Term.zig b/core/Term.zig
index d4baf4e8..509da6d9 100644
--- a/core/Term.zig
+++ b/core/Term.zig
@@ -422,7 +422,7 @@ pub const calls = [_]struct { []const u8, []const u8, []const u8 }{
.{ "endOutputHere", "ninep/pty.zig:1", "WRITE: a 9P pty/run's step ends a command's output at the cursor: the session's step, replayed as such" },
.{ "replies", "Core.zig:1", "WRITE: a step drains the reply buffer (in the digest), counted when it held any (the feed's own unit, which filled it); only the session writes it to the pty (pty_write is off the tape)" },
// ---- reads by a step: in the digest ----
- .{ "grid", "Core.zig:2 ansi.zig:3 body_layer.zig:3 draw.zig:2 dump.zig:4 echo.zig:8 exec.zig:2 layout.zig:2 panes.zig:6 replica.zig:2", "READ: the size, the history's length, the cursor: in the digest (a view's place is its pane's; ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" },
+ .{ "grid", "Core.zig:3 ansi.zig:3 body_layer.zig:3 draw.zig:2 dump.zig:4 echo.zig:8 exec.zig:2 layout.zig:2 panes.zig:6 replica.zig:2", "READ: the size, the history's length, the cursor: in the digest (a view's place is its pane's; ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" },
.{ "modes", "Core.zig:5 draw.zig:1 dump.zig:2 echo.zig:3 exec.zig:3 mouse.zig:4 ninep/pty.zig:3 panes.zig:2 replica.zig:1", "READ: the program's modes (mouse, focus, bracketed paste, the alternate screen): in the digest (draw.zig, echo.zig: a draw's; panes.zig: a view scrolls no history on the alternate screen)" },
.{ "prompt", "Core.zig:1 builtins.zig:1 echo.zig:1 exec.zig:3 ninep/pty.zig:1 panes.zig:1", "READ: the OSC 133 cycle: in the digest (`marksOf`); Core.zig's and ninep/pty.zig's also taped (`.prompt`, each side's compared)" },
.{ "promptPrefix", "body_layer.zig:1 edit.zig:1 exec.zig:1", "READ: a row's prompt cells (`promptCut`): the active area's in the digest; a history row's text is not (below)" },
diff --git a/core/Trail.zig b/core/Trail.zig
index cd8eb924..e42ab1e2 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -250,7 +250,9 @@ fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
.opened => |free| free,
.shown, .none => return p.view().active,
};
- if (at.line > panes.File.nlines(p.gpa, &p.panes[free].?.file.?)) {
+ // (A kind's pane, look.open's for a file a kind takes, has no lines.)
+ const nf = if (p.panes[free].?.file) |*f| f else return free;
+ if (at.line > panes.File.nlines(p.gpa, nf)) {
try p.removePane(free, null);
p.view().active = id;
return error.LineMissing;
@@ -712,7 +714,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.
@@ -764,7 +766,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";
@@ -867,7 +869,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);
@@ -944,7 +946,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 829935c7..176cabe0 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/colors.zig b/core/colors.zig
index 98b3b184..6c83f5c8 100644
--- a/core/colors.zig
+++ b/core/colors.zig
@@ -588,8 +588,10 @@ pub const Chrome = struct {
/// user's, a path, `Keep`), word (computed command words: the text
/// toward the ground to 4.5:1, H), dim (hints, meta, forward steps),
/// rule (spines), key (the accent: keys, `▶`, the walked word), match
- /// (a query's letters), the four severities, and a selection rebuilt
- /// on it with its own.
+ /// (a query's letters), kind (a symbol's kind mark in a list, `t`,
+ /// `f`: the keyword's hue, which spells a kind in the text, held on the
+ /// ground and on its selection, a list's cursor row), the four
+ /// severities, and a selection rebuilt on it with its own.
pub const Inks = struct {
ground: [3]u8,
text: [3]u8,
@@ -598,6 +600,7 @@ pub const Chrome = struct {
rule: [3]u8,
key: [3]u8,
match: [3]u8,
+ kind: [3]u8,
severity: [4][3]u8,
selection: Selection,
};
@@ -986,6 +989,7 @@ fn groundInks(th: *const Theme, ground: [3]u8, text: [3]u8, sel: [3]u8, sel_text
.rule = line.toward(Chrome.rule_ink),
.key = hold(th.accent, &.{ground}, Chrome.text_floor),
.match = hold(hue, &.{ground}, Chrome.text_floor),
+ .kind = hold(th.keyword, &.{ ground, sel }, Chrome.text_floor),
.severity = severity,
.selection = .{
.ground = sel,
@@ -2716,6 +2720,13 @@ fn ringFailures(th: *const Theme, c: *const Chrome, designed_here: bool) std.Enu
const t = contrast(g.text, g.ground);
var low = (n > 0 and t < @min(4.5, reach(g.ground))) or contrast(g.dim, g.ground) < @min(3, t) - 0.01;
for ([2][3]u8{ g.key, g.match } ++ g.severity) |i| low = low or contrast(i, g.ground) < @min(4.5, reach(g.ground));
+ // The kind mark on the ground and on its selection, a list's
+ // cursor row: one ink for both, 4.5:1 where the keyword's hue
+ // reaches it there (held to the end of light, a hue keeps a trace
+ // of itself: #000100 on solarized_dark's grey tag reads 4.49).
+ const both = [2][3]u8{ g.ground, g.selection.ground };
+ const most = leastContrast(hold(th.keyword, &both, 21), &both);
+ low = low or leastContrast(g.kind, &both) < @min(4.5, most) - 0.01;
low = low or contrast(g.selection.text, g.selection.ground) < @min(4.5, reach(g.selection.ground));
if (low) f.insert(.inks);
}
diff --git a/core/config.zig b/core/config.zig
index dc1d98dc..d500cdcb 100644
--- a/core/config.zig
+++ b/core/config.zig
@@ -239,8 +239,20 @@ pub const child_term = "xterm-256color";
pub const child_colorterm = "truecolor";
pub const child_term_program = "pardes";
-// Fonts is the window's word alone (the font picker), so a terminal build's
-// row has no such builtin to name: the window's row and the terminal's.
+/// The window row's words (UX K'2): at its right end, `Restore <dump>`
+/// after them once a dump exists (tagline.headerWords). The rest of the
+/// words that left it run from `:`, their keys and typed (K'4).
+pub const window_words_str = "Find Grep Newcol Help Exit";
+/// A column's words: at the window row's left while there is one column,
+/// in its column tag with several, where Joincol and Delcol have a
+/// column to act on.
+pub const column_words_str = "New Term";
+pub const columns_words_str = "New Term Joincol Delcol";
+
+// The window's tag before UX K', its own text then: a dump's own text equal
+// to one is dropped (dump.dropOldTags), and /tagexec still takes their words
+// (ninep/cols.zig paneWord). Fonts is the window's word alone (the font
+// picker), so a terminal build's row has no such builtin to name.
pub const topbar_window_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Fonts Config History Debug Exit";
pub const topbar_terminal_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit";
pub const topbar_str = if (@import("builtins.zig").capabilities.font_picker) topbar_window_str else topbar_terminal_str;
@@ -1564,13 +1576,16 @@ const doc_typ = struct {
if (w.end > 0) w.writeByte(' ') catch return false;
w.writeAll(x[0 .. std.mem.indexOfScalar(u8, x, '+') orelse x.len]) catch return false;
}
- // Both rows: the docs and the tutor show the window's and the terminal's.
- const tags = [_][]const u8{ topbar_window_str, topbar_terminal_str, @import("tagline.zig").column_tag_default, pane_builtins_str, file_pane_builtins_str, diff_pane_builtins_str, pager_pane_builtins_str, pager_diff_pane_builtins_str, diff_view_builtins_str, terminal_pane_builtins_str, command_pane_builtins_str, dir_pane_builtins_str };
+ // The window row's and the column tags' words (UX K'2), and K'3's
+ // computed words of a pane at rest: a file reading, held, edited,
+ // a +New typed into, a running command, a directory, a pager, a
+ // terminal with its shell's word.
+ const tags = [_][]const u8{ window_words_str, column_words_str, columns_words_str, "Keep Del", "Del", "Save Undo Del", "Undo Del", "Kill Del", "Get Del", "Filter Del", "Del Term" };
for (tags) |d| if (std.mem.eql(u8, d, w.buffered())) return true;
- // A kind's pane's: Term, its addon's words, Collapse Del (Kind.zig).
+ // A kind's pane's: its addon's words, then Del (Kind.zig).
const shown = w.buffered();
- if (!std.mem.startsWith(u8, shown, "Term ") or !std.mem.endsWith(u8, shown, " Collapse Del")) return false;
- var mid = std.mem.tokenizeScalar(u8, shown["Term ".len .. shown.len - " Collapse Del".len], ' ');
+ if (!std.mem.endsWith(u8, shown, " Del")) return false;
+ var mid = std.mem.tokenizeScalar(u8, shown[0 .. shown.len - " Del".len], ' ');
while (mid.next()) |x| {
if (!addonWord(x)) return false;
}
diff --git a/core/draw.zig b/core/draw.zig
index e90535b5..42396aa1 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -152,6 +152,12 @@ pub fn place(p: *Pardes, s: *Surface) void {
}
}
const column_rows = layout.columnBarHeight(p);
+ // A lone column's tag at the window row's left (UX K'2): no grip, a
+ // column's edge has nothing to be dragged against.
+ if (layout.columnInWindowRow(p)) {
+ const inset = @min(TAG_TEXT_INSET, v.screen_w);
+ s.addRegion(.{ .kind = .column_tag, .owner = 0, .serial = v.cols[0].serial, .active = layout.findPane(p, v.active) != null, .rect = .{ .x = inset, .y = 0, .w = tagline.windowRow(p).column, .h = p.topBarHeight() } });
+ }
if (column_rows > 0) for (0..p.view().ncol) |c| {
if (v.col_w[c] == 0) continue;
const active = if (layout.findPane(p, v.active)) |found| found.col == c else false;
@@ -538,7 +544,14 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
// painted out. Text gets the overlay; a kind's pane gives up the rows.
const shown = pane.notices.span();
const body_h = (r.h -| pane.tag_rows) -| shown;
- pardes.Kind.draw(p, s, arena, pane, id, tx, body_y + shown, tw, body_h);
+ // A picker's preview through a kind (Pick.showKind): its file named
+ // until its kind has drawn it.
+ if (!pardes.Kind.draw(p, s, arena, pane, id, tx, body_y + shown, tw, body_h) and body_h > 0 and pardes.Pick.previewing(p, id)) {
+ const k = pane.addon.?;
+ if (pardes.Pick.nameLine(arena, k.path, k.nameOf(), k.size, "")) |line| {
+ _ = s.print(tx, body_y + shown, tw, line, .{ .fg = if (th.fg) |c| .{ .rgb = c } else .default, .bg = pane_bg });
+ } else |_| {}
+ }
// The same one column as the real scrollbar below, running past
// the notice bands so the gutter has no notch in it; its thumb
// where this frame's paint said its window is in its whole (a
@@ -588,25 +601,31 @@ fn paintHeaders(p: *Pardes, s: *Surface) !void {
if (s.region(.workspace_tag, Region.none)) |region| {
const top = if (v.header != null and p.headerColumn() == null) v.header_top else 0;
const layer = &s.tag_layers[MAX_PANES + MAX_COLS];
- var viewport = region.rect;
- s.chrome.tagline_rows = @intCast(viewport.y + viewport.h);
- const inset = @min(TAG_TEXT_INSET, viewport.w);
- s.fill(viewport.x, viewport.y, inset, viewport.h, .{ .bg = .{ .rgb = chrome.tagline_bg }, .fg = .{ .rgb = chrome.tagline_fg }, .font_role = .tagline });
- viewport.x += inset;
- viewport.w -= inset;
- try renderHeaderLayer(p, layer, .workspace, 0, viewport, tagline.topbar(p), top, chrome.tagline_bg, chrome.tagline_fg);
+ s.chrome.tagline_rows = @intCast(region.rect.y + region.rect.h);
+ // The window row (UX K'2), on the tagline's ground end to end: a
+ // lone column's tag at its left (its region), in the row's inks;
+ // the window's at its right end (tagline.windowRow).
+ s.fill(region.rect.x, region.rect.y, region.rect.w, region.rect.h, .{ .bg = .{ .rgb = chrome.tagline_bg }, .fg = .{ .rgb = chrome.tagline_fg }, .font_role = .tagline });
+ if (s.region(.column_tag, 0)) |column| if (column.rect.y < region.rect.y + region.rect.h) {
+ const column_top = if (v.header != null and p.headerColumn() == 0) v.header_top else 0;
+ const column_layer = &s.tag_layers[MAX_PANES];
+ try renderHeaderLayer(p, column_layer, .column, 0, column.rect, tagline.columnTag(p, 0), column_top, chrome.tagline_bg, chrome.tagline_fg);
+ joinHeaderRows(s, column_layer, chrome.tagline_fg);
+ };
+ const words = tagline.windowRow(p).words;
+ const viewport: Rect = .{ .x = words, .y = region.rect.y, .w = region.rect.w -| words, .h = region.rect.h };
+ const text = tagline.topbar(p);
+ try renderHeaderLayer(p, layer, .workspace, 0, viewport, text, top, chrome.tagline_bg, chrome.tagline_fg);
// A server's progress (a message of no pane) at its first row's
// right end, where the row has room for it.
- if (layer.rows > 0 and top == 0) for (p.messages.live[0..p.messages.live_len]) |*said| {
- if (said.kind != .progress or said.pane != 0) continue;
+ if (layer.rows > 0 and top == 0) if (tagline.sessionProgress(p)) |said| {
var buf: [Messages.LoggedMessage.cap + 8]u8 = undefined;
- const text = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch break;
- const width = panes.File.displayWidth(p.settings.tab, text);
- const used = panes.File.displayWidth(p.settings.tab, modal.lineSlice(tagline.topbar(p), 0));
+ const shown = std.fmt.bufPrint(&buf, "{s} {s}", .{ Messages.Kind.progress.glyph(), said.words() }) catch "";
+ const width = panes.File.displayWidth(p.settings.tab, shown);
+ const used = panes.File.displayWidth(p.settings.tab, modal.lineSlice(text, 0));
const room = layout.tagCapacity(p, viewport.w);
var row: Surface = .{ .cols = layer.cols, .rows = 1, .cells = layer.cells[0..layer.cols], .tab = p.settings.tab };
- if (used + 2 + width < room) _ = row.print(@intCast(room - 1 - width), 0, @intCast(width), text, .{ .fg = .{ .rgb = Messages.ink(chrome, .progress) }, .bg = .{ .rgb = chrome.tagline_bg }, .font_role = .tagline });
- break;
+ if (used + 2 + width < room) _ = row.print(@intCast(room - 1 - width), 0, @intCast(width), shown, .{ .fg = .{ .rgb = Messages.ink(chrome, .progress) }, .bg = .{ .rgb = chrome.tagline_bg }, .font_role = .tagline });
};
joinHeaderRows(s, layer, chrome.tagline_fg);
}
@@ -926,6 +945,9 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
const ground = groundOf(p, pane, active);
const inks = chrome.roles.on(ground);
const selected = chrome.roles.selectedOn(ground);
+ // A symbol's kind mark (colors.Chrome.Inks.kind): held on this tag's
+ // ground and on its cursor row's selection.
+ const kind = p.chrome().on(if (active) .focus else .plain).kind;
const bg = inks.ground;
const fg = inks.text;
const storage = try arena.alloc(Cell, @as(usize, columns) * rows);
@@ -970,6 +992,7 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
if (b < part.row.chord) style.fg = .{ .rgb = chrome.roles.key };
if (b < part.row.pre) style.fg = .{ .rgb = if (active) chrome.tag_active_name_fg else chrome.tag_name_fg };
if (part.row.dim or (b >= part.row.pre and b < part.row.pre + part.row.faint) or (b >= part.row.quiet[0] and b < part.row.quiet[1])) style.fg = .{ .rgb = on.dim };
+ if (b < part.row.kind) style.fg = .{ .rgb = kind };
for (part.row.keys) |k| if (k == b) {
style.fg = .{ .rgb = chrome.roles.key };
style.bold = true;
diff --git a/core/dump.zig b/core/dump.zig
index 69eda35e..0cefa157 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -635,6 +635,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, &notes, &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);
@@ -657,6 +658,36 @@ 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).
+/// The window's and the columns' tags the same (UX K'2): the window row of
+/// either build, with its `Restore <path>` or without, and the column tag
+/// it had.
+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))) dropOwn(p, &pane.tag);
+ };
+ const window: []const u8 = p.global_tag.own orelse "";
+ for ([_][]const u8{ pardes.config.topbar_window_str, pardes.config.topbar_terminal_str }) |old| {
+ if (!std.mem.startsWith(u8, window, old)) continue;
+ if (window.len != old.len and !std.mem.startsWith(u8, window[old.len..], " Restore ")) continue;
+ dropOwn(p, &p.global_tag);
+ break;
+ }
+ for (&p.views) |*slot| if (slot.*) |*v| for (v.col_tags[0..v.ncol]) |*t| {
+ if (t.own) |own| if (std.mem.eql(u8, own, pardes.tagline.column_tag_default)) dropOwn(p, t);
+ };
+}
+
+fn dropOwn(p: *Pardes, t: *pardes.panes.Text) void {
+ p.gpa.free(t.own.?);
+ t.own = null;
+ t.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
@@ -714,8 +745,9 @@ fn reviveSession(p: *Pardes, previous: ?*Pardes, resumed: bool) !void {
}
/// A loaded pane given to this host: a terminal a new shell in its old
-/// one's directory under its history, a file watched again (one changed on
-/// disk since comes back as it is now, one unsaved is marked changed), a
+/// one's directory under its history, a file watched again and its
+/// language's server started (one changed on disk since comes back as it
+/// is now, one unsaved is marked changed), a
/// kind's pane opened again (a PDF a build before the pdf addon dumped, as
/// the addon's).
fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool) void {
@@ -758,6 +790,7 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool
} else |_| {}
}
p.emit(.{ .watch = .{ .pane = .at(id), .on = true } });
+ p.emit(.{ .lsp_open = .{ .pane = .at(id) } });
// Its file gone from disk since the dump: its text is nowhere else, so
// it is said deleted, and Del, Exit and Restore ask first. One never on
// disk (a name not yet saved) comes back as it was.
@@ -1375,7 +1408,7 @@ test "restored syntax context caches are rebuilt from the text rather than loade
const f = &pane.file.?;
const declarations = try p.tree_sitter_gpa.alloc(pardes.syntax.ContextDeclaration, 1);
@memset(std.mem.sliceAsBytes(declarations), 0);
- f.context.replace(p.tree_sitter_gpa, declarations, f.revision);
+ f.context.replace(p.tree_sitter_gpa, .{ .declarations = declarations }, f.revision);
// Older builds persisted these two fields; the schema reader must skip them too.
const OldFile = struct {
path: []const u8,
@@ -1401,13 +1434,14 @@ test "restored syntax context caches are rebuilt from the text rather than loade
defer gpa.free(bytes);
const q = try load(gpa, opts, bytes, null);
defer q.deinit();
- // This build's: the revision kept, the declarations parsed again from
- // the text, with the syntax allocator.
- const want = try pardes.syntax.contextDeclarations(syntax_gpa.allocator(), f.path, f.content);
- defer syntax_gpa.allocator().free(want);
+ // This build's: the revision kept, the declarations and the symbols
+ // parsed again from the text, with the syntax allocator.
+ var want = try pardes.syntax.context(syntax_gpa.allocator(), f.path, f.content);
+ defer want.deinit(syntax_gpa.allocator());
for (q.panes) |slot| if (slot) |restored| if (restored.file) |file| {
try std.testing.expectEqual(f.context.revision, file.context.revision);
- try std.testing.expectEqualSlices(pardes.syntax.ContextDeclaration, want, file.context.declarations);
+ try std.testing.expectEqualSlices(pardes.syntax.ContextDeclaration, want.declarations, file.context.declarations);
+ try std.testing.expectEqualSlices(pardes.syntax.Symbol, want.symbols, file.context.symbols);
};
}
diff --git a/core/edit.zig b/core/edit.zig
index e68f8d38..12cd7706 100644
--- a/core/edit.zig
+++ b/core/edit.zig
@@ -540,7 +540,8 @@ pub fn flatSurface(e: Editor, t: *Text) Error![]const u8 {
// the tag as it is shown: the keyboard reaches its prefix too
.tag => return if (t.pane()) |pane| try tagline.tagText(e.p, e.scratch, pane) else "",
.input => return t.own orelse "",
- .column, .workspace => return t.own orelse if (comptime Editor.lib) "" else tagline.headerDefault(e.p, t.what),
+ // a header as it is shown: its computed words, then its own text
+ .column, .workspace => return if (comptime Editor.lib) t.own orelse "" else try tagline.headerText(e.p, t),
}
const pane = t.pane() orelse return "";
if (pane.file) |f| return f.content;
@@ -576,14 +577,13 @@ pub fn paneWrapWidth(e: Editor, t: *Text) usize {
/// Route shared edit operations to the characters `t` edits: its own, or
/// for a body its file's content or its terminal's overlay.
fn editText(e: Editor, t: *Text, lo: i32, hi: i32, col: i32) Error!?panes.EditText {
- // A tag or header nobody has changed shows its default; the first edit
- // makes that default its own text.
+ // A tag or a header is edited as it is shown, its computed words and
+ // all; what an edit leaves after them is its own text (setEditTextSpan).
if (t.what == .tag) {
const pane = t.pane() orelse return null;
return .{ .text = try tagline.tagText(e.p, e.scratch, pane), .row0 = 0 };
}
- if (t.what != .body and t.what != .input and t.own == null)
- t.own = try e.gpa.dupe(u8, try flatSurface(e, t));
+ if (comptime !Editor.lib) if (t.what == .column or t.what == .workspace) return .{ .text = try tagline.headerText(e.p, t), .row0 = 0 };
if (t.what != .body or comptime Editor.lib) return .{ .text = t.own orelse &.{}, .row0 = 0 };
const pane = t.pane() orelse return null;
if (pane.file) |f| return .{ .text = f.content, .row0 = 0 };
@@ -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;
@@ -702,6 +703,20 @@ fn setEditTextSpan(e: Editor, t: *Text, new: []u8, known_end: ?modal.Cursor, spa
t.own = tail;
return;
}
+ if (comptime !Editor.lib) if (t.what == .column or t.what == .workspace) {
+ // A header's computed words (UX K'2) are no one's to edit, as a
+ // tag's prefix is not.
+ defer retireEditText(e, new);
+ const words = tagline.headerWords(e.p, t.what);
+ if (!std.mem.startsWith(u8, new, words) or new.len == words.len or new[words.len] != ' ') {
+ t.refused = true;
+ return;
+ }
+ const tail = try e.gpa.dupe(u8, new[words.len + 1 ..]);
+ if (t.own) |old| e.gpa.free(old);
+ t.own = tail;
+ return;
+ };
if (t.what != .body) {
if (t.own) |old| e.gpa.free(old);
t.own = new;
diff --git a/core/fs.zig b/core/fs.zig
index 594c89cf..c5eb432d 100644
--- a/core/fs.zig
+++ b/core/fs.zig
@@ -868,7 +868,7 @@ pub const Namespace = struct {
.authority = .{
"socket_path", "tcp_address", "mounts", "node_name", "os_paths", "out",
"listeners", "origin", "no_prompt", "session_write", "unlogged", "capturing",
- "serving", "typed", "refused", "failure", "failure_len", "no_pane_slot", "no_pane_slot_len",
+ "serving", "refused", "failure", "failure_len", "no_pane_slot", "no_pane_slot_len",
"said", "said_len", "said_at", "late_failure", "late_failure_len",
"lsp_answer_at", "edit_started", "edit_hold", "edit_said", "lsp_result", "write_room",
"write_waits", "log_full_hash", "pages", "closed_lines", "ran_at", "refilled",
@@ -908,12 +908,10 @@ pub const Namespace = struct {
/// which also refuses prompts, which a click may open).
capturing: bool = false,
/// A 9P request is being served (Pardes.serveFs): a prompt it opens is
- /// a question for the log (`ask`), answered with `answer`.
+ /// a question for the log (`ask`), answered with `answer`. Not while
+ /// the keys or the mouse written to `kbdin` or `mousein` run: they are
+ /// the user's own (ninep/ctl.zig writeKbdin).
serving: bool = false,
- /// The request is keys or a mouse written to `kbdin` or `mousein`:
- /// the user's own, so a builtin they reach routes as typed
- /// (Pick.asked), though their write is served as any other.
- typed: bool = false,
refused: bool = false,
failure: [256]u8 = undefined,
failure_len: u16 = 0,
diff --git a/core/jj.zig b/core/jj.zig
index e9b8edd1..618f363e 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -157,7 +157,7 @@ pub fn open(p: *Pardes, near: usize, path: []const u8, rev: []const u8, at: look
if (replace) p.removePane(near, free) catch |err| p.reportError(.at(free), "At", err);
layout.compute(p);
// Sized for its place before it is centred there.
- p.sync();
+ p.layOut();
look.focusPaneLine(p, free, at, .center);
return free;
}
@@ -2486,7 +2486,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/keys.zig b/core/keys.zig
index 803b2b3c..05349d59 100644
--- a/core/keys.zig
+++ b/core/keys.zig
@@ -1066,12 +1066,12 @@ test "s in a header selects in the header's own text" {
p.update(.{ .key = .{ .cp = 's' } });
try std.testing.expect(pane.prompt == .search and pane.prompt_for == .workspace);
// the prompt takes the keys while the header keeps the keyboard
- p.update(.{ .key = .{ .cp = 'c', .text = "col" } });
+ p.update(.{ .key = .{ .cp = 'i', .text = "i" } });
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expect(p.view().header != null and pane.prompt == .none);
var ranges: [Text.max_selections]modal.Selection = undefined;
const text = try edit.flatSurface(p.editor(), &p.global_tag);
const got = p.global_tag.ranges(text, 0, &ranges);
- try std.testing.expectEqual(@as(usize, 2), got.n); // Newcol, Joincol
+ try std.testing.expectEqual(@as(usize, 2), got.n); // Find, Exit
try std.testing.expectEqual(@as(u16, 0), pane.body.nsel);
}
diff --git a/core/layout.zig b/core/layout.zig
index 3f6bea51..c8fb91f9 100644
--- a/core/layout.zig
+++ b/core/layout.zig
@@ -402,7 +402,7 @@ pub fn givePaneRows(p: *Pardes, id: usize, wanted: u16, context: usize) void {
if (missing == 0) break;
}
setColumnWeights(p, at.col, &heights);
- p.sync();
+ p.layOut();
}
pub fn applyRowSplit(p: *Pardes, cc: usize, k: usize, cur_y: u16) void {
@@ -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'
@@ -1668,12 +1678,24 @@ pub fn noticeRowHeight(p: *const Pardes) u16 {
return 1;
}
-/// The column tags' height: one row, as acme's (cols.c:244, colresize,
-/// gives a column tag one font height); a newline in one is a space
-/// (tagline.flattenHeaders).
+/// The column tags' row: one, as acme's (cols.c:244, colresize, gives a
+/// column tag one font height), a newline in one a space
+/// (tagline.flattenHeaders); only while there are columns (UX K'2): two
+/// or more, a column tag holding the user's text, or no window row for a
+/// lone column's words (a native shell's). None on a screen too short.
pub fn columnBarHeight(p: *const Pardes) u16 {
- if (p.view().screen_h < 3) return 0;
- return COLBAR_H;
+ const v = p.view();
+ if (v.screen_h < 3) return 0;
+ if (v.ncol > 1 or p.topBarHeight() == 0) return COLBAR_H;
+ for (v.col_tags[0..v.ncol]) |t| if (t.own) |own| if (own.len > 0) return COLBAR_H;
+ return 0;
+}
+
+/// A lone column's tag is at the window row's left (UX K'2): no column
+/// row, and a window row for it.
+pub fn columnInWindowRow(p: *const Pardes) bool {
+ const v = p.view();
+ return v.ncol == 1 and v.screen_h >= 3 and p.topBarHeight() > 0 and columnBarHeight(p) == 0;
}
/// Whether new column `c` (Newcol's) may stay. A narrower
@@ -1682,9 +1704,13 @@ pub fn columnBarHeight(p: *const Pardes) u16 {
/// minimum `before`, `before_min`, not one dragged short) takes rows back
/// from the panes with rows to spare, its column shared out again only
/// where that is not enough. False, `c` dropped unannounced, where nothing
-/// holds every minimum, as a size too small is refused.
+/// holds every minimum, as a size too small is refused, and every pane's
+/// rows as they were: the trial's shares are taken back with it (the
+/// column row a second column brings, UX K'2, takes a row from every pane).
pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_min: *const [MAX_PANES]u16) bool {
const v = p.view();
+ var weights: [MAX_PANES]f32 = undefined;
+ for (p.panes, &weights) |slot, *w| w.* = if (slot) |pane| pane.vweight else 0;
restoreMinimaFrom(p, before, before_min);
for (0..p.view().ncol) |k| {
compute(p);
@@ -1694,6 +1720,9 @@ pub fn keepColumn(p: *Pardes, c: usize, before: *const [MAX_PANES]Rect, before_m
if (!pane.collapsed and v.rects[id].h < minRows(p, id) and before[id].h >= before_min[id]) break true;
} else false;
if (squeezed and !shareColumn(p, k)) {
+ for (p.panes, weights) |slot, w| if (slot) |pane| {
+ pane.vweight = w;
+ };
dropColumnUnannounced(p, c);
return false;
}
@@ -2580,3 +2609,47 @@ test "free space first (UX J1): a command's output and a Term take an untouched
try std.testing.expectEqual(before + 3, f.count());
try std.testing.expect(p.panes[scratch] != null);
}
+
+test "the column row comes with a second column and goes with it, the panes giving it and taking it back; a column tag with the user's text keeps it (UX K'2)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ // One column: no column row, its words in the window row, its pane
+ // under the window row.
+ try std.testing.expectEqual(@as(u16, 0), columnBarHeight(p));
+ try std.testing.expect(columnInWindowRow(p));
+ const alone = p.view().rects[0];
+ try std.testing.expectEqual(TOPBAR_H, alone.y);
+ // A second column: the row, under the window row, every column's panes
+ // starting under it.
+ try std.testing.expect(p.executeBuiltinLine(0, "Newcol"));
+ p.sync();
+ try std.testing.expectEqual(@as(usize, 2), p.view().ncol);
+ try std.testing.expectEqual(COLBAR_H, columnBarHeight(p));
+ try std.testing.expect(!columnInWindowRow(p));
+ try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y);
+ newScratchIn(p, 0, 1);
+ p.sync();
+ const second = p.view().cols[1].panes[0];
+ try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[second].y);
+ // Delcol back to one: the row goes, the pane has it again.
+ p.exec_column = 1;
+ try std.testing.expect(p.executeBuiltinLine(second, "Delcol"));
+ p.exec_column = null;
+ p.sync();
+ try std.testing.expectEqual(@as(usize, 1), p.view().ncol);
+ try std.testing.expectEqual(@as(u16, 0), columnBarHeight(p));
+ try std.testing.expectEqualDeep(alone, p.view().rects[0]);
+ // The user's text in the column's tag: the row stays for it, alone.
+ p.view().col_tags[0].own = try p.gpa.dupe(u8, "Mine");
+ p.sync();
+ try std.testing.expectEqual(COLBAR_H, columnBarHeight(p));
+ try std.testing.expect(!columnInWindowRow(p));
+ try std.testing.expectEqual(TOPBAR_H + COLBAR_H, p.view().rects[0].y);
+ // Emptied, it goes again.
+ p.gpa.free(p.view().col_tags[0].own.?);
+ p.view().col_tags[0].own = try p.gpa.dupe(u8, "");
+ p.sync();
+ try std.testing.expectEqual(@as(u16, 0), columnBarHeight(p));
+ try std.testing.expectEqualDeep(alone, p.view().rects[0]);
+}
diff --git a/core/look.zig b/core/look.zig
index d9dfe0e1..3ce1e48c 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -1522,6 +1522,9 @@ pub const Landed = union(enum) { none, shown, opened: usize };
/// `Jumps new-pane` as before the walk: a pane showing the file focused,
/// else a new one.
pub fn open(p: *Pardes, from: usize, path: []const u8, at: Spot, how: How) Landed {
+ // A file a kind takes (an addon's: a picture, a PDF) is its kind's
+ // pane, as a Look of it opens (resolve), never its bytes as a text.
+ if (p.kinds.forPath(path)) |k| return openKind(p, from, path, k, at);
if (how == .replace and p.settings.jumps == .walk and path.len <= Trail.max_text and p.panes[from] != null) return walk(p, from, path, at);
if (how == .replace and focusPaneByPath(p, path, at)) return .shown;
return if (openNew(p, from, path, at, .doc)) |free| .{ .opened = free } else .none;
@@ -1557,6 +1560,38 @@ fn walk(p: *Pardes, from: usize, path: []const u8, at: Spot) Landed {
return .shown;
}
+/// The file at `path`, of kind `kind`, looked at from pane `id`: the pane
+/// of it there is focused, else one of its kind opened as a document is
+/// placed (layout.placeNew), at `at` when it says a place.
+fn openKind(p: *Pardes, id: usize, path: []const u8, kind: u8, at: Spot) Landed {
+ var place: [41]u8 = undefined;
+ if (focusPaneByPath(p, path, .{})) {
+ if (at.line > 0) lookKind(p, id, p.view().active, spotText(at, &place), false);
+ return .shown;
+ }
+ const free = p.freeSlot() orelse {
+ p.reportError(.at(id), "look", error.NoPaneSlots);
+ return .none;
+ };
+ const made = Kind.openFile(p, free, kind, path) catch |err| {
+ lookOpenFailed(p, id, path, err);
+ return .none;
+ };
+ // One its kind refuses (an image corrupt, truncated, not what its name
+ // says) is said, a failure, rather than shown blank.
+ if (made.addon.?.refused.len > 0) {
+ made.vweight = 0;
+ p.unplaced.set(free);
+ var said: Kind.Buf(miss_path_cap + 160) = .{};
+ var cut: [miss_path_cap + "…".len]u8 = undefined;
+ p.reportFailure(id, said.print("look: {s}: {s}", .{ missText(path, &cut), made.addon.?.refused.slice() }));
+ return .none;
+ }
+ layout.placeNew(p, id, id, free, .doc);
+ if (at.line > 0) lookKind(p, id, free, spotText(at, &place), true);
+ return .{ .opened = free };
+}
+
/// `path` opened at `at` in a new pane placed as `kind` places one from
/// `from`, its line half its body's rows down; null when it is not
/// (refused, said).
@@ -1808,24 +1843,7 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
};
return missed(p, id, "{s}: the pane its list is of is gone", .{target.path});
}
- if (focusPaneByPath(p, target.path, .{})) {
- if (target.at.line > 0) lookKind(p, id, v.active, spotText(target.at, &place), false);
- return;
- }
- const free = p.freeSlot() orelse return p.reportError(.at(id), "look", error.NoPaneSlots);
- const made = Kind.openFile(p, free, target.kind, target.path) catch |err|
- return lookOpenFailed(p, id, target.path, err);
- // One its kind refuses (an image corrupt, truncated, not what
- // its name says) is said, a failure, rather than shown blank.
- if (made.addon.?.refused.len > 0) {
- made.vweight = 0;
- p.unplaced.set(free);
- var said: Kind.Buf(miss_path_cap + 160) = .{};
- var cut: [miss_path_cap + "…".len]u8 = undefined;
- return p.reportFailure(id, said.print("look: {s}: {s}", .{ missText(target.path, &cut), made.addon.?.refused.slice() }));
- }
- layout.placeNew(p, id, id, free, .doc);
- if (target.at.line > 0) lookKind(p, id, free, spotText(target.at, &place), true);
+ _ = openKind(p, id, target.path, target.kind, target.at);
},
}
}
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/lsp/lsp.zig b/core/lsp/lsp.zig
index 7a636f72..00ffc98b 100644
--- a/core/lsp/lsp.zig
+++ b/core/lsp/lsp.zig
@@ -96,6 +96,12 @@ pub fn query(io: std.Io, arena: std.mem.Allocator, req: Req, out: *std.Io.Writer
return client.query(io, arena, req, out);
}
+/// A file opened in a pane: its language's server started and told of it
+/// (lsp_client.open), on a host's worker.
+pub fn open(io: std.Io, arena: std.mem.Allocator, req: Req) !void {
+ return client.open(io, arena, req);
+}
+
/// The one line the client answers with when it cannot answer at all, and
/// why: the core says it rather than "nothing found".
pub fn none(out: *std.Io.Writer, comptime fmt: []const u8, args: anytype) std.Io.Writer.Error!void {
diff --git a/core/mouse.zig b/core/mouse.zig
index b62cec7e..04bbaeb4 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -235,7 +235,8 @@ fn kindMouse(p: *Pardes, m: Mouse) bool {
for (p.panes, 0..) |slot, id| {
const pane = slot orelse continue;
const k = pane.addon orelse continue;
- if (!pardes.Kind.takesMouse(p, k) or pane.collapsed) continue;
+ // A picker's preview through a kind is shown, not handled.
+ if (!pardes.Kind.takesMouse(p, k) or pane.collapsed or pardes.Pick.previewing(p, id)) continue;
const r = v.rects[id];
const top = p.bodyTop(pane, r) + pane.notices.span();
const x0 = r.x + config.GUTTER;
@@ -365,11 +366,14 @@ fn emulateButton(p: *Pardes, m: *Mouse) void {
fn headerPoint(p: *Pardes, column: ?usize, mcol: u16, mrow: u16, clamp: bool) ?struct { t: *panes.Text, text: []const u8, line: u16, at: usize } {
const v = p.view();
const t = if (column) |c| &v.col_tags[c] else &p.global_tag;
- const x = if (column) |c| v.col_x[c] + TAG_TEXT_INSET else TAG_TEXT_INSET;
+ // A lone column's tag is at the window row's left, the window's at
+ // its right end (UX K'2).
+ const in_row = column == null or layout.columnInWindowRow(p);
+ const x = if (column) |c| (if (in_row) TAG_TEXT_INSET else v.col_x[c] + TAG_TEXT_INSET) else tagline.windowRow(p).words;
const focused = v.header != null and p.headerColumn() == column;
const text = edit.flatSurface(p.editor(), t) catch return null;
- const base = if (column != null) p.topBarHeight() else 0;
- const rows = if (column != null) layout.columnBarHeight(p) else p.topBarHeight();
+ const base = if (in_row) 0 else p.topBarHeight();
+ const rows = if (in_row) p.topBarHeight() else layout.columnBarHeight(p);
const row: u16 = if (clamp) @min(mrow -| base, rows -| 1) else mrow -| base;
const top: usize = if (focused) v.header_top else 0;
const lines = modal.lineCount(text);
@@ -680,7 +684,12 @@ pub fn handleMouse(p: *Pardes, event: Mouse) void {
var column: ?usize = null;
var x: u16 = TAG_TEXT_INSET;
if (mcol < x) return;
- if (mrow >= p.topBarHeight()) {
+ if (mrow < p.topBarHeight()) {
+ // The window row: a lone column's tag at its left, the
+ // window's at its right; the blank between them is no one's.
+ const sides = tagline.windowRow(p);
+ if (mcol < TAG_TEXT_INSET + sides.column) column = 0 else if (mcol < sides.words) return;
+ } else {
for (0..p.view().ncol) |c| if (mcol >= v.col_x[c] and mcol < v.col_x[c] + v.col_w[c]) {
column = c;
x = v.col_x[c] + TAG_TEXT_INSET;
@@ -1991,3 +2000,39 @@ test "a body press, drag and release are the same state whichever frame this pro
}
try expectSame(a, b, "after the press");
}
+
+fn clickAt(p: *Pardes, button: pardes.Mouse.Button, col: u16, row: u16) void {
+ p.update(.{ .mouse = .{ .button = button, .kind = .press, .col = col, .row = row } });
+ p.update(.{ .mouse = .{ .button = button, .kind = .release, .col = col, .row = row } });
+}
+
+test "one column's words at the window row's left and the window's at its right each run their own; the blank between is no one's (UX K'2)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 20, .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ const row = tagline.windowRow(p);
+ // `New Term ` and its caret's cell from the inset; the window's words
+ // end on the blank before the last cell.
+ try std.testing.expectEqual(@as(u16, "New Term ".len + 1), row.column);
+ try std.testing.expectEqual(@as(u16, 100 - "Find Grep Newcol Help Exit ".len - 1), row.words);
+ // B2 on `New`: a pane in the column.
+ clickAt(p, .middle, TAG_TEXT_INSET + 1, 0);
+ try std.testing.expectEqual(@as(usize, 2), p.view().cols[0].n);
+ // B2 and B1 on the blank between: nothing, and no tag takes the keyboard.
+ const between = row.words - 2;
+ try std.testing.expect(between > TAG_TEXT_INSET + row.column);
+ clickAt(p, .middle, between, 0);
+ clickAt(p, .left, between, 0);
+ try std.testing.expectEqual(@as(usize, 2), p.view().cols[0].n);
+ try std.testing.expectEqual(@as(usize, 1), p.view().ncol);
+ try std.testing.expect(p.view().header == null);
+ // B1 on `Term`: the column's tag has the keyboard, there in the window
+ // row, its caret on the clicked cell.
+ clickAt(p, .left, TAG_TEXT_INSET + "New ".len + 1, 0);
+ p.sync();
+ try std.testing.expectEqual(@as(?usize, 0), p.headerColumn());
+ try std.testing.expectEqual(@as(i32, "New ".len + 1), p.view().col_tags[0].cur_col);
+ // B2 on `Newcol`, at the right: a second column.
+ clickAt(p, .middle, row.words + @as(u16, "Find Grep ".len) + 2, 0);
+ try std.testing.expectEqual(@as(usize, 2), p.view().ncol);
+}
diff --git a/core/ninep/cols.zig b/core/ninep/cols.zig
index 88d8ef88..c84017a7 100644
--- a/core/ninep/cols.zig
+++ b/core/ninep/cols.zig
@@ -79,7 +79,7 @@ pub fn write(p: *Pardes, req: Req, serial: ?u32) Reply {
if (pending) p.fs.header_trunc_pending = null;
return tree.failText(req.tag, E.INVAL, why);
}
- const had = if (pending) 0 else headerText(p, serial).?.len;
+ const had = if (pending) 0 else if (t.own) |own| own.len else 0;
// A rewrite drops its one trailing newline: `echo <4096 bytes> > tag`
// is 4096 bytes of tag, and fits.
const rewrite = pending or p.fs.header_rewrite == rewriteKey(serial);
@@ -89,7 +89,8 @@ pub fn write(p: *Pardes, req: Req, serial: ?u32) Reply {
return tree.failText(req.tag, E.NOSPC, pardes.ctlfs.pane.e_tag_over);
}
applyTruncation(p, serial);
- const was = headerText(p, serial).?;
+ // Its own text grows, after the computed words (UX K'1).
+ const was: []const u8 = t.own orelse "";
var data = req.data;
const rewriting = p.fs.header_rewrite == rewriteKey(serial);
// A newline held from the write before goes in once more text follows.
@@ -106,8 +107,8 @@ pub fn write(p: *Pardes, req: Req, serial: ?u32) Reply {
return .{ .tag = req.tag, .written = @intCast(req.data.len) };
}
-/// Truncating clears it, as a pane tag's `cleartag`: its default words go
-/// too, and `u` in it brings them back.
+/// Truncating clears it, as a pane tag's `cleartag`: its own text goes,
+/// its computed words stay, and `u` in it brings the text back.
pub fn truncate(p: *Pardes, serial: ?u32) tree.Status {
if (header(p, serial) == null) return .err;
// Done with the write after it, which may yet be refused.
@@ -128,8 +129,9 @@ fn clear(p: *Pardes, serial: ?u32) tree.Status {
const empty = p.gpa.alloc(u8, 0) catch unreachable; // no byte: the allocator is not asked
if (t.own) |own| p.gpa.free(own);
t.own = empty;
+ // what is left is the computed words; the cursor goes after them
t.cur_row = 0;
- t.cur_col = 0;
+ t.cur_col = @intCast(tagline.headerWords(p, t.what).len + 1);
p.fs.header_rewrite = rewriteKey(serial);
p.fs.header_held = false;
return .ok;
@@ -548,19 +550,21 @@ test "a column's tag and the workspace's read, replace and append as a pane tag
try testing.expectEqual(E.NOENT, th.look_up(p, col_dir, "777").errno());
const tag = Node.ofCol(serial, .tag);
try testing.expectEqual(tree.Status.ok, th.look_up(p, Node.ofCol(serial, .dir), "tag").reply.status);
- try testing.expectEqualStrings("New Term Find Grep Joincol Delcol", th.rd(p, tag, 0, 4096).bytes);
- // `echo Make > tag`: cleared, then the newline ending the write dropped.
+ // Its computed words (UX K'2), a blank, and its own text: none yet.
+ try testing.expectEqualStrings("New Term ", th.rd(p, tag, 0, 4096).bytes);
+ // `echo Make > tag`: its own text cleared, then the newline ending the
+ // write dropped; the computed words stay.
_ = th.call(p, .{ .tag = 1, .op = .setattr, .node = tag, .truncate = true });
_ = th.wr(p, tag, "Make\n");
- try testing.expectEqualStrings("Make", th.rd(p, tag, 0, 4096).bytes);
+ try testing.expectEqualStrings("New Term Make", th.rd(p, tag, 0, 4096).bytes);
_ = th.call(p, .{ .tag = 2, .op = .release, .node = tag });
// `>>` appends; a newline in a one-line tag is a space.
_ = th.wr(p, tag, " Lint\nNow");
- try testing.expectEqualStrings("Make Lint Now", th.rd(p, tag, 0, 4096).bytes);
+ try testing.expectEqualStrings("New Term Make Lint Now", th.rd(p, tag, 0, 4096).bytes);
const top = @backingInt(tree.TopFile.tag);
_ = th.call(p, .{ .tag = 3, .op = .setattr, .node = top, .truncate = true });
_ = th.wr(p, top, "Newcol Exit\n");
- try testing.expectEqualStrings("Newcol Exit", tagline.topbar(p));
+ try testing.expectEqualStrings("Find Grep Newcol Help Exit Newcol Exit", tagline.topbar(p));
}
test "a focus write makes its pane's column the active one: layout says so and pane/new goes there" {
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig
index 80d1176c..6d78bc44 100644
--- a/core/ninep/ctl.zig
+++ b/core/ninep/ctl.zig
@@ -882,7 +882,10 @@ const e_no_pane = "no such pane";
/// rio's kbdin (windows/rio/xfid.c:515): each rune written is a key typed
/// at the pane with the keyboard, the user's own, each done before the next
-/// and all before the write is answered. Control runes are Ctrl and a
+/// and all before the write is answered. They run as the keyboard's, not as
+/// a script's write: what they start on a worker (a picker's listing or
+/// search, a parse, a language server's answer) comes after the answer, as
+/// a keyboard's comes a frame later. Control runes are Ctrl and a
/// letter, but for Plan 9's keys (include/ALL/keyboard.h): \n or \r Enter,
/// \t Tab, \b Backspace, 0x7f Delete, 0x1b Esc, and the arrows, Home, End,
/// Page Up and Down, Insert and F1-F12 at its private-use runes. Its
@@ -890,8 +893,11 @@ const e_no_pane = "no such pane";
/// or Ctrl to the key after them.
pub fn writeKbdin(p: *Pardes, req: Req) Reply {
const view = std.unicode.Utf8View.init(req.data) catch return tree.failText(req.tag, E.INVAL, "invalid UTF-8");
- p.fs.typed = true;
- defer p.fs.typed = false;
+ // The keyboard's path, not a script's write's: nothing waits on the
+ // loop for a picker's source or an answer (Pick.asked, Stream.step).
+ const serving = p.fs.serving;
+ p.fs.serving = false;
+ defer p.fs.serving = serving;
var it = view.iterator();
var mods: pardes.Key = .{ .cp = 0 };
while (it.nextCodepointSlice()) |rune| {
@@ -946,8 +952,10 @@ fn kbdKey(rune: []const u8) pardes.Key {
/// changed since the last line is pressed or released there, in that order
/// of buttons; a move with one held drags, with none moves.
pub fn writeMousein(p: *Pardes, req: Req) Reply {
- p.fs.typed = true;
- defer p.fs.typed = false;
+ // The mouse's path, as kbdin's keys take the keyboard's.
+ const serving = p.fs.serving;
+ p.fs.serving = false;
+ defer p.fs.serving = serving;
var lines = std.mem.tokenizeScalar(u8, req.data, '\n');
while (lines.next()) |line| {
var words = std.mem.tokenizeAny(u8, line, " \t\r");
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/ninep/pty.zig b/core/ninep/pty.zig
index 2dd7f7f3..2671467f 100644
--- a/core/ninep/pty.zig
+++ b/core/ninep/pty.zig
@@ -597,6 +597,7 @@ test "every pty/ctl verb, and every refusal" {
try testing.expectEqual(@as(u64, "winsize 132 44\n".len), call(p, .{ .tag = 1, .op = .getattr, .node = ctl }).reply.attr.size);
try testing.expect(std.mem.startsWith(u8, rd(p, Node.of(serialOf(p), .pty_status), 0, 64).bytes, " 132 44 "));
p.update(.{ .resize = .{ .cols = 76, .rows = 24 } });
+ p.settle(); // the step's end: the pty takes its pane's size (Pardes.sizeTerminals)
try testing.expect(pane.cols != 132);
try testing.expectEqualStrings(try std.fmt.bufPrint(&said, "winsize {d} {d}\n", .{ pane.cols, pane.rows }), rd(p, ctl, 0, 64).bytes);
diff --git a/core/replica.zig b/core/replica.zig
index 97cbaeee..6c037cd2 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -7351,6 +7351,8 @@ const may_wait = [_]Wait{
.{ .what = "Save", .on = .any, .stop = "write_file", .why = "a save" },
// A program run, a shell opened or closed: the session's processes.
.{ .what = "Exec *", .on = .any, .stop = "kind", .why = "a program run: its name asked of the disk first" },
+ .{ .what = "Find *", .on = .any, .stop = "kind", .why = "the work tree it lists from, a `.jj` or `.git` above the pane's directory asked of the session's disk (Pick.workTree), as the listing itself is the session's" },
+ .{ .what = "Grep *", .on = .any, .stop = "kind", .why = "the work tree it searches, a `.jj` or `.git` above the pane's directory asked of the session's disk (Pick.workTree), as the search itself is the session's" },
.{ .what = "Exec *", .on = .any, .stop = "tty_taken", .why = "a program run in a shell: whether one has it, the session's" },
.{ .what = "Term", .on = .any, .stop = "kind", .why = "a shell opened: its name asked of the disk first" },
.{ .what = "A-n", .on = .any, .stop = "open a terminal", .why = "a shell opened" },
@@ -8001,7 +8003,9 @@ test "a far client's drag in a kind's pane it grabbed, the pane since too short
}
for ([_]pardes.Event{
.{ .mouse = .{ .button = .left, .kind = .press, .col = col, .row = row } },
- .{ .resize = .{ .cols = 80, .rows = 5 } },
+ // Two rows for the two panes under the window row (a lone column has
+ // no column row, UX K'2): one each.
+ .{ .resize = .{ .cols = 80, .rows = 4 } },
.{ .mouse = .{ .button = .left, .kind = .drag, .col = col, .row = 30 } },
.{ .mouse = .{ .button = .left, .kind = .release, .col = col, .row = 30 } },
}) |ev| {
diff --git a/core/root.zig b/core/root.zig
index e07cbed6..1b107d59 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -166,7 +166,13 @@ pub const TAG_TEXT_INSET: u16 = config.GUTTER;
pub fn taglineOriginCol(p: *const Pardes, col: u16, row: u16) f32 {
const v = p.view();
- if (row < p.topBarHeight()) return 0;
+ // The window row's two tags (UX K'2): a lone column's from the inset,
+ // the window's from its words.
+ if (row < p.topBarHeight()) {
+ const sides = tagline.windowRow(p);
+ if (col >= sides.words) return @floatFromInt(sides.words);
+ return if (sides.column > 0 and col >= TAG_TEXT_INSET) @floatFromInt(TAG_TEXT_INSET) else 0;
+ }
if (row < p.topBarHeight() + layout.columnBarHeight(p)) {
for (v.col_x[0..p.view().ncol], v.col_w[0..p.view().ncol]) |x, w|
if (col >= x and col - x < w) return @floatFromInt(x);
@@ -183,7 +189,17 @@ pub fn taglineOriginCol(p: *const Pardes, col: u16, row: u16) f32 {
pub fn gridColAt(p: ?*const Pardes, x: f32, row: u16, body_w: f32, tagline_w: f32) u16 {
const body = @max(body_w, 1);
const tag = @max(tagline_w, 1);
- if (row < (if (p) |core| core.topBarHeight() else TOPBAR_H)) return colFromSpan(x, tag);
+ if (row < (if (p) |core| core.topBarHeight() else TOPBAR_H)) {
+ // Its inset and the blank between its two tags on the body's grid,
+ // each tag's glyphs from its origin (taglineOriginCol).
+ const core = p orelse return colFromSpan(x, tag);
+ const cell = colFromSpan(x, body);
+ const origin: u16 = @intFromFloat(taglineOriginCol(core, cell, row));
+ if (origin == 0) return cell;
+ const sides = tagline.windowRow(core);
+ const end = if (origin < sides.words) TAG_TEXT_INSET + sides.column else core.view().screen_w;
+ return @min(origin + colFromSpan(x - @as(f32, @floatFromInt(origin)) * body, tag), end -| 1);
+ }
if (p) |core| if (row < core.topBarHeight() + layout.columnBarHeight(core)) {
for (core.view().col_x[0..core.view().ncol], core.view().col_w[0..core.view().ncol]) |origin, width| {
if (width == 0) continue;
@@ -279,7 +295,7 @@ fn shortcuts(comptime b: Builtin) []const u8 {
for (config.exec_key) |k| s = s ++ ", " ++ chordName(k);
s = s ++ ", " ++ @tagName(config.exec_button) ++ "-click";
}
- var it = std.mem.tokenizeScalar(u8, config.topbar_str, ' ');
+ var it = std.mem.tokenizeScalar(u8, config.window_words_str, ' ');
while (it.next()) |w| if (std.mem.eql(u8, w, @tagName(b))) {
s = s ++ ", topbar";
};
@@ -333,7 +349,7 @@ pub const builtin_rows: [std.enums.values(Builtin).len]Row = blk: {
comptime {
@setEvalBranchQuota(20000); // one branch per string byte, behind the decl walk that folds Builtin
- var it = std.mem.tokenizeScalar(u8, config.topbar_str, ' ');
+ var it = std.mem.tokenizeScalar(u8, config.topbar_str ++ " " ++ config.window_words_str ++ " " ++ config.columns_words_str, ' ');
words: while (it.next()) |w| {
for (@typeInfo(Builtin).@"enum".field_names) |name|
if (std.mem.eql(u8, name, w)) continue :words;
@@ -368,9 +384,11 @@ test "a compact tagline anchors at its own pane, and both shells step from the s
try std.testing.expectEqual(@as(f32, @floatFromInt(left.x)), taglineOriginCol(p, left.x + 3, left.y));
try std.testing.expectEqual(@as(f32, @floatFromInt(right.x)), taglineOriginCol(p, right.x + 3, right.y));
- // The topbar's origin is column zero always — it is not a pane rect, which
- // is why row zero is right even in a window with no core to ask.
+ // The window row (UX K'2): its blank's origin is column zero, as a window
+ // with no core to ask has it; the window's words start at their own.
+ const words = tagline.windowRow(p).words;
try std.testing.expectEqual(@as(f32, 0), taglineOriginCol(p, 40, 0));
+ try std.testing.expectEqual(@as(f32, @floatFromInt(words)), taglineOriginCol(p, words + 3, 0));
const body_row = left.y + 2;
try std.testing.expectEqual(@as(f32, 7), taglineOriginCol(p, 7, body_row));
@@ -399,9 +417,10 @@ test "a compact tagline anchors at its own pane, and both shells step from the s
try std.testing.expectEqual(col, gridColAt(p, glyph_x + tag_w / 2, left.y, body_w, tag_w));
}
- // The topbar's pointer grid is compact from column zero, with no pane to
- // anchor to — the one tag row that is right with or without a core.
- try std.testing.expectEqual(@as(u16, 3), gridColAt(p, 3.5 * tag_w, 0, body_w, tag_w));
+ // The window row's blank is on the body's grid, its words compact from
+ // where they start; with no core to ask, compact from column zero.
+ try std.testing.expectEqual(@as(u16, 3), gridColAt(p, 3.5 * body_w, 0, body_w, tag_w));
+ try std.testing.expectEqual(words + 3, gridColAt(p, @as(f32, @floatFromInt(words)) * body_w + 3.5 * tag_w, 0, body_w, tag_w));
try std.testing.expectEqual(@as(u16, 3), gridColAt(null, 3.5 * tag_w, 0, body_w, tag_w));
// A body row is untouched: still the body grid, still divided by the body
@@ -461,6 +480,7 @@ test {
_ = @import("FrameStats.zig");
_ = @import("Query.zig");
_ = @import("Names.zig");
+ _ = @import("syntax.zig"); // without it a -Dtest-filter run compiles none of its tests (a whole run has them)
_ = @import("Stream.zig");
_ = @import("Tables.zig");
_ = @import("Handover.zig");
@@ -791,6 +811,7 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{
.{ "Text.zig", "room", "a buffer's capacity" },
.{ "Kind.zig", "ops st gpa arena plain file opened reloads jobs record", "the kind's code and memory here: a plain kind's block is in the copy, and its state hash is checked at every call (Kind.Call.end)" },
.{ "Kind.zig", "thumb_at thumb_span pointer painted over used", "a frame's: written by a paint; `painted` is read by a tick of a kind that is not plain, whose calls are the authority's alone" },
+ .{ "Kind.zig", "drawn_from size", "a picker's preview through a kind (Pick.showKind): this process's draw count when the slot was made, which drops the answers of draws made before it, and the file's size for the line naming it until its kind draws; both read by a frame alone" },
.{ "Places.zig", "ticks ticks_gen re", "the rail's ticks, made again when the places move (`gen`), and the compiled pattern, of the pattern" },
.{ "Plumb.zig", "parsed parsed_arena", "the rules parsed, of their text" },
.{ "Stream.zig", "parse_ns paint paint_retired paint_count ahead ahead_for painted_ahead painted_on_loop ahead_seen ahead_ask", "the workers' paints and timings: how a text looks, and numbers" },
diff --git a/core/syntax.zig b/core/syntax.zig
index 5c05300e..9fbad3cf 100644
--- a/core/syntax.zig
+++ b/core/syntax.zig
@@ -621,7 +621,7 @@ pub fn analyzeSource(gpa: std.mem.Allocator, path: []const u8, content: []const
defer tree.destroy();
var result: SourceAnalysis = .{};
errdefer result.deinit(gpa);
- if (want_declarations) result.declarations = try declarationsFromTree(gpa, content, tree, null);
+ if (want_declarations) result.declarations = (try contextFromTree(gpa, content, tree, null, &.{})).declarations;
if (want_colors) {
result.colors = try gpa.alloc(u8, content.len);
@memset(result.colors, 0);
@@ -635,23 +635,52 @@ pub fn contextDeclarations(gpa: std.mem.Allocator, path: []const u8, content: []
return analysis.declarations;
}
-/// The declarations of `content` (its path's language), on a worker
-/// (`parseApart`). `halt` ends the parse and the walk early
-/// (error.Canceled): a 1.2 MB file is seconds in a Debug build.
-pub fn declarationsApart(gpa: std.mem.Allocator, path: []const u8, content: []const u8, halt: *const std.atomic.Value(bool)) ![]ContextDeclaration {
- if (content.len == 0) return &.{};
+/// A text's context, from one parse: its declarations (the sticky
+/// headers', Locations') and its symbols (the Symbols picker's, UX DESIGN
+/// N), both of the same allocator.
+pub const Context = struct {
+ declarations: []ContextDeclaration = &.{},
+ symbols: []Symbol = &.{},
+
+ pub fn deinit(c: *Context, gpa: std.mem.Allocator) void {
+ gpa.free(c.declarations);
+ gpa.free(c.symbols);
+ c.* = .{};
+ }
+};
+
+/// `content`'s context (its path's language), parsed here: a sticky
+/// header's (File.refreshContext), a loaded text's.
+pub fn context(gpa: std.mem.Allocator, path: []const u8, content: []const u8) !Context {
+ if (content.len == 0) return .{};
+ const spec = byExt(std.Io.Dir.path.extension(path)) orelse return .{};
+ const selected = try ensure(spec);
+ const tree = selected.parser.parseString(content, null) orelse return .{};
+ defer tree.destroy();
+ return contextFromTree(gpa, content, tree, null, rulesOf(spec.name));
+}
+
+/// `content`'s context, on a worker (`parseApart`). `halt` ends the parse
+/// and the walk early (error.Canceled): a 1.2 MB file is seconds in a
+/// Debug build.
+pub fn contextApart(gpa: std.mem.Allocator, path: []const u8, content: []const u8, halt: *const std.atomic.Value(bool)) !Context {
+ if (content.len == 0) return .{};
const ext = std.Io.Dir.path.extension(path);
const spec = specs: for (&specs) |*spec| {
for (spec.exts) |choice| if (std.ascii.eqlIgnoreCase(ext, choice)) break :specs spec;
- } else return &.{};
+ } else return .{};
const tree = try parseApart(langOf(spec), content, halt);
defer tree.destroy();
- return declarationsFromTree(gpa, content, tree, halt);
+ return contextFromTree(gpa, content, tree, halt, rulesOf(spec.name));
}
-fn declarationsFromTree(gpa: std.mem.Allocator, content: []const u8, tree: *ts.Tree, halt: ?*const std.atomic.Value(bool)) ![]ContextDeclaration {
+/// The declarations and, by `rules` (none: no symbols), the symbols of a
+/// parse, in one walk of its nodes.
+fn contextFromTree(gpa: std.mem.Allocator, content: []const u8, tree: *ts.Tree, halt: ?*const std.atomic.Value(bool), rules: []const Rule) !Context {
var result: std.ArrayList(ContextDeclaration) = .empty;
errdefer result.deinit(gpa);
+ var symbols: SymbolWalk = .{ .gpa = gpa, .rules = rules, .source = content };
+ errdefer symbols.out.deinit(gpa);
// The cursor retains its ancestor stack: sibling visits do not repeatedly
// reconstruct parents in broad syntax trees. Preorder preserves source order.
var cursor = tree.rootNode().walk();
@@ -661,14 +690,21 @@ fn declarationsFromTree(gpa: std.mem.Allocator, content: []const u8, tree: *ts.T
visited += 1;
if (halt) |flag| if (visited % 4096 == 0 and flag.load(.monotonic)) return error.Canceled;
const node = cursor.node();
- if (node.isNamed()) if (contextSpan(node, content)) |span| {
- if (result.items.len == 0 or result.items[result.items.len - 1].start_line != span.start_line or
- result.items[result.items.len - 1].end_line != span.end_line)
- try result.append(gpa, span);
- };
+ if (node.isNamed()) {
+ if (contextSpan(node, content)) |span| {
+ if (result.items.len == 0 or result.items[result.items.len - 1].start_line != span.start_line or
+ result.items[result.items.len - 1].end_line != span.end_line)
+ try result.append(gpa, span);
+ }
+ if (rules.len > 0) try symbols.visit(node);
+ }
if (cursor.gotoFirstChild()) continue;
while (!cursor.gotoNextSibling()) {
- if (!cursor.gotoParent()) return result.toOwnedSlice(gpa);
+ if (!cursor.gotoParent()) {
+ const declarations = try result.toOwnedSlice(gpa);
+ errdefer gpa.free(declarations);
+ return .{ .declarations = declarations, .symbols = try symbols.out.toOwnedSlice(gpa) };
+ }
}
}
}
@@ -761,6 +797,543 @@ fn contextSpan(node: ts.Node, source: []const u8) ?ContextDeclaration {
};
}
+// ---- symbols: the Symbols picker's (UX DESIGN N) ----
+
+/// What a symbol is, in the Symbols picker's order (UX DESIGN N2): types,
+/// functions, fields, then the rest (consts, vars, modules, other) as one
+/// group. A `scope` is listed nowhere: it names its members (Rust's
+/// `impl S`: `S.new`).
+pub const SymbolKind = enum(u8) {
+ type,
+ function,
+ field,
+ constant,
+ variable,
+ module,
+ other,
+ scope,
+
+ /// Its mark in a row (UX DESIGN N4): one letter, `·` for the other.
+ pub fn mark(k: SymbolKind) []const u8 {
+ return switch (k) {
+ .type => "t",
+ .function => "f",
+ .field => "m",
+ .constant => "c",
+ .variable => "v",
+ .module => "n",
+ .other, .scope => "·",
+ };
+ }
+
+ /// Its group in the picker: 0 types, 1 functions, 2 fields, 3 the rest.
+ pub fn group(k: SymbolKind) u8 {
+ return @min(@intFromEnum(k), 3);
+ }
+};
+
+/// A declaration the Symbols picker lists: its kind, the line and bytes of
+/// its name, and the symbol it is declared in.
+pub const Symbol = struct {
+ kind: SymbolKind,
+ /// The line its name is on, from 0.
+ line: u32,
+ name_start: u32,
+ name_end: u32,
+ /// Where what its row says after its name ends (a function's
+ /// signature): its body's start, else its own end. Its row cuts it at
+ /// its name's line's end.
+ end: u32,
+ /// The symbol it is declared in, by its index + 1 (0: none): its name
+ /// qualifies this one's (`Counts.lines`).
+ parent: u32 = 0,
+};
+
+/// How a node of a grammar is a symbol (UX DESIGN N2: one table a language).
+const Rule = struct {
+ node: []const u8,
+ kind: SymbolKind,
+ how: How = .plain,
+ /// The field naming it; without it, its declarator's name (C's) or the
+ /// first name under it (`nameOf`). "": none (an anonymous scope).
+ name: []const u8 = "name",
+ /// A form's first words and the kinds they declare (`.head`).
+ heads: []const struct { []const u8, SymbolKind } = &.{},
+ /// Not one under a node of this kind (Pascal's declProc heading the
+ /// defProc that is the symbol).
+ unless_in: []const u8 = "",
+};
+
+const How = enum {
+ /// Its kind as given.
+ plain,
+ /// Only with a body (C's `struct s { ... }`; `struct s x;` names the
+ /// type, declares none); unnamed, a scope (an anonymous struct's fields
+ /// are its owner's).
+ body,
+ /// C's declaration: a function where a declarator on the way to its
+ /// name is one's; else a const where `const` says so (its kind a var).
+ declarator,
+ /// A binding whose value tells: a type, a function, a module (Zig's
+ /// `const S = struct`, `@import`, JavaScript's arrow function); else a
+ /// const or a var by its keyword.
+ value,
+ /// A binding that is a field in a type (a Python class's attribute,
+ /// Kotlin's property); else a const or a var by its keyword. Named
+ /// by a name, never a pattern (`self.x = ...`).
+ binding,
+ /// A form whose first word says what it declares (Elixir's `def f`,
+ /// Clojure's `(defn f ...)`), named by its second.
+ head,
+ /// No row: a scope its members are named in, by its own name (Rust's
+ /// `impl S`) or its owner's (an anonymous struct).
+ scope,
+};
+
+const c_rules = [_]Rule{
+ .{ .node = "function_definition", .kind = .function },
+ .{ .node = "declaration", .kind = .variable, .how = .declarator },
+ .{ .node = "field_declaration", .kind = .field, .how = .declarator },
+ .{ .node = "struct_specifier", .kind = .type, .how = .body },
+ .{ .node = "union_specifier", .kind = .type, .how = .body },
+ .{ .node = "enum_specifier", .kind = .type, .how = .body },
+ .{ .node = "enumerator", .kind = .field },
+ .{ .node = "type_definition", .kind = .type },
+ .{ .node = "preproc_def", .kind = .other },
+ .{ .node = "preproc_function_def", .kind = .other },
+};
+
+/// The kind tables, by grammar (grammar_manifest.zig): a grammar with none
+/// (JSON, CSS, HTML, Markdown, Typst) lists no symbols.
+const symbol_rules = [_]struct { []const u8, []const Rule }{
+ .{ "zig", &.{
+ // Named by its FnProto's `function` (symbolOf).
+ .{ .node = "Decl", .kind = .function, .name = "" },
+ .{ .node = "VarDecl", .kind = .variable, .how = .value, .name = "variable_type_function" },
+ .{ .node = "ContainerField", .kind = .field },
+ .{ .node = "TestDecl", .kind = .other, .name = "" },
+ .{ .node = "ContainerDecl", .kind = .type, .how = .scope, .name = "" },
+ } },
+ .{ "c", &c_rules },
+ .{ "cpp", &(c_rules ++ [_]Rule{
+ .{ .node = "class_specifier", .kind = .type, .how = .body },
+ .{ .node = "namespace_definition", .kind = .module },
+ .{ .node = "alias_declaration", .kind = .type },
+ }) },
+ .{ "rust", &.{
+ .{ .node = "function_item", .kind = .function },
+ .{ .node = "function_signature_item", .kind = .function },
+ .{ .node = "struct_item", .kind = .type },
+ .{ .node = "enum_item", .kind = .type },
+ .{ .node = "union_item", .kind = .type },
+ .{ .node = "trait_item", .kind = .type },
+ .{ .node = "type_item", .kind = .type },
+ .{ .node = "impl_item", .kind = .type, .how = .scope, .name = "type" },
+ .{ .node = "field_declaration", .kind = .field },
+ .{ .node = "enum_variant", .kind = .field },
+ .{ .node = "const_item", .kind = .constant },
+ .{ .node = "static_item", .kind = .variable },
+ .{ .node = "mod_item", .kind = .module },
+ .{ .node = "macro_definition", .kind = .other },
+ } },
+ .{ "go", &.{
+ .{ .node = "function_declaration", .kind = .function },
+ .{ .node = "method_declaration", .kind = .function },
+ .{ .node = "method_elem", .kind = .function },
+ .{ .node = "type_spec", .kind = .type },
+ .{ .node = "type_alias", .kind = .type },
+ .{ .node = "field_declaration", .kind = .field },
+ .{ .node = "const_spec", .kind = .constant },
+ .{ .node = "var_spec", .kind = .variable },
+ } },
+ .{ "python", &.{
+ .{ .node = "class_definition", .kind = .type },
+ .{ .node = "function_definition", .kind = .function },
+ .{ .node = "assignment", .kind = .variable, .how = .binding, .name = "left" },
+ } },
+ .{ "javascript", &.{
+ .{ .node = "function_declaration", .kind = .function },
+ .{ .node = "generator_function_declaration", .kind = .function },
+ .{ .node = "class_declaration", .kind = .type },
+ .{ .node = "method_definition", .kind = .function },
+ .{ .node = "field_definition", .kind = .field, .name = "property" },
+ .{ .node = "variable_declarator", .kind = .variable, .how = .value },
+ } },
+ .{ "java", &.{
+ .{ .node = "class_declaration", .kind = .type },
+ .{ .node = "interface_declaration", .kind = .type },
+ .{ .node = "enum_declaration", .kind = .type },
+ .{ .node = "record_declaration", .kind = .type },
+ .{ .node = "annotation_type_declaration", .kind = .type },
+ .{ .node = "method_declaration", .kind = .function },
+ .{ .node = "constructor_declaration", .kind = .function },
+ .{ .node = "field_declaration", .kind = .field },
+ .{ .node = "enum_constant", .kind = .field },
+ .{ .node = "constant_declaration", .kind = .constant },
+ } },
+ .{ "c_sharp", &.{
+ .{ .node = "class_declaration", .kind = .type },
+ .{ .node = "struct_declaration", .kind = .type },
+ .{ .node = "interface_declaration", .kind = .type },
+ .{ .node = "enum_declaration", .kind = .type },
+ .{ .node = "record_declaration", .kind = .type },
+ .{ .node = "delegate_declaration", .kind = .type },
+ .{ .node = "namespace_declaration", .kind = .module },
+ .{ .node = "file_scoped_namespace_declaration", .kind = .module },
+ .{ .node = "method_declaration", .kind = .function },
+ .{ .node = "constructor_declaration", .kind = .function },
+ .{ .node = "destructor_declaration", .kind = .function },
+ .{ .node = "field_declaration", .kind = .field },
+ .{ .node = "property_declaration", .kind = .field },
+ .{ .node = "event_field_declaration", .kind = .field },
+ .{ .node = "enum_member_declaration", .kind = .field },
+ } },
+ .{ "kotlin", &.{
+ .{ .node = "class_declaration", .kind = .type },
+ .{ .node = "object_declaration", .kind = .type },
+ .{ .node = "companion_object", .kind = .type, .how = .scope, .name = "" },
+ .{ .node = "function_declaration", .kind = .function },
+ .{ .node = "property_declaration", .kind = .variable, .how = .binding },
+ .{ .node = "type_alias", .kind = .type },
+ .{ .node = "enum_entry", .kind = .field },
+ } },
+ .{ "scala", &.{
+ .{ .node = "class_definition", .kind = .type },
+ .{ .node = "object_definition", .kind = .type },
+ .{ .node = "trait_definition", .kind = .type },
+ .{ .node = "enum_definition", .kind = .type },
+ .{ .node = "type_definition", .kind = .type },
+ .{ .node = "function_definition", .kind = .function },
+ .{ .node = "function_declaration", .kind = .function },
+ .{ .node = "val_definition", .kind = .constant, .how = .binding, .name = "pattern" },
+ .{ .node = "var_definition", .kind = .variable, .how = .binding, .name = "pattern" },
+ .{ .node = "simple_enum_case", .kind = .field },
+ .{ .node = "full_enum_case", .kind = .field },
+ } },
+ .{ "ruby", &.{
+ .{ .node = "class", .kind = .type },
+ .{ .node = "singleton_class", .kind = .type, .how = .scope, .name = "" },
+ .{ .node = "module", .kind = .module },
+ .{ .node = "method", .kind = .function },
+ .{ .node = "singleton_method", .kind = .function },
+ } },
+ .{ "php", &.{
+ .{ .node = "class_declaration", .kind = .type },
+ .{ .node = "interface_declaration", .kind = .type },
+ .{ .node = "trait_declaration", .kind = .type },
+ .{ .node = "enum_declaration", .kind = .type },
+ .{ .node = "function_definition", .kind = .function },
+ .{ .node = "method_declaration", .kind = .function },
+ .{ .node = "property_declaration", .kind = .field },
+ .{ .node = "enum_case", .kind = .field },
+ .{ .node = "const_declaration", .kind = .constant },
+ .{ .node = "namespace_definition", .kind = .module },
+ } },
+ .{ "bash", &.{
+ .{ .node = "function_definition", .kind = .function },
+ .{ .node = "variable_assignment", .kind = .variable, .how = .binding },
+ } },
+ .{ "haskell", &.{
+ .{ .node = "data_type", .kind = .type },
+ .{ .node = "newtype", .kind = .type },
+ .{ .node = "type_synomym", .kind = .type },
+ .{ .node = "class", .kind = .type },
+ .{ .node = "instance", .kind = .type, .how = .scope },
+ .{ .node = "function", .kind = .function },
+ .{ .node = "bind", .kind = .constant },
+ .{ .node = "data_constructor", .kind = .field },
+ } },
+ .{ "ocaml", &.{
+ .{ .node = "type_binding", .kind = .type },
+ .{ .node = "module_binding", .kind = .module },
+ .{ .node = "module_type_definition", .kind = .type },
+ .{ .node = "class_binding", .kind = .type },
+ .{ .node = "method_definition", .kind = .function },
+ .{ .node = "let_binding", .kind = .constant, .how = .value, .name = "pattern" },
+ .{ .node = "field_declaration", .kind = .field },
+ .{ .node = "constructor_declaration", .kind = .field },
+ } },
+ .{ "erlang", &.{
+ .{ .node = "fun_decl", .kind = .function },
+ .{ .node = "record_decl", .kind = .type },
+ .{ .node = "record_field", .kind = .field },
+ .{ .node = "type_alias", .kind = .type },
+ .{ .node = "pp_define", .kind = .other },
+ .{ .node = "module_attribute", .kind = .module },
+ } },
+ .{ "elixir", &.{
+ .{ .node = "call", .kind = .other, .how = .head, .heads = &.{
+ .{ "defmodule", .module }, .{ "defprotocol", .type }, .{ "def", .function },
+ .{ "defp", .function }, .{ "defdelegate", .function }, .{ "defguard", .function },
+ .{ "defguardp", .function }, .{ "defmacro", .other }, .{ "defmacrop", .other },
+ } },
+ } },
+ .{ "clojure", &.{
+ .{ .node = "list_lit", .kind = .other, .how = .head, .heads = &.{
+ .{ "ns", .module }, .{ "def", .constant }, .{ "defonce", .constant }, .{ "defn", .function },
+ .{ "defn-", .function }, .{ "defmulti", .function }, .{ "defmethod", .function }, .{ "defmacro", .other },
+ .{ "defrecord", .type }, .{ "deftype", .type }, .{ "defprotocol", .type }, .{ "definterface", .type },
+ .{ "defstruct", .type },
+ } },
+ } },
+ .{ "fortran", &.{
+ .{ .node = "module", .kind = .module },
+ .{ .node = "program", .kind = .module },
+ .{ .node = "subroutine", .kind = .function },
+ .{ .node = "function", .kind = .function },
+ .{ .node = "derived_type_definition", .kind = .type },
+ .{ .node = "variable_declaration", .kind = .variable, .how = .binding },
+ } },
+ .{ "ada", &.{
+ .{ .node = "package_declaration", .kind = .module },
+ .{ .node = "package_body", .kind = .module },
+ .{ .node = "full_type_declaration", .kind = .type },
+ .{ .node = "subprogram_declaration", .kind = .function },
+ .{ .node = "subprogram_body", .kind = .function },
+ .{ .node = "object_declaration", .kind = .variable, .how = .binding },
+ .{ .node = "component_declaration", .kind = .field },
+ } },
+ .{ "pascal", &.{
+ .{ .node = "declType", .kind = .type },
+ .{ .node = "declProc", .kind = .function, .unless_in = "defProc" },
+ .{ .node = "defProc", .kind = .function },
+ .{ .node = "declConst", .kind = .constant },
+ .{ .node = "declVar", .kind = .variable, .how = .binding },
+ .{ .node = "declField", .kind = .field },
+ } },
+ .{ "powershell", &.{
+ .{ .node = "function_statement", .kind = .function },
+ .{ .node = "class_statement", .kind = .type },
+ .{ .node = "class_method_definition", .kind = .function },
+ .{ .node = "class_property_definition", .kind = .field },
+ .{ .node = "enum_statement", .kind = .type },
+ .{ .node = "enum_member", .kind = .field },
+ } },
+};
+
+fn rulesOf(grammar: []const u8) []const Rule {
+ for (symbol_rules) |entry| if (std.mem.eql(u8, entry[0], grammar)) return entry[1];
+ return &.{};
+}
+
+/// A walk's symbols, node by node in preorder (`contextFromTree`).
+const SymbolWalk = struct {
+ gpa: std.mem.Allocator,
+ rules: []const Rule,
+ source: []const u8,
+ out: std.ArrayList(Symbol) = .empty,
+ /// The scopes the node is in, the innermost last.
+ scopes: [max_scopes]Scope = undefined,
+ depth: u8 = 0,
+
+ /// Where a scope ends, its kind, and the symbol its members are named
+ /// in (an index + 1, 0 none).
+ const Scope = struct { end: u32, kind: SymbolKind, symbol: u32 };
+ /// Deeper scopes are their parent's.
+ const max_scopes = 32;
+
+ fn visit(w: *SymbolWalk, node: ts.Node) !void {
+ while (w.depth > 0 and w.scopes[w.depth - 1].end <= node.startByte()) w.depth -= 1;
+ const in: Scope = if (w.depth > 0) w.scopes[w.depth - 1] else .{ .end = 0, .kind = .module, .symbol = 0 };
+ // A test's body (a macro's) lists nothing: its types are its
+ // locals' (a test's `const Find = struct`).
+ if (in.kind == .other) return;
+ const kind_name = node.kind();
+ const rule = for (w.rules) |r| {
+ if (std.mem.eql(u8, r.node, kind_name)) break r;
+ } else return;
+ const found = symbolOf(rule, node, w.source, in.kind) orelse return;
+ // A body's consts and vars are its locals, none of them listed.
+ const local = in.kind != .type and in.kind != .module and in.kind != .scope;
+ if (local and (found.kind == .constant or found.kind == .variable)) return;
+ var named = in.symbol;
+ if (found.name) |name| {
+ // A longer name is cut (a test's sentence), on a character.
+ var end = name.endByte();
+ if (end - name.startByte() > max_name) {
+ end = name.startByte() + max_name;
+ while (end > name.startByte() and w.source[end] & 0xc0 == 0x80) end -= 1;
+ }
+ try w.out.append(w.gpa, .{
+ .kind = found.kind,
+ .line = name.startPoint().row,
+ .name_start = name.startByte(),
+ .name_end = end,
+ .end = found.end,
+ .parent = in.symbol,
+ });
+ // A const's or a field's members are not named in it.
+ if (found.kind == .type or found.kind == .function or found.kind == .module or found.kind == .scope) named = @intCast(w.out.items.len);
+ }
+ if (w.depth == max_scopes) return;
+ w.scopes[w.depth] = .{ .end = node.endByte(), .kind = if (found.kind == .scope) rule.kind else found.kind, .symbol = named };
+ w.depth += 1;
+ }
+};
+
+/// What node `node` declares by `rule`, in a scope of kind `in`: its kind,
+/// its name (null: an anonymous scope) and where its row's words end.
+fn symbolOf(rule: Rule, node: ts.Node, source: []const u8, in: SymbolKind) ?struct { kind: SymbolKind, name: ?ts.Node, end: u32 } {
+ if (rule.unless_in.len > 0) if (node.parent()) |up| if (std.mem.eql(u8, up.kind(), rule.unless_in)) return null;
+ var kind = rule.kind;
+ var name: ?ts.Node = null;
+ var end = if (node.childByFieldName("body")) |body| body.startByte() else node.endByte();
+ switch (rule.how) {
+ .plain => name = nameOf(node, rule.name),
+ .scope => {
+ name = nameOf(node, rule.name);
+ kind = .scope;
+ },
+ .body => {
+ if (node.childByFieldName("body") == null) return null;
+ name = nameOf(node, rule.name);
+ if (name == null) kind = .scope;
+ },
+ .declarator => {
+ var d = node;
+ while (d.childByFieldName("declarator")) |next| {
+ if (std.mem.eql(u8, next.kind(), "function_declarator")) kind = .function;
+ d = next;
+ }
+ name = nameOf(node, rule.name);
+ if (kind == .variable and constant(source, node.startByte(), name orelse return null)) kind = .constant;
+ },
+ .value => {
+ // Named by a name, never a pattern (`const { a, b } = ...`,
+ // OCaml's `let () = ...`).
+ name = nameOf(node, rule.name);
+ if (name) |n| if (!nameLike(n.kind())) return null;
+ kind = valueKind(node, source) orelse kind;
+ // JavaScript's keyword is its declaration's (`const a = 1, b`).
+ const from = if (std.mem.eql(u8, rule.node, "variable_declarator")) (node.parent() orelse node).startByte() else node.startByte();
+ if (kind == .variable and constant(source, from, name orelse return null)) kind = .constant;
+ },
+ .binding => {
+ const n = node.childByFieldName(rule.name) orelse nameOf(node, rule.name) orelse return null;
+ if (!nameLike(n.kind())) return null;
+ name = n;
+ if (in == .type) kind = .field else if (kind == .variable and constant(source, node.startByte(), n)) kind = .constant;
+ },
+ .head => {
+ const elixir = std.mem.eql(u8, rule.node, "call");
+ const first = (if (elixir) node.childByFieldName("target") else node.namedChild(0)) orelse return null;
+ const word = source[first.startByte()..first.endByte()];
+ kind = for (rule.heads) |h| {
+ if (std.mem.eql(u8, h[0], word)) break h[1];
+ } else return null;
+ var second = (if (elixir) childOfKind(node, "arguments") else node.namedChild(1)) orelse return null;
+ if (elixir) second = second.namedChild(0) orelse return null;
+ if (second.childByFieldName("target")) |target| second = target;
+ name = if (nameLike(second.kind())) second else nameOf(second, "name");
+ },
+ }
+ // Zig's: a function's name is its prototype's, its body a Block; a
+ // test's its string.
+ if (std.mem.eql(u8, rule.node, "Decl")) {
+ const proto = childOfKind(node, "FnProto") orelse return null;
+ name = proto.childByFieldName("function");
+ if (childOfKind(node, "Block")) |block| end = block.startByte();
+ } else if (std.mem.eql(u8, rule.node, "TestDecl")) {
+ const first = node.namedChild(0) orelse return null;
+ if (std.mem.eql(u8, first.kind(), "Block")) return null;
+ name = first;
+ if (childOfKind(node, "Block")) |block| end = block.startByte();
+ }
+ if (name == null and kind != .scope) return null;
+ if (name) |n| if (n.endByte() <= n.startByte()) return null;
+ return .{ .kind = kind, .name = name, .end = end };
+}
+
+/// The longest name a symbol has: a longer one is cut.
+const max_name = 200;
+
+/// The node naming `node`: its field `field`, whole on its line (C++'s
+/// `namespace v8::internal`, Rust's `impl Vec<T>`); without one, its
+/// declarator's (C's `int *f(void)`: `f`); else the first name under it,
+/// past its type, value, body and parameters (Kotlin's, Fortran's).
+fn nameOf(node: ts.Node, field: []const u8) ?ts.Node {
+ if (field.len == 0) return null;
+ var n = node;
+ if (node.childByFieldName(field)) |f| {
+ if (f.startPoint().row == f.endPoint().row) return f;
+ n = f;
+ } else while (n.childByFieldName("declarator")) |d| n = d;
+ if (nameLike(n.kind())) return n;
+ if (n.childByFieldName("name")) |f| if (nameLike(f.kind())) return f;
+ return firstName(n, 3);
+}
+
+fn firstName(node: ts.Node, depth: u8) ?ts.Node {
+ if (depth == 0) return null;
+ const skipped = [_][]const u8{ "type", "value", "body", "parameters", "return_type", "returns", "result", "superclass", "arguments", "default", "trait" };
+ var i: u32 = 0;
+ while (i < node.childCount()) : (i += 1) {
+ const child = node.child(i) orelse continue;
+ if (!child.isNamed()) continue;
+ const field = node.fieldNameForChild(i) orelse "";
+ if (for (skipped) |s| {
+ if (std.mem.eql(u8, s, field)) break true;
+ } else false) continue;
+ const kind = child.kind();
+ if (std.mem.indexOf(u8, kind, "modifier") != null or std.mem.indexOf(u8, kind, "annotation") != null or
+ std.mem.indexOf(u8, kind, "parameter") != null or std.mem.indexOf(u8, kind, "attribute") != null or
+ std.mem.indexOf(u8, kind, "decorator") != null or std.mem.indexOf(u8, kind, "comment") != null or
+ std.mem.indexOf(u8, kind, "literal") != null) continue;
+ if (nameLike(kind)) return child;
+ if (firstName(child, depth - 1)) |found| return found;
+ }
+ return null;
+}
+
+/// A node kind that is a name: an identifier, a `*_name`, a word.
+fn nameLike(kind: []const u8) bool {
+ if (std.ascii.endsWithIgnoreCase(kind, "identifier") or std.mem.endsWith(u8, kind, "name")) return true;
+ for ([_][]const u8{ "word", "constant", "atom", "variable", "constructor", "type_constructor", "alias" }) |k| {
+ if (std.mem.eql(u8, kind, k)) return true;
+ }
+ return false;
+}
+
+/// What a binding's value makes it, where it says (else null): Zig's
+/// `struct {...}`, `error{...}`, `@This()`, `@Type(...)` a type and
+/// `@import(...)` a module; JavaScript's function a function and class a
+/// type; OCaml's `let f x = ...` (a parameter) a function.
+fn valueKind(node: ts.Node, source: []const u8) ?SymbolKind {
+ if (node.childByFieldName("value")) |value| {
+ const kind = value.kind();
+ for ([_][]const u8{ "arrow_function", "function_expression", "generator_function" }) |k| if (std.mem.eql(u8, kind, k)) return .function;
+ if (std.mem.eql(u8, kind, "class")) return .type;
+ return null;
+ }
+ if (childOfKind(node, "parameter") != null) return .function;
+ // Zig's value: the last of the VarDecl, under its ErrorUnionExpr.
+ var v = node.namedChild(node.namedChildCount() -| 1) orelse return null;
+ while (std.mem.eql(u8, v.kind(), "ErrorUnionExpr")) v = v.namedChild(0) orelse return null;
+ if (!std.mem.eql(u8, v.kind(), "SuffixExpr")) return null;
+ const first = v.namedChild(0) orelse return null;
+ const kind = first.kind();
+ if (std.mem.eql(u8, kind, "ContainerDecl") or std.mem.eql(u8, kind, "ErrorSetDecl")) return .type;
+ if (!std.mem.eql(u8, kind, "BUILTINIDENTIFIER")) return null;
+ const builtin = source[first.startByte()..first.endByte()];
+ if (std.mem.eql(u8, builtin, "@This") or std.mem.eql(u8, builtin, "@Type")) return .type;
+ if ((std.mem.eql(u8, builtin, "@import") or std.mem.eql(u8, builtin, "@cImport")) and v.namedChildCount() == 2) return .module;
+ return null;
+}
+
+/// Whether a binding is a const: a keyword says so between `from` and its
+/// name, or after the name before its value (Ada's `K : constant`).
+fn constant(source: []const u8, from: usize, name: ts.Node) bool {
+ const after = source[name.endByte()..];
+ const before_value = std.mem.indexOfAny(u8, after, "=\n") orelse after.len;
+ for ([_][]const u8{ source[@min(from, name.startByte())..name.startByte()], after[0..before_value] }) |text| {
+ var words = std.mem.tokenizeAny(u8, text, " \t\r\n,:()*&");
+ while (words.next()) |word| for ([_][]const u8{ "const", "constexpr", "val", "final", "readonly", "parameter", "constant" }) |k| {
+ if (std.mem.eql(u8, word, k)) return true;
+ };
+ }
+ return false;
+}
+
fn paint(styles: []u8, source: []const u8, selected: Selected) void {
const tree = selected.parser.parseString(source, null) orelse return;
defer tree.destroy();
@@ -2180,3 +2753,131 @@ test "syntax: a grammar handed in at run time colours and walks as the one compi
forgetLanguages();
try std.testing.expect(!supportsPath("x.mine"));
}
+
+/// Each of `source`'s symbols as `mark qualified name`, in the walk's order.
+fn symbolLines(gpa: std.mem.Allocator, path: []const u8, source: []const u8) ![]const u8 {
+ var made = try context(gpa, path, source);
+ defer made.deinit(gpa);
+ var out: std.Io.Writer.Allocating = .init(gpa);
+ defer out.deinit();
+ for (made.symbols) |sym| {
+ if (sym.kind == .scope) continue;
+ try out.writer.print("{s} ", .{sym.kind.mark()});
+ var chain: [8]u32 = undefined;
+ var n: usize = 0;
+ var up = sym.parent;
+ while (up != 0 and n < chain.len) : (up = made.symbols[up - 1].parent) {
+ chain[n] = up;
+ n += 1;
+ }
+ while (n > 0) {
+ n -= 1;
+ const s = made.symbols[chain[n] - 1];
+ try out.writer.print("{s}.", .{source[s.name_start..s.name_end]});
+ }
+ try out.writer.print("{s}\n", .{source[sym.name_start..sym.name_end]});
+ }
+ return out.toOwnedSlice();
+}
+
+test "syntax symbols: a Zig file's types, functions, fields and the rest by their declarations and values, each named in the containers it is in; a function's locals and an unnamed test none of them (UX DESIGN N2)" {
+ if (comptime !minimal_grammars) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ start(gpa);
+ defer stop();
+ const source =
+ \\const std = @import("std");
+ \\pub const Counts = struct {
+ \\ lines: usize = 0,
+ \\ pub const zero: Counts = .{};
+ \\ pub fn add(c: *Counts) void {
+ \\ const local = 1;
+ \\ c.lines += local;
+ \\ }
+ \\};
+ \\const Mode = enum { fast, slow };
+ \\const Failure = error{ Late, Lost };
+ \\const Self = @This();
+ \\var hits: u32 = 0;
+ \\fn List(comptime T: type) type {
+ \\ return struct { items: []T };
+ \\}
+ \\test "count" {
+ \\ const Local = struct {
+ \\ fn helper() void {}
+ \\ };
+ \\ _ = Local;
+ \\}
+ \\test {}
+ \\extern fn tick() void;
+ \\
+ ;
+ // A test's name longer than a row's room is cut, its body still none.
+ const xs: [250]u8 = @splat('x');
+ const long = "test \"" ++ xs ++ "\" {\n const Inner = struct {};\n _ = Inner;\n}\n";
+ const lines = try symbolLines(gpa, "a.zig", source ++ long);
+ defer gpa.free(lines);
+ try std.testing.expectEqualStrings(
+ \\n std
+ \\t Counts
+ \\m Counts.lines
+ \\c Counts.zero
+ \\f Counts.add
+ \\t Mode
+ \\m Mode.fast
+ \\m Mode.slow
+ \\t Failure
+ \\t Self
+ \\v hits
+ \\f List
+ \\m List.items
+ \\· "count"
+ \\f tick
+ \\
+ ++ "· \"" ++ xs[0 .. max_name - 1].* ++ "\n", lines);
+}
+
+test "syntax symbols: C, C++, Rust, Go, Python and JavaScript by their kind tables, members named in their types, an impl's in its type, locals none" {
+ if (!full_grammars) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ start(gpa);
+ defer stop();
+ const cases = [_]struct { path: []const u8, source: []const u8, want: []const u8 }{
+ .{ .path = "a.c", .source = "#define LIMIT 4\nstruct point { int x; int *y; };\ntypedef struct { int a; } pair;\nenum color { RED };\nstatic int counter = 0;\nconst int limit = 4;\nint add(int a) { int local = a; return local; }\nint later(void);\nstruct point p;\n", .want = "· LIMIT\nt point\nm point.x\nm point.y\nt pair\nm pair.a\nt color\nm color.RED\nv counter\nc limit\nf add\nf later\nv p\n" },
+ .{ .path = "a.cc", .source = "namespace torque {\nclass Parser : public Base {\n public:\n Parser();\n int Parse(int depth) const { return depth; }\n int depth_;\n};\nint Parser::Run(int n) { int local = n; return local; }\nusing Alias = int;\n}\nnamespace v8::internal {\nint flags;\n}\n", .want = "n torque\nt torque.Parser\nf torque.Parser.Parser\nf torque.Parser.Parse\nm torque.Parser.depth_\nf torque.Parser::Run\nt torque.Alias\nn v8::internal\nv v8::internal.flags\n" },
+ .{ .path = "a.rs", .source = "mod m {\npub struct S { pub a: u32 }\nenum E { A, B(u32) }\ntrait T { fn f(&self); }\nimpl S { pub fn new() -> Self { let x = 1; S { a: x } } }\nconst C: u32 = 1;\nstatic G: u32 = 2;\nmacro_rules! mac { () => {} }\n}\n", .want = "n m\nt m.S\nm m.S.a\nt m.E\nm m.E.A\nm m.E.B\nt m.T\nf m.T.f\nf m.S.new\nc m.C\nv m.G\n· m.mac\n" },
+ .{ .path = "a.go", .source = "package main\ntype S struct { A int }\ntype I interface { M() }\nconst C = 1\nvar V = 2\nfunc F() { var x = 1; _ = x }\nfunc (s *S) M() {}\n", .want = "t S\nm S.A\nt I\nf I.M\nc C\nv V\nf F\nf M\n" },
+ .{ .path = "a.py", .source = "X = 1\nclass C:\n attr = 2\n def m(self):\n y = 3\n self.z = 4\ndef f():\n pass\n", .want = "v X\nt C\nm C.attr\nf C.m\nf f\n" },
+ .{ .path = "a.js", .source = "const A = 1;\nlet b = 2;\nfunction f() { const local = 1; }\nclass K { field = 1; m() {} }\nconst arrow = () => 1;\nconst Klass = class {};\nconst { x, y } = A;\n", .want = "c A\nv b\nf f\nt K\nm K.field\nf K.m\nf arrow\nt Klass\n" },
+ };
+ for (cases) |case| {
+ const lines = try symbolLines(gpa, case.path, case.source);
+ defer gpa.free(lines);
+ std.testing.expectEqualStrings(case.want, lines) catch |err| {
+ std.debug.print("in {s}\n", .{case.path});
+ return err;
+ };
+ }
+}
+
+test "syntax symbols: every kind table names nodes of its grammar, and a grammar with none (JSON) lists no symbol" {
+ if (!full_grammars) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ start(gpa);
+ defer stop();
+ var tables: usize = 0;
+ for (symbol_rules) |entry| {
+ const spec = for (&specs) |*spec| {
+ if (std.mem.eql(u8, spec.name, entry[0])) break spec;
+ } else return error.NoGrammar;
+ for (entry[1]) |rule| std.testing.expect(langOf(spec).idForNodeKind(rule.node, true) != 0) catch |err| {
+ std.debug.print("{s} has no node {s}\n", .{ entry[0], rule.node });
+ return err;
+ };
+ tables += 1;
+ }
+ try std.testing.expectEqual(@as(usize, 23), tables);
+ var made = try context(gpa, "a.json", "{\"a\": 1}\n");
+ defer made.deinit(gpa);
+ try std.testing.expectEqual(@as(usize, 0), made.symbols.len);
+}
diff --git a/core/tagline.zig b/core/tagline.zig
index 0ec26d2f..8e8c5d2d 100644
--- a/core/tagline.zig
+++ b/core/tagline.zig
@@ -12,11 +12,14 @@ const config = @import("config.zig");
const Layer = @import("Layer.zig");
const layout = @import("layout.zig");
const TagState = @import("TagState.zig");
+const Messages = @import("Messages.zig");
const Pane = panes.Pane;
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,39 +44,161 @@ 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;
return panes.Output.fileTraits(f.output).saves and (f.revision != f.saved_revision or f.disk_gone);
}
-/// What a column's tag says until someone edits it.
+/// What a column's tag said before UX K', its own text then: a dump's own
+/// text equal to it is dropped (dump.dropOldTags), and a column's exec
+/// still takes its words (ninep/cols.zig paneWord).
pub const column_tag_default = "New Term Find Grep Joincol Delcol";
-/// What a header says until someone edits it: for the workspace the
-/// fixed builtins, plus `Restore <path>` once a dump exists.
-pub fn headerDefault(p: *Pardes, what: Text.What) []const u8 {
- if (what == .column) return column_tag_default;
- const row = topbarDefault(p);
- const d = p.last_dump orelse return row;
- return std.fmt.allocPrint(p.scratch.allocator(), "{s} Restore {s}", .{ row, d }) catch row;
+/// A header's computed words (UX K'2), read-only, made again from the
+/// session's state as a pane tag's are: the window's, then `Restore
+/// <path>` once a dump exists; a column's, with Joincol and Delcol where
+/// there is a second column for them.
+pub fn headerWords(p: *Pardes, what: Text.What) []const u8 {
+ if (what == .column) return if (p.view().ncol > 1) config.columns_words_str else config.column_words_str;
+ const d = p.last_dump orelse return config.window_words_str;
+ return std.fmt.allocPrint(p.scratch.allocator(), "{s} Restore {s}", .{ config.window_words_str, d }) catch config.window_words_str;
}
-/// The workspace row's words for this view: the window's row, with Fonts,
-/// in a window's view alone; a terminal's view (a terminal's build, or a
-/// terminal's replica of a window's session) has the row without it.
-fn topbarDefault(p: *Pardes) []const u8 {
- if (comptime @import("builtins.zig").capabilities.font_picker) if (@import("builtins.zig").registry.here(p, .Fonts)) return config.topbar_window_str;
- return config.topbar_terminal_str;
+/// A header as it is shown, read and edited: its computed words, a blank,
+/// then the user's text (UX K'1), everything typed into it, as a pane
+/// tag's own text follows its prefix.
+pub fn headerText(p: *Pardes, t: *const Text) ![]u8 {
+ const own: []const u8 = t.own orelse "";
+ return std.mem.concat(p.scratch.allocator(), u8, &.{ headerWords(p, t.what), " ", own });
}
-/// the topbar line -- render and click dispatch must agree on this exact
-/// string
+/// The window's tag -- render and click dispatch must agree on this exact
+/// string.
pub fn topbar(p: *Pardes) []const u8 {
- return p.global_tag.own orelse headerDefault(p, .workspace);
+ return headerText(p, &p.global_tag) catch config.window_words_str;
+}
+
+pub fn columnTag(p: *Pardes, c: usize) []const u8 {
+ return headerText(p, &p.view().col_tags[c]) catch config.column_words_str;
+}
+
+/// A header's width in glyphs as headerText makes it, made of nothing.
+fn headerWidth(p: *const Pardes, t: *const Text) usize {
+ const tab = p.settings.tab;
+ const own = if (t.own) |text| panes.File.displayWidth(tab, text) else 0;
+ const column: []const u8 = if (p.view().ncol > 1) config.columns_words_str else config.column_words_str;
+ if (t.what == .column) return column.len + 1 + own;
+ const restore = if (p.last_dump) |d| " Restore ".len + panes.File.displayWidth(tab, d) else 0;
+ return config.window_words_str.len + restore + 1 + own;
+}
+
+/// The window row's two sides (UX K'2), in cells from the window's left:
+/// column 0's tag from the inset, `column` cells (its text and its caret's
+/// cell; none but while layout.columnInWindowRow), and the window's tag
+/// from `words` to the right edge, its last cell the caret's, a server's
+/// progress after its text while one runs and the row has room for it
+/// (draw.zig). Draw, the mouse, workspaceBlank and a pixel shell's grid
+/// read it.
+pub const WindowRow = struct { column: u16, words: u16 };
+pub fn windowRow(p: *const Pardes) WindowRow {
+ const v = p.view();
+ const inset = @min(TAG_TEXT_INSET, v.screen_w);
+ const column = if (layout.columnInWindowRow(p)) @min(cellsFor(p, headerWidth(p, &v.col_tags[0]) + 1), v.screen_w - inset) else 0;
+ var glyphs = headerWidth(p, &p.global_tag) + 1;
+ // The progress where the row has room for it beside the column's
+ // words; else it is not drawn (draw.zig), and moves nothing.
+ if (sessionProgress(p)) |said| {
+ const with = glyphs + 2 + progressWidth(p, said);
+ if (cellsFor(p, with) <= v.screen_w -| (inset + column)) glyphs = with;
+ }
+ return .{ .column = column, .words = @max(v.screen_w -| cellsFor(p, glyphs), inset + column) };
+}
+
+/// A server's progress that is no pane's, the session's: shown at the
+/// window tag's end while it runs.
+pub fn sessionProgress(p: *const Pardes) ?*const Messages.Said {
+ for (p.messages.live[0..p.messages.live_len]) |*said| if (said.kind == .progress and said.pane == 0) return said;
+ return null;
}
-pub fn columnTag(p: *const Pardes, c: usize) []const u8 {
- return p.view().col_tags[c].own orelse column_tag_default;
+/// The width of a server's progress as the window's tag shows it: its
+/// glyph, a blank and its words.
+pub fn progressWidth(p: *const Pardes, said: *const Messages.Said) usize {
+ return panes.File.displayWidth(p.settings.tab, Messages.Kind.progress.glyph()) + 1 + panes.File.displayWidth(p.settings.tab, said.words());
+}
+
+/// The grid cells `glyphs` tagline glyphs take: layout.tagCapacity's
+/// inverse.
+fn cellsFor(p: *const Pardes, glyphs: usize) u16 {
+ const m = p.view().row_metrics;
+ const body: usize = @max(1, m.body_w);
+ const tag: usize = @max(1, m.tagline_w);
+ return @intCast(@min(std.math.maxInt(u16), (glyphs * tag + body - 1) / body));
}
/// The header with the keyboard, when one has it.
@@ -93,11 +218,14 @@ pub fn revealHeader(p: *Pardes) void {
};
const text = edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(v.active), "tag", err);
const cur: usize = @intCast(@max(0, t.cur_row));
- const rows: usize = if (p.headerColumn() != null) layout.columnBarHeight(p) else p.topBarHeight();
+ // Column 0's tag in the window row (UX K'2) has that row and its side.
+ const in_row = p.headerColumn() != null and layout.columnInWindowRow(p);
+ const rows: usize = if (p.headerColumn() != null and !in_row) layout.columnBarHeight(p) else p.topBarHeight();
if (cur < v.header_top) v.header_top = cur;
if (rows > 0 and cur >= v.header_top + rows) v.header_top = cur + 1 - rows;
const line = modal.lineSlice(text, cur);
- const width = layout.tagCapacity(p, if (p.headerColumn()) |c| v.col_w[c] -| TAG_TEXT_INSET else v.screen_w -| TAG_TEXT_INSET);
+ const sides = windowRow(p);
+ const width = layout.tagCapacity(p, if (p.headerColumn()) |c| (if (in_row) sides.column else v.col_w[c] -| TAG_TEXT_INSET) else v.screen_w -| sides.words);
const col = panes.File.rawDisplayCol(p.settings.tab, line, @min(@as(usize, @intCast(@max(0, t.cur_col))), line.len));
if (col < v.header_scroll) v.header_scroll = col;
if (col >= v.header_scroll + width) v.header_scroll = col -| (width -| 1);
@@ -120,9 +248,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 +368,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 +379,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 +468,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 +526,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 +547,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);
@@ -616,13 +760,18 @@ pub fn exitHeader(p: *Pardes) void {
}
/// Give the keyboard to a column's tag, or the workspace's for null, in
-/// normal mode, its cursor where that header last had it.
+/// normal mode, its cursor where that header last had it; the first time
+/// on the user's text, after the computed words (UX K'1), as enterTag.
pub fn enterHeader(p: *Pardes, column: ?usize) void {
exitHeader(p);
if (p.panes[p.view().active]) |pane| pane.focus = .body;
p.view().header = if (column) |c| .{ .column = c } else .workspace;
if (column) |c| p.setActiveColumn(c);
const t = focusedHeader(p) orelse return exitHeader(p);
+ if (!t.cur_pinned) {
+ t.cur_row = 0;
+ t.cur_col = @intCast(headerWords(p, t.what).len + 1);
+ }
takeKeyboard(t, edit.flatSurface(p.editor(), t) catch |err| return p.reportError(.at(p.view().active), "tag", err));
}
@@ -641,19 +790,23 @@ pub fn headerSelection(t: *const Text, text: []const u8, row: usize) ?struct { l
return .{ .lo = @max(lo, start) - start, .hi = @min(hi, end) - start };
}
-/// Whether the workspace tag is blank at cell (col, row): its inset left of
-/// the text, or past the text's end with two cells kept free for the caret
-/// (a B1 there still types at the end of the tag). A pixel shell lets the
-/// window be dragged by such a cell, as a browser by the space beside its
-/// tabs: blank is no text, so no button of acme's is taken from any. A
-/// column's tag and a pane's are not: their blank is where B1 types.
+/// Whether the window row is blank at cell (col, row): its inset, the
+/// cells between its two sides (UX K'2), or past the window's text with
+/// two cells kept free for the caret (a B1 there still types at the end of
+/// the tag). A pixel shell lets the window be dragged by such a cell, as a
+/// browser by the space beside its tabs: blank is no text, so no button of
+/// acme's is taken from any. A column's tag and a pane's are not: their
+/// blank is where B1 types.
pub fn workspaceBlank(p: *Pardes, col: u16, row: u16, tag_hit: ?pardes.TagHit) bool {
const v = p.view();
if (row >= p.topBarHeight() or col >= v.screen_w) return false;
if (col < TAG_TEXT_INSET) return true;
- const text = edit.flatSurface(p.editor(), &p.global_tag) catch return false;
+ const sides = windowRow(p);
+ if (col < TAG_TEXT_INSET + sides.column) return false;
+ if (col < sides.words) return true;
+ const text = topbar(p);
const scroll: usize = if (v.header != null and p.headerColumn() == null) v.header_scroll else 0;
- const at = @as(usize, Layer.columnAt(p, .workspace, 0, tag_hit, false, 0) orelse (col - TAG_TEXT_INSET)) + scroll;
+ const at = @as(usize, Layer.columnAt(p, .workspace, 0, tag_hit, false, 0) orelse (col - sides.words)) + scroll;
return at >= panes.File.displayWidth(p.settings.tab, modal.lineSlice(text, 0)) + 2;
}
@@ -661,15 +814,17 @@ pub fn workspaceBlank(p: *Pardes, col: u16, row: u16, tag_hit: ?pardes.TagHit) b
/// pasted or restored from a dump into one becomes a space, the caret and
/// the selection kept on the same characters.
pub fn flattenHeaders(p: *Pardes) void {
- for (p.view().col_tags[0..p.view().ncol]) |*t| flatten(t);
- flatten(&p.global_tag);
+ for (p.view().col_tags[0..p.view().ncol]) |*t| flatten(p, t);
+ flatten(p, &p.global_tag);
}
-fn flatten(t: *Text) void {
+fn flatten(p: *Pardes, t: *Text) void {
const own = t.own orelse return;
if (std.mem.indexOfScalar(u8, own, '\n') == null) return;
- const cur = modal.offsetAt(own, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) });
- const anchor = modal.offsetAt(own, .{ .row = @intCast(@max(0, t.vsel.row)), .col = @intCast(@max(0, t.vsel.col)) });
+ // The caret and the anchor are in the text as shown, words and all.
+ const shown = headerText(p, t) catch return;
+ const cur = modal.offsetAt(shown, .{ .row = @intCast(@max(0, t.cur_row)), .col = @intCast(@max(0, t.cur_col)) });
+ const anchor = modal.offsetAt(shown, .{ .row = @intCast(@max(0, t.vsel.row)), .col = @intCast(@max(0, t.vsel.col)) });
std.mem.replaceScalar(u8, own, '\n', ' ');
t.cur_row = 0;
t.cur_col = @intCast(cur);
@@ -691,25 +846,22 @@ pub fn wordBoundsAtCol(str: []const u8, col: usize) ?WordBounds {
return .{ .lo = lo, .hi = hi };
}
-test "the workspace tag is blank left of its text and past its end, and nowhere else" {
+test "the window row is blank at its inset and between its two sides, and nowhere else (UX K'2)" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 12, .tty_only = true });
defer p.deinit();
- p.global_tag.own = try p.gpa.dupe(u8, "Newcol Exit");
p.sync();
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
_ = try p.render(arena.allocator());
- const end = TAG_TEXT_INSET + "Newcol Exit".len;
- try std.testing.expect(workspaceBlank(p, 0, 0, null));
- try std.testing.expect(workspaceBlank(p, TAG_TEXT_INSET - 1, 0, null));
- // Every cell of the text, the gap between its words too, is not.
- for (TAG_TEXT_INSET..end) |c| try std.testing.expect(!workspaceBlank(p, @intCast(c), 0, null));
- // The two cells after it are the caret's, then blank to the edge.
- try std.testing.expect(!workspaceBlank(p, end, 0, null));
- try std.testing.expect(!workspaceBlank(p, end + 1, 0, null));
- try std.testing.expect(workspaceBlank(p, end + 2, 0, null));
- try std.testing.expect(workspaceBlank(p, 79, 0, null));
- // Below the workspace tag: a column's tag, a pane: never.
+ const sides = windowRow(p);
+ try std.testing.expect(sides.column > 0 and TAG_TEXT_INSET + sides.column < sides.words);
+ for (0..TAG_TEXT_INSET) |c| try std.testing.expect(workspaceBlank(p, @intCast(c), 0, null));
+ // The column's words and their caret's cell are not; the cells between
+ // the two sides are; the window's words and their caret's cell are not.
+ for (TAG_TEXT_INSET..TAG_TEXT_INSET + sides.column) |c| try std.testing.expect(!workspaceBlank(p, @intCast(c), 0, null));
+ for (TAG_TEXT_INSET + sides.column..sides.words) |c| try std.testing.expect(workspaceBlank(p, @intCast(c), 0, null));
+ for (sides.words..80) |c| try std.testing.expect(!workspaceBlank(p, @intCast(c), 0, null));
+ // Below the window row: a column's tag, a pane: never.
for (1..12) |r| try std.testing.expect(!workspaceBlank(p, 79, @intCast(r), null));
// Hidden, there is none.
p.settings.workspace_tag = false;
@@ -724,10 +876,11 @@ test "a column or workspace tag is one line: a newline in it is a space" {
p.view().col_tags[0].cur_col = 2;
p.global_tag.own = try p.gpa.dupe(u8, "Newcol\nExit");
p.sync();
- try std.testing.expectEqualStrings("New Snarf", columnTag(p, 0));
+ try std.testing.expectEqualStrings("New Term New Snarf", columnTag(p, 0));
try std.testing.expectEqualStrings("Newcol Exit", p.global_tag.own.?);
+ // The caret on the same character, `a` of Snarf.
try std.testing.expectEqual(@as(i32, 0), p.view().col_tags[0].cur_row);
- try std.testing.expectEqual(@as(i32, 6), p.view().col_tags[0].cur_col);
+ try std.testing.expectEqual(@as(i32, "New Term New Sn".len), p.view().col_tags[0].cur_col);
try std.testing.expectEqual(pardes.COLBAR_H, layout.columnBarHeight(p));
try std.testing.expectEqual(pardes.TOPBAR_H, p.topBarHeight());
}
@@ -741,3 +894,203 @@ 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.?);
+}
+
+test "a header reads its computed words, then the user's text: typed there, kept through a change of its words (UX K'1, K'2)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 30, .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit ", topbar(p));
+ try std.testing.expectEqualStrings("New Term ", columnTag(p, 0));
+ // The window's tag given the keyboard starts on the user's text.
+ enterHeader(p, null);
+ typeKeys(p, "iMine");
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expectEqualStrings("Mine", p.global_tag.own.?);
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Mine", topbar(p));
+ // A Backspace on the blank before it is refused: the words are no one's.
+ p.global_tag.cur_col = "Find Grep Newcol Help Exit ".len;
+ typeKeys(p, "i");
+ p.update(.{ .key = .{ .cp = pardes.Key.backspace } });
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Mine", topbar(p));
+ // A dump: its Restore comes into the words, the user's text after it.
+ p.setLastDump("/tmp/a.zon");
+ try std.testing.expectEqualStrings("Find Grep Newcol Help Exit Restore /tmp/a.zon Mine", topbar(p));
+ // A second column: Joincol and Delcol come into every column's words.
+ exitHeader(p);
+ try std.testing.expect(p.executeBuiltinLine(0, "Newcol"));
+ p.sync();
+ try std.testing.expectEqualStrings("New Term Joincol Delcol ", columnTag(p, 0));
+ try std.testing.expectEqualStrings("New Term Joincol Delcol ", columnTag(p, 1));
+ // Newcol gave the keyboard to the new column's tag, on its user's text.
+ try std.testing.expectEqual(@as(?usize, 1), p.headerColumn());
+ typeKeys(p, "iTwo");
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expectEqualStrings("New Term Joincol Delcol Two", columnTag(p, 1));
+ try std.testing.expectEqualStrings("Two", p.view().col_tags[1].own.?);
+}
+
+test "a dump of a build before UX K' restores a header'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();
+ _ = try p.setTestFile("one\n");
+ // What the window's and a column's tags said before, with a Restore.
+ p.global_tag.own = try p.gpa.dupe(u8, config.topbar_terminal_str ++ " Restore /tmp/old.zon");
+ p.view().col_tags[0].own = try p.gpa.dupe(u8, column_tag_default);
+ try dump.dumpState(p);
+ const dropped = try dump.restore(p, p.dump_out.?, "old");
+ defer dropped.deinit();
+ try std.testing.expect(dropped.global_tag.own == null);
+ try std.testing.expect(dropped.view().col_tags[0].own == null);
+ try std.testing.expectEqualStrings("New Term ", columnTag(dropped, 0));
+ // The window's row with Fonts, and no Restore, is dropped too.
+ p.gpa.free(p.global_tag.own.?);
+ p.global_tag.own = try p.gpa.dupe(u8, config.topbar_window_str);
+ try dump.dumpState(p);
+ const window = try dump.restore(p, p.dump_out.?, "window");
+ defer window.deinit();
+ try std.testing.expect(window.global_tag.own == null);
+ // Edited around: kept whole, after the computed words.
+ p.gpa.free(p.global_tag.own.?);
+ p.global_tag.own = try p.gpa.dupe(u8, config.topbar_terminal_str ++ " Mine");
+ p.gpa.free(p.view().col_tags[0].own.?);
+ p.view().col_tags[0].own = try p.gpa.dupe(u8, "New Mine");
+ try dump.dumpState(p);
+ const kept = try dump.restore(p, p.dump_out.?, "custom");
+ defer kept.deinit();
+ try std.testing.expectEqualStrings(config.topbar_terminal_str ++ " Mine", kept.global_tag.own.?);
+ try std.testing.expectEqualStrings("New Term New Mine", columnTag(kept, 0));
+}
+
+test "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)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 84, .rows = 20, .tty_only = true });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ const alone = windowRow(p).words;
+ try std.testing.expectEqual(@as(u16, 84 - "Find Grep Newcol Help Exit ".len - 1), alone);
+ // Too long for the row beside the column's words: not drawn, and the
+ // words stay where they were.
+ _ = Messages.say(p, .progress, pardes.MAX_PANES, "lsp zls ready \u{2014} /tmp/claude-1000/a/long/session/directory");
+ try std.testing.expectEqual(alone, windowRow(p).words);
+ // Short: after the words, two cells between, the words left by as
+ // much (`⋯ zls 3/9`, 9 cells).
+ _ = Messages.say(p, .progress, pardes.MAX_PANES, "zls 3/9");
+ try std.testing.expectEqual(alone - 2 - 9, windowRow(p).words);
+}
diff --git a/core/tutor.txt b/core/tutor.txt
index 5b0fd23d..62f71402 100644
--- a/core/tutor.txt
+++ b/core/tutor.txt
@@ -59,18 +59,19 @@
The workspace tag, a column's, and a file's, a terminal's, a PDF's
and an image's:
-| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit
-| New Term Find Grep Joincol Delcol
-| Save Term Collapse Follow Del
-| Term Save Mode Filter Collapse Del
-| Term PdfSections PdfTint PdfFit Collapse Del
-| Term Collapse Follow Del
+| Find Grep Newcol Help Exit
+| New Term Joincol Delcol
+| Save Undo Del
+| Del Term
+| PdfSections PdfTint PdfFit Del
+| Del
- 1. Press : here: the keyboard goes to this pane's tag, on `Save`.
- Press A, type a space and Help, press Esc, then Tab: `Help`
+ 1. Press : twice here: the keyboard goes to this pane's tag, after
+ its words. Press i, type Help, press Esc, then Tab: `Help`
runs and its list takes the keyboard. Esc brings you back.
- 2. Click `Collapse` in this tag: the pane folds to its tag. Click
- it again.
+ 2. A tag shows the words that act now; its kind's others run from
+ :, listed for this pane. Press :, type Coll, press Enter: the
+ pane folds to its tag. The same again unfolds it.
3. Drag the box left of the tag down a few rows, then back.
-> Guide: Tags