summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Band.zig133
-rw-r--r--core/Messages.zig20
-rw-r--r--core/Names.zig92
-rw-r--r--core/Pick.zig461
-rw-r--r--core/Places.zig9
-rw-r--r--core/Prompt.zig42
-rw-r--r--core/TagState.zig36
-rw-r--r--core/Trail.zig27
-rw-r--r--core/bindings.zig70
-rw-r--r--core/body_layer.zig168
-rw-r--r--core/builtins.zig6
-rw-r--r--core/colors.zig348
-rw-r--r--core/draw.zig184
-rw-r--r--core/fs.zig6
-rw-r--r--core/jj.zig11
-rw-r--r--core/look.zig34
-rw-r--r--core/lsp/Ask.zig47
-rw-r--r--core/ninep/ctl.zig4
-rw-r--r--core/normal.zig4
-rw-r--r--core/panes.zig13
-rw-r--r--core/root.zig1
-rw-r--r--core/syntax.zig39
22 files changed, 1570 insertions, 185 deletions
diff --git a/core/Band.zig b/core/Band.zig
index 2b688a61..507f1bee 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -39,6 +39,9 @@ pub const Row = struct {
on: bool = false,
/// Its first `key` bytes are a key: the key ink, bold.
key: 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,
dim: bool = false,
/// The leaf its group ran last.
under: bool = false,
@@ -53,6 +56,14 @@ pub const Row = struct {
/// tint; the `faint` bytes after them dimmed (a path's directory).
pre: u16 = 0,
faint: u16 = 0,
+ /// Said at the row's right end in the dim ink, two cells off its text
+ /// at least, and the first to give way (UX D5): `in use`.
+ meta: []const u8 = "",
+ /// Its bytes `quiet[0]..quiet[1]` in the dim ink: an empty register's
+ /// `—`, a value's `⏎`.
+ quiet: [2]u16 = .{ 0, 0 },
+ /// Bytes that are keys, each in the key ink, bold: a register's verbs.
+ keys: []const u16 = &.{},
};
/// A column of rows. A level of more than 9 rows flows into two columns
@@ -225,7 +236,9 @@ fn helpSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, s: *const TagSta
const low = try std.ascii.allocLowerString(arena, leaf.row);
_ = Names.match(q, leaf.row, low, 0, &marks, &nmarks);
}
- row.* = .{ .text = leaf.row, .on = i == s.rows.at, .marks = try arena.dupe(u16, marks[0..nmarks]), .index = @intCast(i), .dim = bindings.dimmed(p.panes[p.view().active].?, leaf.child) };
+ // Its chord (`SPC h t`, before the first ` · `) in the key ink.
+ const chord = std.mem.indexOf(u8, leaf.row, " · ") orelse 0;
+ row.* = .{ .text = leaf.row, .on = i == s.rows.at, .chord = @intCast(@min(chord, 255)), .marks = try arena.dupe(u16, marks[0..nmarks]), .index = @intCast(i), .dim = bindings.dimmed(p.panes[p.view().active].?, leaf.child) };
}
band.add(.{ .rows = rows });
var buf: [TagState.row_max]u8 = undefined;
@@ -233,6 +246,18 @@ fn helpSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, s: *const TagSta
band.add(try docStep(p, arena, at.root, at.path[0 .. at.path.len - 1], at.child));
}
+/// What a register's doc step offers next, its letters keys (UX D11).
+const verbs = "p after P before R replace y into";
+const verb_keys = blk: {
+ var out: [4]u16 = undefined;
+ var n: usize = 0;
+ for (0..verbs.len) |i| if (i == 0 or (i >= 2 and std.mem.eql(u8, verbs[i - 2 .. i], " "))) {
+ out[n] = i;
+ n += 1;
+ };
+ break :blk out;
+};
+
/// `"` unrolled (SPEC §9): the registers, a row each (its key, what it
/// is, its first line) around the cursor, or under `"a` its verbs; beside
/// them the value of the one on the cursor (or named) in full, as many of
@@ -250,17 +275,25 @@ fn registerSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *const
if (path.len > 0) band.add(try levelStep(arena, pane, level, at, used)) else {
const w = (Cursor{ .at = @intCast(at) }).window(@intCast(level.len));
const rows = try arena.alloc(Row, w.hi - w.lo);
+ // A row each (UX D11): `key value`, its name at the right; an
+ // empty one's `—` and a newline's `⏎` dim.
for (rows, w.lo..) |*row, i| {
const c = level[i];
const name = for (bindings.register_names) |r| {
if (r.key == c.key) break r.name;
} else "named";
+ const key = bindings.keyName(c.key);
+ const shown = try bindings.registerShown(arena, p.settings.tab, bindings.registerValue(p, c.key));
+ const text = try std.fmt.allocPrint(arena, "{s} {s}", .{ key, shown });
+ const quiet = if (std.mem.eql(u8, shown, "—")) key.len + 2 else if (std.mem.endsWith(u8, shown, "⏎")) text.len - "⏎".len else text.len;
row.* = .{
- .text = try std.fmt.allocPrint(arena, "{s} {s: <17} {s}{s}", .{ bindings.keyName(c.key), name, c.label, if (c.more) "…" else "" }),
+ .text = text,
.on = i == at,
- .key = 1,
+ .key = @intCast(key.len),
.under = c.key == used,
.index = @intCast(i),
+ .meta = name,
+ .quiet = .{ @intCast(quiet), @intCast(text.len) },
};
}
band.add(.{ .rows = rows });
@@ -286,7 +319,7 @@ fn registerSteps(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *const
try rows.append(arena, .{ .text = look[0..end] });
rest = rest[end + 1 ..];
}
- if (path.len == 0) try rows.append(arena, .{ .text = "next p after P before R replace y into", .dim = true });
+ if (path.len == 0) try rows.append(arena, .{ .text = verbs, .dim = true, .keys = &verb_keys });
band.add(.{ .rows = rows.items, .doc = true });
}
@@ -371,6 +404,8 @@ pub fn docStep(p: *Pardes, arena: std.mem.Allocator, root: bindings.Root, path:
.role => bindings.docOf(root, c, try arena.alloc(u8, 160)),
} else bindings.docOf(root, c, &.{});
try rows.append(arena, .{ .text = doc });
+ // A leaf a language server answers, in a pane with none (SPEC §4.2).
+ if (bindings.dimmed(p.panes[p.view().active].?, c)) try rows.append(arena, .{ .text = "needs a language server", .dim = true });
var buf: [64]u8 = undefined;
const here = try std.mem.concat(arena, u8, &.{ path, &.{c.key} });
try rows.append(arena, .{ .text = try std.fmt.allocPrint(arena, "keys {s}", .{bindings.chord(root, here, &buf)}) });
@@ -395,7 +430,7 @@ fn place(band: *Band, p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usi
for (band.steps[0..band.nsteps]) |*step| {
if (step.doc) continue;
var widest: usize = 0;
- for (step.rows) |row| widest = @max(widest, File.displayWidth(tab, row.text));
+ for (step.rows) |row| widest = @max(widest, File.displayWidth(tab, row.text) + if (row.meta.len > 0) 2 + File.displayWidth(tab, row.meta) else 0);
const column: u16 = @intCast(@min(widest, row_cells) + 2);
step.width = if (step.two) 2 * column + 1 else column;
need += step.width + 2;
@@ -516,13 +551,27 @@ pub fn line(band: *const Band, arena: std.mem.Allocator, tab: u16, y: u16) !Line
const room = per -| @as(u16, @intCast(File.displayWidth(tab, lead)));
const fit = try cutRow(arena, tab, row, room);
try parts.append(arena, .{ .col = col, .width = room, .row = fit });
+ const at = col;
try text.appendSlice(arena, fit.text);
col += @intCast(File.displayWidth(tab, fit.text));
+ // Its meta at the part's right end, when it fits after the
+ // whole text: it gives way before the text is cut (UX D5).
+ if (metaShown(tab, row, room)) {
+ const meta: u16 = @intCast(File.displayWidth(tab, row.meta));
+ while (col < at + room - meta) : (col += 1) try text.append(arena, ' ');
+ try text.appendSlice(arena, row.meta);
+ col += meta;
+ }
}
}
return .{ .text = text.items, .parts = parts.items };
}
+/// Whether row `row`'s meta fits `room` cells after its text.
+pub fn metaShown(tab: u16, row: Row, room: u16) bool {
+ return row.meta.len > 0 and File.displayWidth(tab, row.text) + 2 + File.displayWidth(tab, row.meta) <= room;
+}
+
/// Row `row` held to `room` cells (UX D2): a longer one cut with `…`, a
/// path (its directory faint: Find's rows) from the left
/// (`…core/Store.zig`), anything else from the right; its marks and faint
@@ -786,3 +835,77 @@ test "a doc's paragraphs are rows of their own: no newline in a band's row" {
};
try std.testing.expect(docs > 2);
}
+
+test "a band is drawn in the theme's roles (UX D4): spines in the rule ink, a chord in the key ink, a matched letter bold in the match ink on its row's own ground, the cursor row's too; an LSP leaf with no server in the dim ink, never faint, its doc saying why" {
+ const Key = pardes.Key;
+ const Cells = struct {
+ /// The cell `word` starts at, a grapheme a cell.
+ fn find(cells: []const pardes.Cell, word: []const u8) ?usize {
+ var at: usize = 0;
+ while (at + word.len <= cells.len) : (at += 1) {
+ for (word, cells[at..][0..word.len]) |c, cell| {
+ if (cell.len != 1 or cell.text[0] != c) break;
+ } else return at;
+ }
+ return null;
+ }
+ };
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 40 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ const id = p.view().active;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const roles = &p.chromeTheme().roles;
+ const inks = roles.on(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused);
+ const selected = roles.selectedOn(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused);
+ // Help with `wrap` typed: `▶ SPC t w · Wrap · view` on the cursor row.
+ for ([_]u21{ ' ', '?', 'w', 'r', 'a', 'p' }) |c| p.update(.{ .key = .{ .cp = c } });
+ _ = try p.render(a);
+ var layer = bandLayer(p, id).?;
+ var spines: usize = 0;
+ var cursor_row: ?usize = null;
+ for (0..layer.rows) |row| for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| {
+ try std.testing.expect(!cell.style.dim);
+ if (std.mem.eql(u8, cell.grapheme(), "│")) {
+ try std.testing.expectEqual(pardes.Color{ .rgb = inks.rule }, cell.style.fg);
+ spines += 1;
+ }
+ if (std.mem.eql(u8, cell.grapheme(), "▶")) {
+ cursor_row = row;
+ // The cursor's `▶` in the key ink on the selection, which
+ // covers its lead too (UX D4, D5).
+ try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, cell.style.fg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = selected.ground }, cell.style.bg);
+ }
+ };
+ try std.testing.expect(spines > 0);
+ const on = layer.cells[cursor_row.? * layer.cols ..][0..layer.cols];
+ const s_cell = on[Cells.find(on, "SPC t w").?];
+ try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, s_cell.style.fg);
+ try std.testing.expect(!s_cell.style.bold);
+ var matched: usize = 0;
+ for (on) |cell| if (std.meta.eql(cell.style.fg, pardes.Color{ .rgb = roles.match })) {
+ try std.testing.expect(cell.style.bold);
+ try std.testing.expectEqual(pardes.Color{ .rgb = selected.ground }, cell.style.bg);
+ matched += 1;
+ };
+ try std.testing.expect(matched >= 4);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // SPC l unrolled in a text file no server speaks for: its leaves dim.
+ for ([_]u21{ ' ', 'l', Key.down }) |c| p.update(.{ .key = .{ .cp = c } });
+ _ = try p.render(a);
+ layer = bandLayer(p, id).?;
+ var dimmed: usize = 0;
+ var why = false;
+ for (0..layer.rows) |row| {
+ const cells = layer.cells[row * layer.cols ..][0..layer.cols];
+ if (Cells.find(cells, "needs a language server") != null) why = true;
+ const cell = cells[Cells.find(cells, "Hover") orelse continue];
+ try std.testing.expect(!cell.style.dim);
+ try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cell.style.fg);
+ dimmed += 1;
+ }
+ try std.testing.expect(dimmed > 0 and why);
+}
diff --git a/core/Messages.zig b/core/Messages.zig
index 6d8d570d..2cb196f6 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -413,10 +413,10 @@ pub fn markOf(m: *const Messages, pane: *const Pane) ?Kind {
/// A kind's ink, for its glyph, its mark and its words at a line.
pub fn ink(chrome: *const pardes.colors.ChromeTheme, kind: Kind) [3]u8 {
return switch (kind) {
- .@"error" => chrome.diagnostic_error,
- .warn => chrome.diagnostic_warning,
- .question => chrome.diagnostic_info,
- else => chrome.diagnostic_hint,
+ .@"error" => chrome.roles.err,
+ .warn => chrome.roles.warn,
+ .question => chrome.roles.question,
+ else => chrome.roles.hint,
};
}
@@ -679,6 +679,10 @@ pub const Row = struct {
text: []const u8 = "",
/// The message the left says, when it says one.
lead: ?*const Said = null,
+ /// The left in the dim ink (a picker's sentence, UX D7), but for the
+ /// bytes `word` (an address, in the text's).
+ quiet_left: bool = false,
+ word: [2]usize = .{ 0, 0 },
};
/// Room for the notice row's line: the widest window's at the tagline's
@@ -704,8 +708,10 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row {
live += 1;
if (s.kind == .question) questions += 1;
}
- const lead = m.headline();
- if (lead) |s| {
+ // While a picker previews, its sentence (UX D7), before any message.
+ const said = pardes.Pick.sentence(p, &w);
+ const lead = if (said == null) m.headline() else null;
+ if (said != null) {} else if (lead) |s| {
w.print("{s} ", .{s.kind.glyph()}) catch {};
// Its cause first, unless its words name it already.
const words = s.words();
@@ -747,7 +753,7 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row {
for (0..gap) |_| w.writeByte(' ') catch {};
const right_at = w.end;
w.writeAll(tail) catch {};
- return .{ .left = cut, .right = right_at, .text = w.buffered(), .lead = lead };
+ return .{ .left = cut, .right = right_at, .text = w.buffered(), .lead = lead, .quiet_left = said != null, .word = said orelse .{ 0, 0 } };
}
/// What notice band `i` says. The grid pass and the band layers both
diff --git a/core/Names.zig b/core/Names.zig
index 47165f52..d063bd17 100644
--- a/core/Names.zig
+++ b/core/Names.zig
@@ -29,6 +29,10 @@ query_buf: [max_query]u8 = undefined,
query_len: u8 = 0,
/// Bumped whenever `hits` change: the rows are made again only then.
gen: u32 = 0,
+/// How many of `hits` are in order, best first: as many as a list shows
+/// (`max_rows`), or as far as its cursor went (`reachTo`); the matches after
+/// them are counted, in no order.
+reach: u32 = max_rows,
/// The query is `query_buf[0..query_len]`: what lies past it is undefined
/// (0xAA in Debug, not in a release build), so no digest reads it.
@@ -81,6 +85,7 @@ pub fn reset(n: *Names) void {
n.pending.clearRetainingCapacity();
n.pending_at = 0;
n.scored = 0;
+ n.reach = max_rows;
n.gen +%= 1;
}
@@ -124,6 +129,7 @@ pub fn typed(n: *Names, gpa: std.mem.Allocator, text: []const u8) void {
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);
+ n.reach = max_rows;
if (grew) {
const pending = n.pending.items[n.pending_at..];
std.mem.copyForwards(u32, n.pending.items[0..pending.len], pending);
@@ -165,19 +171,65 @@ pub fn rescore(n: *Names, gpa: std.mem.Allocator) void {
if (!empty and left == 0) break;
}
// An empty query keeps the source's order (the walk's, recency): no
- // row moves as the walk goes on, it only grows at the foot.
- if (!empty) std.sort.pdq(Hit, n.hits.items, n.cands.items, struct {
- fn lt(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;
- if (la != lb) return la < lb;
- return a.cand < b.cand;
- }
- }.lt);
+ // row moves as the walk goes on, it only grows at the foot. Else the
+ // best `reach` first: a sort of every hit was most of a first key's
+ // 8 ms over 50,000 paths.
+ if (!empty) bestFirst(n.hits.items, n.cands.items, n.reach);
if (n.hits.items.len != had or n.scored != was_scored or count > 0) n.gen +%= 1;
}
+/// Hits sorted as far as row `rows`, for a cursor gone past the ones that
+/// were (an empty query's are in the source's order already).
+pub fn reachTo(n: *Names, rows: usize) void {
+ if (rows <= n.reach or std.mem.trim(u8, n.queryText(), " ").len == 0) return;
+ n.reach = @intCast(@min(rows, max_cands));
+ bestFirst(n.hits.items, n.cands.items, n.reach);
+ n.gen +%= 1;
+}
+
+/// Hit `a` goes before `b`: the higher score, then the shorter key, then
+/// the candidate added first.
+fn before(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;
+ if (la != lb) return la < lb;
+ return a.cand < b.cand;
+}
+
+/// `hits`' best `k` to the front, in order, the rest after them in no
+/// order: the best so far kept as a heap whose root is the worst of them,
+/// then sorted. O(n log k).
+fn bestFirst(hits: []Hit, cands: []const Cand, k_in: usize) void {
+ const k = @min(k_in, hits.len);
+ if (k == 0) return;
+ const heap = hits[0..k];
+ var i = k / 2;
+ while (i > 0) {
+ i -= 1;
+ sink(heap, cands, i);
+ }
+ for (hits[k..]) |*h| if (before(cands, h.*, heap[0])) {
+ std.mem.swap(Hit, h, &heap[0]);
+ sink(heap, cands, 0);
+ };
+ std.sort.pdq(Hit, heap, cands, before);
+}
+
+/// Heap entry `at` taken down past the worse of its children while it is
+/// better than that child.
+fn sink(heap: []Hit, cands: []const Cand, from: usize) void {
+ var at = from;
+ while (true) {
+ const l = 2 * at + 1;
+ if (l >= heap.len) return;
+ const c = if (l + 1 < heap.len and before(cands, heap[l], heap[l + 1])) l + 1 else l;
+ if (!before(cands, heap[at], heap[c])) return;
+ std.mem.swap(Hit, &heap[at], &heap[c]);
+ at = c;
+ }
+}
+
/// 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];
@@ -363,3 +415,23 @@ test "Names ranks real paths as the pick prototype did" {
try std.testing.expectEqualStrings("src/gui/Post.zig", topFor("gui/po"));
try std.testing.expectEqualStrings("src/Output.zig", topFor("Out"));
}
+
+test "Names keeps its best `reach` hits first in a full sort's order, the rest after them, and sorts further as a cursor goes past them" {
+ const gpa = std.testing.allocator;
+ var n: Names = .{};
+ defer n.deinit(gpa);
+ var buf: [64]u8 = undefined;
+ for (0..3000) |i| {
+ const path = try std.fmt.bufPrint(&buf, "dir{d}/sub{d}/file_{d}.zig", .{ i % 7, i % 13, i });
+ try n.add(gpa, path, 0, path.len, baseOf(path), 0);
+ }
+ n.typed(gpa, "f1");
+ while (n.busy()) n.rescore(gpa);
+ const all = try gpa.dupe(Hit, n.hits.items);
+ defer gpa.free(all);
+ std.sort.pdq(Hit, all, n.cands.items, before);
+ try std.testing.expect(all.len > max_rows);
+ try std.testing.expectEqualSlices(Hit, all[0..max_rows], n.hits.items[0..max_rows]);
+ n.reachTo(max_rows + 500);
+ try std.testing.expectEqualSlices(Hit, all[0 .. max_rows + 500], n.hits.items[0 .. max_rows + 500]);
+}
diff --git a/core/Pick.zig b/core/Pick.zig
index 52e9601d..c5b639cd 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -35,6 +35,10 @@ const Stream = @import("Stream.zig");
const Trail = @import("Trail.zig");
const TagState = @import("TagState.zig");
const Band = @import("Band.zig");
+const Places = @import("Places.zig");
+const colors = @import("colors.zig");
+const Surface = @import("surface.zig").Surface;
+const Cell = @import("surface.zig").Cell;
const Query = panes.Query;
const File = panes.File;
const Output = panes.Output;
@@ -48,9 +52,10 @@ const Key = pardes.Key;
/// declarations, the lines holding the query in every open pane (All, its
/// places in each), the jump list, rows handed over (a language server's
/// answer, SPC e's places), titled by their word, the messages' history
-/// (SPC h m), and the themes (SPC t t, the window wearing the one under
-/// the cursor).
-pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list, messages, themes };
+/// (SPC h m), the themes (SPC t t, the window wearing the one under
+/// the cursor), and a language server's code actions for the caret's place
+/// (SPC l a, the body showing the one under the cursor as its edit).
+pub const Source = enum { find, grep, recent, panes, symbols, all, jumplist, list, messages, themes, actions };
/// Each source's word in the tag and the leader keys of the builtin that
/// opens it, its key cells (`␣ f Find`).
@@ -65,6 +70,7 @@ const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8
.list = .{ .word = "List", .keys = "l" },
.messages = .{ .word = "Messages", .keys = "hm" },
.themes = .{ .word = "Themes", .keys = "t" },
+ .actions = .{ .word = "Actions", .keys = "la" },
});
/// The pickers kept after they roll up, for their list words and Resume.
@@ -94,8 +100,11 @@ names: Names = .{},
/// A Grep's lines, as the disk engine sends them (Query.take).
found: std.ArrayList(Query.Found) = .empty,
found_bytes: std.ArrayList(u8) = .empty,
-/// A list's rows, as they were handed over (`path:line:col text`).
+/// A list's rows, as they were handed over (`path:line:col text`); code
+/// actions' each followed by its edit's records (lsp_client actionEdits).
rows: []u8 = &.{},
+/// The revision of the asking text its actions' edits are of.
+revision: u32 = 0,
/// The query and the cursor as it rolled up (live, they are its view's
/// field and cursor).
query: Kind.Buf(256) = .{},
@@ -149,10 +158,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, never a script's (a 9P write'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), 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;
+ return p.settings.jumps == .walk and (!p.fs.serving or p.fs.typed);
}
/// Picker `id`, kept or live.
@@ -224,8 +234,8 @@ fn hostIn(p: *Pardes, pk: *Pick, from: usize) !void {
pk.owner = asker.serial;
pk.made = false;
// A theme is no place: its list is the asking pane's own tag (§3.5),
- // and its preview the whole window.
- if (pk.source == .themes) {
+ // and its preview the whole window; an action's is that text's edit.
+ if (pk.source == .themes or pk.source == .actions) {
pk.landing = asker.serial;
p.view().active = from;
return;
@@ -301,6 +311,21 @@ fn start(p: *Pardes, pk: *Pick) void {
.themes => for (pardes.colors.themes, 0..) |t, i| {
pk.names.add(p.gpa, t.name, 0, t.name.len, 0, @intCast(i)) catch return;
},
+ // Each action by its title, its digit before it (the first nine,
+ // which `1`-`9` apply), the title what the query matches.
+ .actions => {
+ var lines = std.mem.splitScalar(u8, pk.rows, '\n');
+ var i: u32 = 0;
+ while (lines.next()) |ln| {
+ if (ln.len == 0 or ln[0] == '@') continue;
+ const title = std.mem.trimStart(u8, ln[Output.location(ln).end..], " ");
+ var buf: [2 + 512]u8 = undefined;
+ const cut = title[0..@min(title.len, 512)];
+ const text = if (i < 9) std.fmt.bufPrint(&buf, "{d} {s}", .{ i + 1, cut }) catch unreachable else cut; // 2 + 512 fit
+ pk.names.add(p.gpa, text, text.len - cut.len, cut.len, 0, i) catch return;
+ i += 1;
+ }
+ },
}
}
@@ -399,7 +424,7 @@ 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);
// A theme's preview in the step of the key that moved to it.
- if (pk.source == .themes) pardes.colors.previewTheme(p, themeAt(p, pk));
+ if (pk.source == .themes) pardes.colors.previewTheme(p, refAt(p, pk));
if (tick) preview(p, pk);
};
}
@@ -414,8 +439,9 @@ pub fn busy(p: *const Pardes) bool {
// ---- the rows ----
-/// The theme the cursor of a themes picker is on.
-fn themeAt(p: *const Pardes, pk: *const Pick) ?usize {
+/// What the row under the cursor is of: a themes picker's theme, an
+/// actions picker's action.
+fn refAt(p: *const Pardes, pk: *const Pick) ?usize {
const n = pk.names.hits.items.len;
if (n == 0) return null;
const at = @min(p.view().tag_state.rows.at, n - 1);
@@ -457,7 +483,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, pre: u16 = 0, faint: u16 = 0, dim: bool = false, marks: []const u16 = &.{}, target: Target = .none };
+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 = "" };
fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row {
const dir = pk.dir.slice();
@@ -525,7 +551,23 @@ fn rowAt(p: *Pardes, pk: *const Pick, arena: std.mem.Allocator, i: usize) !Row {
const f = owner.file orelse return row;
row.target = .{ .place = .{ .path = f.path, .at = .{ .line = cand.ref } } };
},
- .themes => {},
+ // The theme in use says so, whichever the window wears (POLISH 12).
+ .themes => if (p.custom_theme == null and cand.ref == p.settings.theme) {
+ row.meta = "in use";
+ },
+ // An action: its digit a key; its place the first line its edit
+ // changes, which the body is moved to while it is previewed.
+ .actions => {
+ row.key = @intFromBool(cand.ref < 9);
+ const owner = p.panes[p.paneBySerial(pk.landing) orelse return row].?;
+ // With the `Changes` layer's lines shown the body stays where it is.
+ const f = if (owner.file) |*file| file else return row;
+ if (f.layer.lines.len > 0 or f.revision != pk.revision) return row;
+ const edits = pardes.lsp.Ask.parseLspEdits(arena, (action(pk, cand.ref) orelse return row).records, null) orelse return row;
+ if (edits[0].start > f.content.len) return row;
+ const line = @import("Places.zig").lineOf(try File.lineIndex(p.gpa, f), edits[0].start);
+ row.target = .{ .place = .{ .path = f.path, .at = .{ .line = line + 1 } } };
+ },
.recent, .jumplist, .list, .grep, .all => {
const t = look.parsePathLine(text);
row.pre = @intCast(t.end);
@@ -580,10 +622,10 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
if (n == 0) try text.append(arena, '0') else try text.print(arena, "{d}/{d}", .{ s.rows.at + 1, n });
if (pk.marks.items.len > 0) try text.print(arena, " •{d}", .{pk.marks.items.len});
if (pk.names.busy() or p.stream.busyFor(pk.id)) try text.appendSlice(arena, " ⋯");
- // Themes have no acts and no other sources: no second row.
- if (pk.source == .themes) {
+ // Themes and actions have no acts and no other sources: no second row.
+ if (pk.source == .themes or pk.source == .actions) {
const hints = text.items.len;
- try b.styled("⏎ wear it · esc", .dim);
+ try b.styled(if (pk.source == .themes) "⏎ wear it · esc" else "⏎ or 1-9 apply it · esc", .dim);
try b.right(counted, hints);
var h = b.done();
h.caret = caret;
@@ -592,9 +634,9 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
try b.right(counted, text.items.len);
// The second row, one row (UX D2): under the spines from the key
// cells, from two cells right of the last, the acts, `|`, the other
- // sources' words, each switching to it; what does not fit is dropped
- // from the right (the sources first) and the row ends in a dim `…`
- // (M-l and M-h reach them all).
+ // sources' words, each switching to it, the `|` and the sources dim
+ // (UX D4); what does not fit is dropped from the right (the sources
+ // first) and the row ends in a dim `…` (M-l and M-h reach them all).
try b.row(if (b.ncols > 0) b.cols[b.ncols - 1] + 2 else 0);
var offer: [acts.len + 1 + std.enums.values(Source).len][]const u8 = undefined;
var nw: usize = 0;
@@ -602,9 +644,10 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
offer[nw] = act.word;
nw += 1;
};
+ const nacts = nw;
offer[nw] = "|";
nw += 1;
- inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != pk.source) {
+ inline for (comptime std.enums.values(Source)) |src| if (src != .list and src != .messages and src != .themes and src != .actions and src != pk.source) {
offer[nw] = words.get(src).word;
nw += 1;
};
@@ -617,7 +660,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head {
break;
}
try b.put(if (gap > 0) " " else "");
- try b.put(word);
+ if (i >= nacts) try b.styled(word, .dim) else try b.put(word);
}
var h = b.done();
h.caret = caret;
@@ -670,7 +713,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, .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) };
+ 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 };
}
out[0] = .{ .rows = rows };
return out;
@@ -678,6 +721,47 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator) ![]Band.Step {
// ---- the preview ----
+/// The line (from 0) pane `pane`'s body lands the live picker's cursor row
+/// on, while it is that picker's landing pane previewing that row's file
+/// (UX D7: drawn on the hit ground, body_layer.zig); null else.
+pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usize {
+ const pk = live(p) orelse return null;
+ // A theme or an action lands nowhere: the window wearing it, its
+ // edit on the Changes grounds are their previews.
+ if (!pk.previews or pk.landing != pane.serial or pk.source == .themes or pk.source == .actions) return null;
+ const s = &p.view().tag_state;
+ if (pk.shown != s.rows.at or count(p, pk) == 0) return null;
+ const row = rowAt(p, pk, arena, s.rows.at) catch return null;
+ const place = switch (row.target) {
+ .place => |t| t,
+ else => return null,
+ };
+ const f = pane.file orelse return null;
+ if (!std.mem.eql(u8, f.path, place.path)) return null;
+ return @intCast(@max(0, pane.body.cur_row));
+}
+
+/// The notice row's sentence while a picker previews (UX D7), written to
+/// `w`: where Enter lands (`here`, or the owner's reader by its address,
+/// a word to Look at), that the body is the preview, and Shift-Enter's new
+/// pane; the address's bytes in what was written, or null with no picker
+/// previewing.
+pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize {
+ const pk = live(p) orelse return null;
+ if (!pk.previews or pk.source == .themes or pk.source == .actions) return null;
+ if (pk.landing == pk.owner) {
+ w.writeAll("⏎ lands here") catch return null;
+ } else {
+ w.writeAll("⏎ lands in ") catch return null;
+ }
+ const lo = w.end;
+ if (pk.landing != pk.owner) w.print("@p{d}", .{pk.owner}) catch return null;
+ const hi = w.end;
+ if (pk.landing != pk.owner) w.writeAll("'s reader") catch return null;
+ w.writeAll(" · its text is the preview · S-⏎ a new pane") catch return null;
+ return .{ lo, hi };
+}
+
/// 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
@@ -743,7 +827,7 @@ fn preview(p: *Pardes, pk: *Pick) void {
pane.body.cur_col = 0;
return;
}
- look.focusPaneLine(p, id, at, .center);
+ 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);
}
@@ -828,6 +912,128 @@ pub fn deinitAll(p: *Pardes) void {
};
}
+// ---- code actions ----
+
+/// Action `index` of a code actions picker's rows: its title and its edit's
+/// records (the `@put` lines after its row, `@elsewhere` for an edit that
+/// reaches other files, none for a command's); null past the last.
+fn action(pk: *const Pick, index: usize) ?struct { title: []const u8, records: []const u8 } {
+ var lines = std.mem.splitScalar(u8, pk.rows, '\n');
+ var n: usize = 0;
+ while (lines.next()) |ln| {
+ if (ln.len == 0 or ln[0] == '@') continue;
+ if (n < index) {
+ n += 1;
+ continue;
+ }
+ const from = lines.index orelse pk.rows.len;
+ var to = from;
+ while (lines.peek()) |next| {
+ if (next.len == 0 or next[0] != '@') break;
+ _ = lines.next();
+ to = lines.index orelse pk.rows.len;
+ }
+ return .{ .title = std.mem.trimStart(u8, ln[Output.location(ln).end..], " "), .records = pk.rows[from..to] };
+ }
+ return null;
+}
+
+/// Action `index` of the live actions picker applied to the text it was
+/// asked of as one undo step, the tag put to rest first (its caret back
+/// where it was, then moved with the edit); one with no edit here (a
+/// command's, or one reaching other files) said and not applied.
+fn apply(p: *Pardes, pk: *Pick, index: usize) void {
+ const act = action(pk, index) orelse return;
+ const id = p.paneBySerial(pk.landing) orelse return TagState.toRest(p);
+ TagState.toRest(p);
+ var said: Kind.Buf(256) = .{};
+ if (std.mem.eql(u8, act.records, "@elsewhere\n")) return p.reportFailure(id, said.print("Actions: {s}: its edit reaches other files, not applied", .{act.title}));
+ if (act.records.len == 0) return p.reportFailure(id, said.print("Actions: {s}: no edit to apply", .{act.title}));
+ if (!pardes.lsp.Ask.applyAction(p, p.panes[id].?, pk.revision, act.records)) return p.reportFailure(id, said.print("Actions: {s}: not applied, the text is not what it was asked of", .{act.title}));
+ p.setMessage(.at(id), said.print("Actions: {s}", .{act.title}));
+}
+
+/// The live code actions picker's preview in its body (SPEC §5.1, the
+/// coordinator's R3): the edit of the action under the cursor, the lines it
+/// changes on the deleted ground and what they become after them as ghost
+/// rows on the added ground, the rows below pushed down and the last off
+/// the view. Drawn, never written; the rows shown alone.
+pub fn ghosts(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: pardes.Rect, body_h: u16) !void {
+ const pk = live(p) orelse return;
+ if (pk.source != .actions or !pk.previews or pk.landing != pane.serial) return;
+ const f = if (pane.file) |*file| file else return;
+ if (f.revision != pk.revision) return;
+ const records = (action(pk, refAt(p, pk) orelse return) orelse return).records;
+ const edits = pardes.lsp.Ask.parseLspEdits(arena, records, null) orelse return;
+ const text = f.content;
+ const index = try File.lineIndex(p.gpa, f);
+ // The edits by the lines they touch: each run of them its old lines
+ // [lo, hi) and their new text, which goes before line hi.
+ const Group = struct { lo: usize, hi: usize, new: []const u8 };
+ var groups: std.ArrayList(Group) = .empty;
+ var k: usize = 0;
+ while (k < edits.len) {
+ const begin = File.bufferOffset(f, edits[k].start, false);
+ if (begin > text.len) return;
+ const lo = Places.lineOf(index, begin);
+ var new: std.ArrayList(u8) = .empty;
+ try new.appendSlice(arena, text[index[lo]..begin]);
+ var hi = lo;
+ var at = begin;
+ while (k < edits.len) : (k += 1) {
+ const from = File.bufferOffset(f, edits[k].start, false);
+ const to = File.bufferOffset(f, edits[k].end, edits[k].end > edits[k].start);
+ if (from < at or to < from or to > text.len) return;
+ if (from > begin and Places.lineOf(index, from) >= hi) break;
+ try new.appendSlice(arena, text[at..from]);
+ try new.appendSlice(arena, edits[k].text);
+ at = to;
+ const line = Places.lineOf(index, to);
+ // Up to a line's start, from one or past its own text: that
+ // line is not changed.
+ hi = if (to == index[line] and (to > begin or begin == index[lo])) line else line + 1;
+ }
+ try new.appendSlice(arena, text[at..if (hi < index.len) index[hi] else text.len]);
+ try groups.append(arena, .{ .lo = lo, .hi = hi, .new = new.items });
+ }
+ const tab = p.settings.tab;
+ const y0 = p.bodyTop(pane, r);
+ const rows: usize = @min(body_h, s.rows -| y0);
+ const first: usize = pane.context_rows;
+ if (rows <= first) return;
+ const w: usize = s.cols;
+ const old = try arena.dupe(Cell, s.cells[(y0 + first) * w .. (y0 + rows) * w]);
+ const grounds = colors.Grounds.of(p.theme());
+ const ink = p.theme().fg orelse p.theme().tag_fg;
+ const x0 = r.x + config.GUTTER + File.gutterWidth(pane);
+ const width = r.w -| (x0 - r.x);
+ var out: usize = first;
+ var g: usize = 0;
+ var vr: usize = first;
+ while (vr < rows and out < rows) : (vr += 1) {
+ const shown = pane.wrapAt(tab, @intCast(vr)).line;
+ const line: usize = if (shown < 0) index.len else @intCast(shown);
+ if (vr == first or pane.wrapAt(tab, @intCast(vr - 1)).line != shown) {
+ while (g < groups.items.len and groups.items[g].hi < line) g += 1;
+ while (g < groups.items.len and groups.items[g].hi == line) : (g += 1) {
+ var news = std.mem.splitScalar(u8, std.mem.trimEnd(u8, groups.items[g].new, "\n"), '\n');
+ if (groups.items[g].new.len > 0) while (news.next()) |l| {
+ if (out >= rows) break;
+ const y: u16 = @intCast(y0 + out);
+ s.fill(0, y, @intCast(s.cols), 1, .{});
+ s.fill(x0, y, width, 1, .{ .bg = .{ .rgb = grounds.add.row } });
+ _ = s.print(x0, y, width, l, .{ .fg = .{ .rgb = ink }, .bg = .{ .rgb = grounds.add.row } });
+ out += 1;
+ };
+ }
+ }
+ if (out >= rows) break;
+ @memcpy(s.cells[(y0 + out) * w ..][0..w], old[(vr - first) * w ..][0..w]);
+ if (g < groups.items.len and line >= groups.items[g].lo and line < groups.items[g].hi) s.tint(x0, @intCast(y0 + out), width, grounds.del.row, null);
+ out += 1;
+ }
+}
+
// ---- keys ----
/// A key in the live picker (keys.zig tagStateKey, SPEC §5.4). Esc is
@@ -845,15 +1051,22 @@ pub fn key(p: *Pardes, k: Key) void {
return;
}
if (pk.spine == .acts) return actKey(p, pk, k);
- // Themes: Enter wears the one under the cursor; the rows and the field.
- if (pk.source == .themes) {
- if (plain and k.cp == Key.enter) {
- const at = themeAt(p, pk) orelse return;
+ // Themes: Enter wears the one under the cursor; actions: Enter, or an
+ // action's digit with the field empty, applies it; the rows and the
+ // field.
+ if (pk.source == .themes or pk.source == .actions) {
+ if (plain and k.cp == Key.enter and pk.source == .themes) {
+ const at = refAt(p, pk) orelse return;
TagState.toRest(p);
pardes.colors.setThemeIndex(p, at);
return;
}
- if (s.rows.key(k, n)) return;
+ if (plain and k.cp == Key.enter) return apply(p, pk, refAt(p, pk) orelse return);
+ if (pk.source == .actions and plain and s.field.len == 0 and k.cp >= '1' and k.cp <= '9') return apply(p, pk, k.cp - '1');
+ if (s.rows.key(k, n)) {
+ pk.names.reachTo(@as(usize, s.rows.at) + Band.Cursor.shown);
+ return;
+ }
if (s.field.key(k)) filter(p, pk);
return;
}
@@ -895,7 +1108,11 @@ pub fn key(p: *Pardes, k: Key) void {
return;
}
if (plain and k.cp == Key.backspace and s.field.len == 0) return back(p, pk);
- if (s.rows.key(k, n)) return;
+ // A cursor gone past the rows sorted sorts as far (Names.reach).
+ if (s.rows.key(k, n)) {
+ if (fuzzy(pk)) pk.names.reachTo(@as(usize, s.rows.at) + Band.Cursor.shown);
+ return;
+ }
if (s.field.key(k)) filter(p, pk);
}
@@ -1051,6 +1268,7 @@ fn keep(p: *Pardes, pk: *Pick) void {
out.writer.print("{s} ", .{pk.word.slice()}) catch return;
for (pk.refined[0..pk.nrefined]) |r| out.writer.print("{s} | ", .{r.query.slice()}) catch return;
out.writer.print("{s}\n", .{s.field.text()}) catch return;
+ if (fuzzy(pk)) pk.names.reachTo(Query.max_rows);
var kept: usize = 0;
for (0..count(p, pk)) |i| {
if (kept == Query.max_rows) break;
@@ -1994,3 +2212,186 @@ test "n and N walk the newest list or search word, or the one Looked at (SPEC §
p.update(.{ .key = .{ .cp = 'n', .text = "n" } });
try std.testing.expect(pane.places.current != null and !std.meta.eql(was, pane.places.current));
}
+
+test "code actions: a picker in the asking pane's tag, the one under the cursor its edit in the body (the lines it changes on the deleted ground, what they become after them), Enter or its digit applies it as one undo step, a command's said" {
+ const Key_ = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
+ defer p.deinit();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ p.settings.jumps = .walk;
+ const pane = try p.setTestFile("one\ntwo add\nthree\n");
+ const id = p.view().active;
+ // `add` is bytes 8..11.
+ const rows = "x:1:1 extract\nx:1:1 add a line\n@put 0 0 //%20top%0A\nx:1:1 rename add to sum\n@put 8 11 sum\n";
+ open(p, id, .actions, "", "", rows);
+ live(p).?.revision = pane.file.?.revision;
+ const s = &p.view().tag_state;
+ try std.testing.expectEqual(Source.actions, live(p).?.source);
+ try std.testing.expectEqual(pane.serial, s.host);
+ try std.testing.expectEqual(@as(usize, 3), count(p, live(p).?));
+ // The rename: `two add` on the deleted ground, `two sum` after it.
+ p.update(.{ .key = .{ .cp = Key_.down } });
+ p.update(.{ .key = .{ .cp = Key_.down } });
+ settle(p);
+ p.sync();
+ var shot = try p.render(frame.allocator());
+ const r = p.view().rects[id];
+ const x = r.x + config.GUTTER + File.gutterWidth(pane);
+ const y = p.bodyTop(pane, r);
+ const grounds = colors.Grounds.of(p.theme());
+ for ([_][]const u8{ "o", "t", "t", "t" }, [_][]const u8{ "n", "w", "w", "h" }, 0..) |c0, c1, row| {
+ try std.testing.expectEqualStrings(c0, shot.at(x, y + @as(u16, @intCast(row))).grapheme());
+ try std.testing.expectEqualStrings(c1, shot.at(x + 1, y + @as(u16, @intCast(row))).grapheme());
+ }
+ try std.testing.expectEqualStrings("a", shot.at(x + 4, y + 1).grapheme());
+ try std.testing.expectEqualStrings("s", shot.at(x + 4, y + 2).grapheme());
+ try std.testing.expectEqual(pardes.Color{ .rgb = grounds.del.row }, shot.at(x, y + 1).style.bg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = grounds.add.row }, shot.at(x, y + 2).style.bg);
+ try std.testing.expectEqualStrings("one\ntwo add\nthree\n", pane.file.?.content);
+ // An action lands nowhere: no landing line, no `▸` before the line it
+ // changes, no sentence of where Enter lands (UX D7's are a jump's; an
+ // action's preview is its edit on the Changes grounds).
+ try std.testing.expect(landingLine(p, frame.allocator(), pane) == null);
+ try std.testing.expect(!std.mem.eql(u8, "▸", shot.at(x - 1, y + 1).grapheme()));
+ var notice: [pardes.Messages.notice_row_cap]u8 = undefined;
+ try std.testing.expect(!pardes.Messages.noticeRow(p, 100, &notice).quiet_left);
+ // Up: the line put in at the top, before line 1, nothing deleted.
+ p.update(.{ .key = .{ .cp = Key_.up } });
+ settle(p);
+ p.sync();
+ frame.deinit();
+ frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ shot = try p.render(frame.allocator());
+ try std.testing.expectEqualStrings("/", shot.at(x, y).grapheme());
+ try std.testing.expectEqual(pardes.Color{ .rgb = grounds.add.row }, shot.at(x, y).style.bg);
+ try std.testing.expectEqualStrings("o", shot.at(x, y + 1).grapheme());
+ try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = grounds.del.row }, shot.at(x, y + 1).style.bg));
+ try std.testing.expect(!std.meta.eql(pardes.Color{ .rgb = p.chromeTheme().roles.hit }, shot.at(x, y + 1).style.bg));
+ // `3`: the rename applied, the tag at rest; one undo takes it back.
+ p.update(.{ .key = .{ .cp = '3', .text = "3" } });
+ try std.testing.expectEqual(TagState.Kind.rest, s.kind);
+ try std.testing.expectEqualStrings("one\ntwo sum\nthree\n", pane.file.?.content);
+ p.update(.{ .key = .{ .cp = 'u', .text = "u" } });
+ try std.testing.expectEqualStrings("one\ntwo add\nthree\n", pane.file.?.content);
+ // Enter on a command's: said, nothing changed.
+ open(p, id, .actions, "", "", rows);
+ live(p).?.revision = pane.file.?.revision;
+ p.update(.{ .key = .{ .cp = Key_.enter } });
+ try std.testing.expectEqual(TagState.Kind.rest, s.kind);
+ try std.testing.expectEqualStrings("one\ntwo add\nthree\n", pane.file.?.content);
+ try std.testing.expectEqualStrings("Actions: extract: no edit to apply", p.messages.saidBy(pane));
+}
+
+test "the themes picker marks the theme in use: `in use` at its row's right end in the dim ink, the cursor on it when it opens, the mark staying on it while the window wears another (POLISH 12, UX A15)" {
+ const Key_ = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ const id = p.view().active;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const was = p.settings.theme;
+ for (" tt") |c| p.update(.{ .key = .{ .cp = c } });
+ const s = &p.view().tag_state;
+ try std.testing.expectEqual(@as(u16, @intCast(was)), s.rows.at);
+ // The band's spines hang from the head's first `cells` spans: its key
+ // cells (`␣ t`), never its dim hint.
+ const h = (try head(p, a, pane)).?;
+ try std.testing.expectEqual(@as(u8, 2), h.cells);
+ for (h.spans[0..h.cells]) |span| try std.testing.expectEqual(TagState.Style.key, span.style);
+ const Find = struct {
+ fn row(band: Band, text: []const u8) ?Band.Row {
+ for (band.steps[0..band.nsteps]) |step| for (step.rows) |r| if (std.mem.eql(u8, r.text, text)) return r;
+ return null;
+ }
+ };
+ var band = (try Band.of(p, a, pane, id)).?;
+ const worn = Find.row(band, pardes.colors.themes[was].name).?;
+ try std.testing.expectEqualStrings("in use", worn.meta);
+ try std.testing.expect(worn.on);
+ // One row says it.
+ var said: usize = 0;
+ for (band.steps[0..band.nsteps]) |step| for (step.rows) |r| {
+ said += @intFromBool(r.meta.len > 0);
+ };
+ try std.testing.expectEqual(@as(usize, 1), said);
+ // Drawn at the row's right end, in the dim ink of the selection it is on.
+ _ = try p.render(a);
+ const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
+ const roles = &p.chromeTheme().roles;
+ const on = roles.selectedOn(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused);
+ var found = false;
+ for (0..layer.rows) |row| {
+ const cells = layer.cells[row * layer.cols ..][0..layer.cols];
+ var at: usize = 0;
+ while (at + 6 <= cells.len) : (at += 1) {
+ if (!std.mem.eql(u8, cells[at].grapheme(), "i") or !std.mem.eql(u8, cells[at + 1].grapheme(), "n") or !std.mem.eql(u8, cells[at + 3].grapheme(), "u")) continue;
+ try std.testing.expectEqual(pardes.Color{ .rgb = on.dim }, cells[at].style.fg);
+ found = true;
+ }
+ }
+ try std.testing.expect(found);
+ // The window wearing the next: the mark stays on the theme in use.
+ p.update(.{ .key = .{ .cp = if (was + 1 < pardes.colors.themes.len) Key_.down else Key_.up } });
+ band = (try Band.of(p, a, pane, id)).?;
+ try std.testing.expectEqualStrings("in use", Find.row(band, pardes.colors.themes[was].name).?.meta);
+}
+
+test "a picker's preview is legible as one (UX D7): its landing line on the hit ground with `▸` in the gutter, a third of the body above it, and the notice row saying where Enter lands" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 140, .rows = 50 });
+ defer p.deinit();
+ p.settings.jumps = .walk;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(std.testing.allocator);
+ for (1..81) |i| try text.print(std.testing.allocator, "line {d} of the file\n", .{i});
+ const path = try testFile(p, &tmp, "long.zig", text.items);
+ defer p.gpa.free(path);
+ _ = try p.setTestFile("held\n");
+ const asker = p.view().active;
+ Trail.keep(p.panes[asker].?);
+ const rows = try std.fmt.allocPrint(std.testing.allocator, "{s}:40:6 line 40 of the file\n", .{path});
+ defer std.testing.allocator.free(rows);
+ open(p, asker, .list, "Refs", "", rows);
+ const pk = live(p).?;
+ const reader = p.paneBySerial(pk.landing).?;
+ p.update(.tick);
+ const pane = p.panes[reader].?;
+ try std.testing.expectEqualStrings(path, pane.file.?.path);
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const s = try p.render(frame.allocator());
+ const r = p.view().rects[reader];
+ const body_y = p.bodyTop(pane, r);
+ // Line 40 a third of the way down: ⌈rows/3⌉ rows of context above it.
+ var at: ?u16 = null;
+ for (0..pane.rows) |row| if (pane.wrapAt(p.settings.tab, @intCast(row)).line == 39) {
+ at = @intCast(row);
+ break;
+ };
+ try std.testing.expectEqual(@as(?u16, @intCast((pane.rows + 2) / 3)), at);
+ const y = body_y + at.?;
+ const roles = &p.chromeTheme().roles;
+ const tx = r.x + pardes.config.GUTTER;
+ const gutter = File.gutterWidth(pane);
+ // Its text on the hit ground across the row; the row above as it was.
+ for (gutter..r.w - pardes.config.GUTTER) |x| try std.testing.expectEqual(pardes.Color{ .rgb = roles.hit }, s.at(tx + @as(u16, @intCast(x)), y).style.bg);
+ try std.testing.expect(!std.meta.eql(s.at(tx + gutter + 2, y - 1).style.bg, pardes.Color{ .rgb = roles.hit }));
+ // `▸` in the key ink in the gutter's cell after the number.
+ const mark = s.at(tx + gutter - 1, y);
+ try std.testing.expectEqualStrings("▸", mark.grapheme());
+ try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, mark.style.fg);
+ // The notice row: where Enter lands, the owner's address a word in it.
+ var buf: [pardes.Messages.notice_row_cap]u8 = undefined;
+ const said = pardes.Messages.noticeRow(p, 120, &buf);
+ const want = try std.fmt.allocPrint(frame.allocator(), "⏎ lands in @p{d}'s reader · its text is the preview · S-⏎ a new pane", .{p.panes[asker].?.serial});
+ try std.testing.expect(std.mem.startsWith(u8, said.text, want));
+ try std.testing.expect(said.quiet_left);
+ try std.testing.expectEqualStrings(try std.fmt.allocPrint(frame.allocator(), "@p{d}", .{p.panes[asker].?.serial}), said.text[said.word[0]..said.word[1]]);
+ // At rest: no ground, no mark, the row back to its own.
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expect(!pardes.Messages.noticeRow(p, 120, &buf).quiet_left);
+}
diff --git a/core/Places.zig b/core/Places.zig
index 7f847f6a..8563d7c8 100644
--- a/core/Places.zig
+++ b/core/Places.zig
@@ -658,14 +658,15 @@ pub fn origin(set: *const Places, pane: *Pane) usize {
return @min(r.anchor, r.head);
}
-/// Every place on the rows shown, tinted over the text; the current one in
-/// the search colour itself, the rest halfway to the page.
+/// Every place on the rows shown, tinted over the text: the hit ground,
+/// the current one the current hit's (colors.Roles, UX D4, D14).
pub fn paint(set: *Places, p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16) void {
if (!set.shows(pane)) return;
const f = &pane.file.?;
const th = p.theme();
- var strong = p.chromeTheme().search_bg;
- var quiet = colors.mix(th.bg orelse th.tag_bg, strong);
+ const roles = &p.chromeTheme().roles;
+ var strong = roles.hit_current;
+ var quiet = roles.hit;
// A search prompt's pattern that is no regex: its last places, dimmed.
if (pardes.Prompt.dims(p, pane)) {
strong = quiet;
diff --git a/core/Prompt.zig b/core/Prompt.zig
index c3d9959a..9dfe9ec2 100644
--- a/core/Prompt.zig
+++ b/core/Prompt.zig
@@ -820,7 +820,7 @@ pub fn unlit(p: *const Pardes, pane: *Pane) ?[2]usize {
}
/// The gutter's marks while a prompt is typed (SPEC §7.1): `▸` on the
-/// current place's line and `▪` on every other line holding a place (`/
+/// current place's line alone (`/
/// ?`); `┃` on each line the selections a sam prompt began with cover (`s
/// S K A-K`), its scope. In the blank after a row's line number, on a
/// line's first row.
@@ -837,8 +837,12 @@ pub fn paintGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h:
const tab = p.settings.tab;
const x = gutterX(pane, r);
const y = p.bodyTop(pane, r);
- const ink = p.chromeTheme().box;
+ const ink = p.chromeTheme().roles.key;
const nlines = File.nlines(p.gpa, f);
+ // `▸` on the current place's line alone: the lines with places are the
+ // rail's ticks (Places.addTicks), never glyphs of their own (UX D14).
+ const c = set.current orelse return;
+ if (c >= hits.len) return;
var last: i32 = -1;
var vr: u16 = 0;
while (vr < body_h) : (vr += 1) {
@@ -848,12 +852,11 @@ pub fn paintGutter(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h:
last = line;
const ls = File.lineStart(p.gpa, f, @intCast(line));
const next = File.lineStart(p.gpa, f, @intCast(line + 1));
- const i = Places.firstFrom(hits, ls);
- if (i == hits.len or hits[i].start >= @max(next, ls + 1)) continue;
- const current = if (set.current) |c| c < hits.len and hits[c].start >= ls and hits[c].start < @max(next, ls + 1) else false;
+ if (hits[c].start < ls or hits[c].start >= @max(next, ls + 1)) continue;
var style = s.at(x, y + vr).style;
style.fg = .{ .rgb = ink };
- s.set(x, y + vr, if (current) "▸" else "▪", style);
+ s.set(x, y + vr, "▸", style);
+ return;
}
}
@@ -1082,10 +1085,14 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !TagState.Head {
// The count and the hints at the row's right end (UX D3).
const at = text.items.len;
if (line.len > 0) {
+ // A pattern that is no regex: why, in the err ink, in place of the
+ // hints (UX D14), what is shown meanwhile dim; in the count's place,
+ // which never drops.
if (pr.bad) {
- try text.appendSlice(arena, " ");
try styled(arena, text, spans, regexMessage(line), .err);
- try text.print(arena, " · the {d} from before shown, dimmed", .{@as(usize, pane.body.nsel) + 1});
+ try styled(arena, text, spans, try std.fmt.allocPrint(arena, " · the {d} from before shown, dimmed", .{@as(usize, pane.body.nsel) + 1}), .dim);
+ try b.right(at, text.items.len);
+ return .{ .text = text.items, .spans = spans.items, .cells = 1, .caret = caret };
} else if (behavior(pr.op) != null) {
try pipeCount(p, arena, text, spans, pane, pr, line);
} else try count(arena, text, pane, pr);
@@ -1302,7 +1309,8 @@ test "s asks in the tag's head: its key cell, the field, the plain word and the
try std.testing.expectEqual(@as(u16, 1), pane.body.nsel);
// No regex: the two from before, dimmed, and why.
typeKeys(p, "(");
- try std.testing.expect(has(try tagOf(p), " bad regular expression · the 2 from before shown, dimmed "));
+ // Its reason in place of the hints (UX D14), what follows it dim.
+ try std.testing.expect(std.mem.endsWith(u8, try tagOf(p), " bad regular expression · the 2 from before shown, dimmed"));
try std.testing.expectEqual(@as(u16, 1), pane.body.nsel);
try std.testing.expect(selecting(p, pane).?.dim);
// Esc: rest, the tag and the selection as they were.
@@ -1373,7 +1381,7 @@ fn gutterAt(p: *Pardes, arena: std.mem.Allocator, row: u16) ![]const u8 {
return s.at(x, p.bodyTop(pane, r) + row).grapheme();
}
-test "/ searches the body as it is typed: the current place selected, the gutter marked, counted 3/7 · 5 lines; Enter folds /dirty/ 3/7 into the trail; n says where it went, round the end too; the first Esc clears the tints and dims the word, Look on it lights them again" {
+test "/ searches the body as it is typed: the current place selected, `▸` in the key ink on its line alone (the others are the rail's ticks), the places on the hit ground, counted 3/7 · 5 lines; Enter folds /dirty/ 3/7 into the trail; n says where it went, round the end too; the first Esc clears the tints and dims the word, Look on it lights them again (UX D14)" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 30 });
defer p.deinit();
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
@@ -1384,10 +1392,20 @@ test "/ searches the body as it is typed: the current place selected, the gutter
typeKeys(p, "/dirty");
try std.testing.expect(has(try tagOf(p), "/ dirty = Look /dirty/ 3/7 · 5 lines ⏎ land · M-⏎ as a list"));
try std.testing.expectEqual(@as(?usize, 2), pane.places.current);
- try std.testing.expectEqualStrings("▪", try gutterAt(p, frame.allocator(), 0));
+ try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 0));
try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 1));
try std.testing.expectEqualStrings("▸", try gutterAt(p, frame.allocator(), 2));
- try std.testing.expectEqualStrings("▪", try gutterAt(p, frame.allocator(), 7));
+ try std.testing.expectEqualStrings(" ", try gutterAt(p, frame.allocator(), 7));
+ {
+ const s = try p.render(frame.allocator());
+ const r = p.view().rects[0];
+ const roles = &p.chromeTheme().roles;
+ const x = r.x + config.GUTTER + File.gutterWidth(pane);
+ const y = p.bodyTop(pane, r);
+ try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, s.at(x - 1 - File.laneCells(pane) - pane.layers.heat, y + 2).style.fg);
+ // Line 1's place (`dirty` at its start) on the hit ground.
+ try std.testing.expectEqual(pardes.Color{ .rgb = roles.hit }, s.at(x, y).style.bg);
+ }
p.update(.{ .key = .{ .cp = Key.enter } });
try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind);
try std.testing.expect(std.mem.startsWith(u8, try tagOf(p), "/dirty/ 3/7 › /test.txt "));
diff --git a/core/TagState.zig b/core/TagState.zig
index 3fceb7f0..5ae2d0b6 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -468,7 +468,7 @@ pub fn helpLeaf(p: *const Pardes, at: u16, buf: *[row_max]u8) Leaf {
}
/// How a span of the head is drawn (draw.zig paintPaneTag).
-pub const Style = enum { key, dim, under, strike, err };
+pub const Style = enum { key, dim, under, strike, err, rule };
pub const Span = struct { lo: u32, hi: u32, style: Style };
/// The head: its text, the spans drawn apart, and the caret in it when the
/// head is typed in.
@@ -608,7 +608,7 @@ pub const Builder = struct {
for (b.cols[0..b.ncols]) |c| {
if (c >= indent) break;
try b.text.appendNTimes(b.arena, ' ', c - at);
- try b.styled("│", .key); // P2: the rule role (UX D4)
+ try b.styled("│", .rule);
at = c + 1;
}
try b.text.appendNTimes(b.arena, ' ', indent -| at);
@@ -718,14 +718,27 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
const tab = p.settings.tab;
const most: usize = if (pane.isTerminal()) @import("layout.zig").wantedTagRows(p, id) else 3;
var children: [bindings.max_children]bindings.Child = undefined;
- const level = bindings.level(p, cur.root, cur.path, &children);
+ var level = bindings.level(p, cur.root, cur.path, &children);
const used = s.used[node.group];
const indent = b.col() + 1;
// A struck key goes after the children: the last row keeps its cells.
const struck: usize = if (s.miss != 0) 1 + panes.File.displayWidth(tab, bindings.keyName(s.miss)) else 0;
+ // The registers rolled (UX D11): the ones holding something, each its
+ // value as a row shows it, a newline's `⏎` dim.
+ const registers = cur.root == .register and cur.path.len == 0;
+ if (registers) {
+ var n: usize = 0;
+ for (level) |c| if (bindings.registerValue(p, c.key).len > 0) {
+ level[n] = c;
+ n += 1;
+ };
+ level = level[0..n];
+ }
var rows: usize = 1;
for (level, 0..) |c, i| {
- const w = panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, c.label) + @intFromBool(c.group or c.more);
+ const label = if (registers) try bindings.registerShown(arena, tab, bindings.registerValue(p, c.key)) else c.label;
+ const cut = c.group or (c.more and !registers);
+ const w = panes.File.displayWidth(tab, bindings.keyName(c.key)) + 1 + panes.File.displayWidth(tab, label) + @intFromBool(cut);
var gap: usize = if (i == 0) 1 else 2;
if (b.col() + gap + w + more(level.len - i - 1, rows == most) + (if (rows == most) struck else 0) > b.width and rows < most and b.col() > indent) {
try b.row(indent);
@@ -741,8 +754,11 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
const lo: u32 = @intCast(b.text.items.len);
try b.styled(bindings.keyName(c.key), .key);
try b.put(" ");
- try b.put(c.label);
- if (c.group or c.more) try b.put("…");
+ if (registers and std.mem.endsWith(u8, label, "⏎")) {
+ try b.put(label[0 .. label.len - "⏎".len]);
+ try b.styled("⏎", .dim);
+ } else try b.put(label);
+ if (cut) try b.put("…");
const hi: u32 = @intCast(b.text.items.len);
if (bindings.dimmed(pane, c)) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .dim });
if (c.key == used) try b.spans.append(arena, .{ .lo = lo, .hi = hi, .style = .under });
@@ -913,6 +929,14 @@ test "a rolled level breaks between its children only: the rows after the first
// child's column; no row wider than the tag.
for (rows[1..n]) |row| try std.testing.expect(std.mem.startsWith(u8, row, "│ ") and row["│ ".len] != ' ');
for (rows[0..n]) |row| try std.testing.expect(panes.File.displayWidth(tab, row) <= width);
+ // The spines in the rule ink, never the key's (UX D4).
+ const h = (try head(p, a, p.panes[p.view().active].?)).?;
+ var spines: usize = 0;
+ for (h.spans) |span| if (std.mem.eql(u8, h.text[span.lo..span.hi], "│")) {
+ try std.testing.expectEqual(Style.rule, span.style);
+ spines += 1;
+ };
+ try std.testing.expect(spines > 0);
// Every child shown is whole on one row; the ones not shown are counted.
var children: [bindings.max_children]bindings.Child = undefined;
const level = bindings.level(p, .leader, "", &children);
diff --git a/core/Trail.zig b/core/Trail.zig
index e22a58b6..c2c1b0c3 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -194,8 +194,11 @@ pub fn replaceStep(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
}
/// Pane `id` showing `path` at `at`, the keyboard on it: its caret moved
-/// in the file it shows, or a new pane on `path` in its place, its walk
-/// with it. A line past the new file's end is a miss that changes nothing.
+/// in the file it shows, or `path` opened in its place as the same pane, as
+/// acme's Get keeps a window's id: its walk, its serial (`@pN`, a script's
+/// `/pane/N`), the 9P state its scripts hold and its /log record (a rename),
+/// the file it left closed as any (Recent keeps its place). A line past the
+/// new file's end is a miss that changes nothing.
fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
const pane = p.panes[id].?;
if (pane.file) |f| if (std.mem.eql(u8, f.path, path)) {
@@ -213,11 +216,23 @@ fn show(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
}
if (at.line > panes.File.nlines(p.gpa, &nt.file.?)) return error.LineMissing;
nt.trail = pane.trail;
+ // What jj answered for the file it leaves goes with that file; its
+ // text a revision on from the one it leaves, so nothing a worker was
+ // asked of that text (a parse, a paint, both by serial and revision)
+ // lands on this one.
+ @import("jj.zig").forget(p, pane.serial);
+ nt.serial = pane.serial;
+ nt.file.?.revision = if (pane.file) |f| f.revision +% 1 else 0;
+ nt.file.?.saved_revision = nt.file.?.revision;
+ // Its 9P state: the one never announced leaves with no record.
+ std.mem.swap(@TypeOf(pane.fs), &nt.fs, &pane.fs);
// Before the layout gives its place away: its file is told closed
// while it is still in its slot.
try panes.deinitPane(p, pane);
layout.replacePane(p, id, free);
p.panes[id] = null;
+ pardes.ctlfs.events.noteLog(p, .rename, nt);
+ if (pardes.Pardes.onDisk(nt)) p.recent.opened(p.recentGpa(), path);
lift(p, free);
look.focusPaneLine(p, free, at, .keep);
// Its line half the body's rows down, as a look's new pane has it.
@@ -751,8 +766,9 @@ test "the session of pick-ui §6.7: four jumps across three files, back by a cli
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
const s = try p.render(arena.allocator());
+ // In the dim ink of the reading tag's ground (UX D4: 3:1 at least).
const dim = try tagCell(p, r, "place.zig:40");
- try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().lineno }, s.at(dim[0], dim[1]).style.fg);
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().roles.on(.reading_focused).dim }, s.at(dim[0], dim[1]).style.fg);
// A click on a forward step goes forward to it.
try clickTag(p, r, "place.zig:9", .left);
r = p.view().active;
@@ -839,7 +855,8 @@ test "a trail keeps its newest three back steps whole, older ones fold into one
defer arena.deinit();
const s = try p.render(arena.allocator());
const fold = try tagCell(p, r, "+2");
- try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().lineno }, s.at(fold[0], fold[1]).style.fg);
+ // In the dim ink of the reading tag's ground (UX D4).
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().roles.on(.reading_focused).dim }, s.at(fold[0], fold[1]).style.fg);
try clickTag(p, r, "+2", .right);
try std.testing.expectEqualStrings("rank.zig:20", f.at(&at));
// Back at the first: five forward steps, the two nearest whole.
@@ -898,6 +915,8 @@ test "two steps whose files have the same name are told apart by the shortest pa
const s = try p.render(arena.allocator());
const word = try tagCell(p, r, "Find x 1/2");
try std.testing.expect(s.at(word[0], word[1]).style.ul == .single);
+ // In the key ink (UX D8, D4).
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().roles.key }, s.at(word[0], word[1]).style.fg);
const other = try tagCell(p, r, "place.zig");
try std.testing.expect(s.at(other[0], other[1]).style.ul != .single);
}
diff --git a/core/bindings.zig b/core/bindings.zig
index af5e8a6d..a8b81842 100644
--- a/core/bindings.zig
+++ b/core/bindings.zig
@@ -337,8 +337,30 @@ pub const register_names = [_]struct { key: u8, name: []const u8 }{
};
/// The display columns of a register's first line which-key shows; the
-/// rest is `…`.
-pub const register_cut = 24;
+/// rest is `…` (UX D11: 20 cells, the `…` among them).
+pub const register_cut = 20;
+
+/// A register's value as a row shows it (UX D11): its first line in
+/// `register_cut` cells at most, a path cut from the left
+/// (`…core/Query.zig`), other text from the right (`…` after it), a newline
+/// that ends what shows said `⏎`; `—` when it holds nothing. Only its first
+/// `4 * register_cut` bytes are read.
+pub fn registerShown(arena: std.mem.Allocator, tab: u16, value: []const u8) ![]const u8 {
+ if (value.len == 0) return "—";
+ const bound = if (value.len > 4 * register_cut) modal.graphemeStart(value, 4 * register_cut) else value.len;
+ const newline = std.mem.indexOfScalar(u8, value[0..bound], '\n');
+ const line = value[0 .. newline orelse bound];
+ const width = File.displayWidth(tab, line);
+ if (width <= register_cut and line.len == value.len) return line;
+ if (width < register_cut and newline != null) return std.mem.concat(arena, u8, &.{ line, "⏎" });
+ // A path: one line, no spaces, a slash in it; its end says which file.
+ if (newline == null and bound == value.len and std.mem.indexOfAny(u8, line, " \t") == null and std.mem.indexOfScalar(u8, line, '/') != null) {
+ var start = File.rawAtDisplay(tab, line, width - (register_cut - 1));
+ if (File.rawDisplayCol(tab, line, start) < width - (register_cut - 1)) start = modal.nextGrapheme(line, start);
+ return std.mem.concat(arena, u8, &.{ "…", line[start..] });
+ }
+ return std.mem.concat(arena, u8, &.{ line[0..File.byteAtDisplay(tab, line, register_cut - 1)], "…" });
+}
/// `"`'s level: a child a register, its label the first line of its value
/// (`—` when empty), cut. Read when the level is (a key, a frame), never
@@ -552,13 +574,15 @@ test "Help's rows: every leaf of every root, spelled as its chord, its word and
for (flat) |f| try std.testing.expectEqual(f.row.len, f.lower.len);
}
-test "\" shows the registers rolled, each its first line; Down unrolls them beside the cursor's value; a register's key goes down to its verbs, Backspace back up, p pastes it" {
+test "\" shows the registers rolled, the ones holding something, each its value cut to 20 cells (a path from the left, a newline a dim ⏎); Down unrolls them all, `key value` with the name at the right, beside the cursor's value and its verbs, their keys in the key ink; a register's key goes down to its verbs, Backspace back up, p pastes it (UX D11)" {
const tagline = @import("tagline.zig");
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 40 });
defer p.deinit();
const pane = try p.setTestFile("one\ntwo\n");
try p.registers.put(p.gpa, 'a', "const best = rank(q, name) orelse continue;\nreturn best;", 0, 1, true);
try p.registers.put(p.gpa, '"', "self.dirty = true;", 0, 1, true);
+ try p.registers.put(p.gpa, 'n', "ab\ncd", 0, 1, true);
+ try p.registers.put(p.gpa, 'p', "/tmp/claude-1000/wuS/r/proj/core/Query.zig", 0, 1, true);
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
const a = frame.allocator();
@@ -573,8 +597,13 @@ test "\" shows the registers rolled, each its first line; Down unrolls them besi
try std.testing.expectEqual(p.clock.now_ns + 300 * std.time.ns_per_ms, p.view().tag_state.due_ns);
p.clock.now_ns = p.view().tag_state.due_ns;
const rolled = try tagline.tagText(p, a, pane);
- try std.testing.expect(std.mem.indexOf(u8, rolled, "\" ▸ \" self.dirty = true; a const best = rank(q, nam… / —") != null);
- try std.testing.expect(std.mem.indexOf(u8, rolled, "% /test.txt . o # 1 _ —") != null);
+ try std.testing.expect(std.mem.indexOf(u8, rolled, "\" ▸ \" self.dirty = true; a const best = rank(q… n ab⏎ p …proj/core/Query.zig % /test.txt . o # 1 ") != null);
+ // Its ⏎ in the dim ink.
+ const h = (try @import("TagState.zig").head(p, a, pane)).?;
+ const nl = std.mem.indexOf(u8, h.text, "ab⏎").? + 2;
+ for (h.spans) |span| {
+ if (span.lo == nl) break try std.testing.expectEqual(.dim, span.style);
+ } else return error.NoDimNewline;
// Down unrolls: a row each, the cursor on the default, its value
// beside them.
p.update(.{ .key = .{ .cp = Key.down } });
@@ -584,8 +613,37 @@ test "\" shows the registers rolled, each its first line; Down unrolls them besi
const layer = &p.surface.tag_layers[pardes.BAND_LAYER];
var band: std.ArrayList(u8) = .empty;
for (0..layer.rows) |row| for (layer.cells[row * layer.cols ..][0..layer.cols]) |cell| try band.appendSlice(a, cell.grapheme());
- try std.testing.expect(std.mem.indexOf(u8, band.items, "▶ \" yank self.dirty = true;") != null);
+ try std.testing.expect(std.mem.indexOf(u8, band.items, "▶ \" self.dirty = true;") != null);
+ try std.testing.expect(std.mem.indexOf(u8, band.items, "/ —") != null);
try std.testing.expect(std.mem.indexOf(u8, band.items, "\"\" · yank") != null);
+ try std.testing.expect(std.mem.indexOf(u8, band.items, "p after P before R replace y into") != null);
+ // The empty register's `—` and the names in the dim ink, the verbs'
+ // letters bold in the key ink.
+ const roles = &p.chromeTheme().roles;
+ const inks = roles.on(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused);
+ const Cells = struct {
+ fn at(l: *const pardes.Layer, word: []const u8) ?*const pardes.Cell {
+ for (0..l.rows) |row| {
+ const cells = l.cells[row * l.cols ..][0..l.cols];
+ var x: usize = 0;
+ while (x + word.len <= cells.len) : (x += 1) {
+ for (word, cells[x..][0..word.len]) |c, cell| {
+ if (cell.len != 1 or cell.text[0] != c) break;
+ } else return &cells[x];
+ }
+ }
+ return null;
+ }
+ };
+ try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, Cells.at(layer, "last search").?.style.fg);
+ const verbs = Cells.at(layer, "p after").?;
+ try std.testing.expectEqual(pardes.Color{ .rgb = roles.key }, verbs.style.fg);
+ try std.testing.expect(verbs.style.bold);
+ for (0..layer.rows) |row| {
+ const cells = layer.cells[row * layer.cols ..][0..layer.cols];
+ for (cells, 0..) |cell, x| if (std.mem.eql(u8, cell.grapheme(), "—") and x > 2 and std.mem.eql(u8, cells[x - 3].grapheme(), "/"))
+ try std.testing.expectEqual(pardes.Color{ .rgb = inks.dim }, cell.style.fg);
+ }
// The next row's value in full, every line of it.
p.update(.{ .key = .{ .cp = Key.down } });
_ = frame.reset(.retain_capacity);
diff --git a/core/body_layer.zig b/core/body_layer.zig
index a182f218..0107b3e0 100644
--- a/core/body_layer.zig
+++ b/core/body_layer.zig
@@ -349,7 +349,11 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
panes.File.recolorSyntax(p, s, pane, f, r, tx, tw, body_h);
panes.Tables.paint(p, s, pane, r, tx, tw, body_h);
drawWrapMarkers(p, s, pane, r, tx, tw, body_h, pane_bg);
+ // A picker's landing line under the places it lights (UX D7).
+ const landing = pardes.Pick.landingLine(p, arena, pane);
+ if (landing) |line| paintLanding(p, s, pane, r, tx, tw, body_h, line);
pane.places.paint(p, s, pane, r, body_h);
+ if (landing) |line| paintLandingSpan(p, s, pane, r, f, line);
pardes.Prompt.paintGutter(p, s, pane, r, body_h);
panes.Query.paint(p, s, pane, r, body_h);
} else if (pane.isTerminal()) {
@@ -557,6 +561,8 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
// A pipe prompt's live run, as ghost lines over what is painted
// (Prompt.zig).
if (pane.file != null) try pardes.Prompt.ghosts(p, s, arena, pane, r, body_h);
+ // A code action's edit, previewed (Pick.zig).
+ if (pane.file != null) try pardes.Pick.ghosts(p, s, arena, pane, r, body_h);
if (rail) |bar| if (bar.rect.h > 0) {
// The rail covers the notice bands too: nothing else paints those
// two gutter columns, so a gap there keeps the frame-wide border
@@ -650,6 +656,47 @@ pub fn wordAt(p: *Pardes, arena: std.mem.Allocator, id: usize, row: usize, col:
return text.items[b.lo..b.hi];
}
+/// A picker's landing line (UX D7): its text on the hit ground across
+/// the body's width, and `▸` in the key ink in the gutter's cell after its
+/// number (the one a prompt's current place has, Prompt.paintGutter), on
+/// each row it wraps onto.
+fn paintLanding(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, tx: u16, tw: u16, body_h: u16, line: usize) void {
+ const roles = &p.chromeTheme().roles;
+ const gutter = File.gutterWidth(pane);
+ const number = gutter -| File.laneCells(pane) -| pane.layers.heat -| 1;
+ const body_y = p.bodyTop(pane, r);
+ var vr: u16 = pane.context_rows;
+ while (vr < body_h) : (vr += 1) {
+ const w = pane.wrapAt(p.settings.tab, vr);
+ if (w.line != @as(i32, @intCast(line))) continue;
+ for (gutter..tw) |x| {
+ const cell = s.at(tx + @as(u16, @intCast(x)), body_y + vr);
+ cell.default = false;
+ cell.style.bg = .{ .rgb = roles.hit };
+ }
+ if (gutter > 0 and w.at == 0) {
+ var style = s.at(tx + number, body_y + vr).style;
+ style.fg = .{ .rgb = roles.key };
+ s.set(tx + number, body_y + vr, "▸", style);
+ }
+ }
+}
+
+/// The landing line's matched span (a Grep's match at the row's column) on
+/// the current hit's ground, over the places lit on it (UX D7).
+fn paintLandingSpan(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, f: *panes.File.State, line: usize) void {
+ if (!pane.places.shows(pane)) return;
+ const hits = pane.places.hits.items;
+ const ls = File.lineStart(p.gpa, f, line);
+ const caret = ls + @as(usize, @intCast(@max(0, pane.body.cur_col)));
+ var i = panes.Places.firstFrom(hits, ls);
+ while (i < hits.len and hits[i].start <= caret) : (i += 1) {
+ if (hits[i].end <= caret) continue;
+ File.paintWordSelection(p, s, pane, r, @intCast(line), @intCast(hits[i].start - ls), @intCast(hits[i].end - ls), p.chromeTheme().roles.hit_current);
+ return;
+ }
+}
+
/// Painted targets (SPEC §4.4), while a motion root's level shows in this
/// body's tag: each of its keys at the line it would go to, in the gutter
/// (`g e t b .` for `g`; for `]` the next and for `[` the previous
@@ -706,10 +753,9 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
return;
}
if (cur.root != .goto and cur.root != .next and cur.root != .prev) return;
- const th = p.theme();
- const style: CellStyle = .{ .fg = .{ .rgb = p.chromeTheme().box }, .bg = if (th.bg) |c| .{ .rgb = c } else .default, .bold = true };
- // The rows painted so far: a second key on a row goes after the first.
- var painted: [bindings.max_children]u16 = undefined;
+ // Each target's row and key, in the level's order.
+ var rows: [bindings.max_children]u16 = undefined;
+ var keys: [bindings.max_children]u8 = undefined;
var n: usize = 0;
for (level) |c| {
const leaf = (c.node orelse continue).leaf orelse continue;
@@ -721,12 +767,34 @@ fn paintTargets(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const w = pane.wrapAt(tab, row);
if (w.line == line and w.at == 0) break;
} else continue;
- const x: u16 = @intCast(std.mem.count(u16, painted[0..n], &.{row}));
- if (x >= tw) continue;
- s.set(tx + x, body_y + row, bindings.keyName(c.key), style);
- painted[n] = row;
+ rows[n] = row;
+ keys[n] = c.key;
n += 1;
}
+ // In place of the line's number (UX D10): its cells blank and the
+ // row's keys, as many as they hold, right-aligned to its last digit,
+ // bold in the key ink on the gutter's ground. With no numbers, over
+ // the line's first cells on the selection's ground. Never a shift.
+ const ink = p.chromeTheme().roles.key;
+ const number = File.gutterWidth(pane) -| File.laneCells(pane) -| pane.layers.heat -| 1;
+ const cells = @min(if (number > 0) number else tw, tw);
+ for (rows[0..n], 0..) |row, i| {
+ if (std.mem.indexOfScalar(u16, rows[0..i], row) != null) continue;
+ const y = body_y + row;
+ const shown = @min(std.mem.count(u16, rows[0..n], &.{row}), cells);
+ if (number > 0) for (0..cells) |x| {
+ s.at(tx + @as(u16, @intCast(x)), y).text[0] = ' ';
+ s.at(tx + @as(u16, @intCast(x)), y).len = 1;
+ };
+ var x: u16 = if (number > 0) @intCast(cells - shown) else 0;
+ for (rows[i..n], keys[i..n]) |other, key| {
+ if (other != row) continue;
+ if (x >= (if (number > 0) cells else shown)) break;
+ const bg = if (number > 0) s.at(tx + x, y).style.bg else pardes.Color{ .rgb = p.theme().sel_bg };
+ s.set(tx + x, y, bindings.keyName(key), .{ .fg = .{ .rgb = ink }, .bg = bg, .bold = true });
+ x += 1;
+ }
+ }
}
/// A hover's answer as ghost lines under the line it was asked at (SPEC
@@ -873,21 +941,34 @@ fn targetLine(p: *Pardes, pane: *Pane, f: *panes.File.State, role: modal.Normal.
if (forward) return if (a < hits.len) lineOf(f, hits[a].start) else null;
return if (a > 0) lineOf(f, hits[a - 1].start) else null;
},
- inline .goto_function, .goto_comment, .goto_test => |r| {
- // The tree as the motion reads it, made once a revision; with
- // the Changes layer's lines in the buffer its offsets are not the
- // buffer's: not painted then.
- if (f.layer.lines.len > 0) return null;
- const tree = normal.fileTree(p, f) orelse return null;
- const object = @field(modal.Normal.Object, @tagName(r)["goto_".len..]);
- const at = lineStart(f, caret) + @as(usize, @intCast(@max(0, pane.body.cur_col)));
- const span = @import("syntax.zig").objectNext(f.path, tree, f.content, object, forward, @min(at, f.content.len), .{ lineStart(f, lo), lineStart(f, hi + 1) }) orelse return null;
- return lineOf(f, span.from);
- },
+ // With the Changes layer's lines in the buffer the tree's offsets
+ // are not the buffer's: not painted then.
+ .goto_function => return if (f.layer.lines.len > 0) null else treeTargets(p, pane, f, forward, lo, hi)[0],
+ .goto_comment => return if (f.layer.lines.len > 0) null else treeTargets(p, pane, f, forward, lo, hi)[1],
+ .goto_test => return if (f.layer.lines.len > 0) null else treeTargets(p, pane, f, forward, lo, hi)[2],
else => return null,
}
}
+/// The lines `]f`, `]c` and `]T` (or `[`'s) go to from the caret, in lines
+/// `lo` to `hi` (the rows shown): one pass of the grammar's query over the
+/// tree the motions read (made once a revision), kept on the pane while
+/// its text, its caret and those lines stay (`Pane.targets`), so a frame
+/// that paints them again asks nothing.
+fn treeTargets(p: *Pardes, pane: *Pane, f: *panes.File.State, forward: bool, lo: usize, hi: usize) [3]?usize {
+ const at = lineStart(f, @intCast(@max(0, pane.body.cur_row))) + @as(usize, @intCast(@max(0, pane.body.cur_col)));
+ const key: panes.TargetsKey = .{ .revision = f.revision, .at = at, .lo = lo, .hi = hi, .forward = forward };
+ if (pane.targets.key) |was| if (std.meta.eql(was, key)) return pane.targets.lines;
+ var lines: [3]?usize = @splat(null);
+ if (normal.fileTree(p, f)) |tree| {
+ var spans: [3]?@import("syntax.zig").Span = undefined;
+ @import("syntax.zig").objectNext(f.path, tree, f.content, &.{ .function, .comment, .@"test" }, forward, @min(at, f.content.len), .{ lineStart(f, lo), lineStart(f, hi + 1) }, &spans);
+ for (spans, &lines) |span, *line| line.* = if (span) |s| lineOf(f, s.from) else null;
+ }
+ pane.targets = .{ .key = key, .lines = lines };
+ return lines;
+}
+
fn blank(pane: *const Pane, line: usize) bool {
return std.mem.trim(u8, File.sourceLine(pane, @intCast(line)), " \t\r").len == 0;
}
@@ -1155,7 +1236,7 @@ test "a click under a message's detail lands on the row drawn there, a click on
try std.testing.expectEqualStrings("one\ntwo\nthree\nfour\nfive\nsix\n", pane.file.?.content);
}
-test "a motion root's level paints its targets in the gutter: `]` the next paragraph's p, `g` g and e; `m` browsed on `i` tints the braces' inside; nothing at rest" {
+test "a motion root's level paints its targets in place of their lines' numbers, right-aligned to the last digit, bold in the key ink: `]` the next paragraph's p and an unsaved edit's g, which `]g` goes to; `g` g and e; `m` browsed on `i` tints the braces' inside; nothing at rest (UX D10)" {
const Key = pardes.Key;
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 20 });
defer p.deinit();
@@ -1167,34 +1248,59 @@ test "a motion root's level paints its targets in the gutter: `]` the next parag
p.clock.now_ns = 5 * std.time.ns_per_s;
p.clock.stepped_ns = p.clock.now_ns;
pane.focus = .body;
- pane.body.cur_row = 1;
- pane.body.cur_col = 4;
+ // An edit on line 6, not saved; the caret back on line 2.
+ for ("5jAx") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ for ("4k") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row);
p.sync();
var s = try p.render(a);
const body = s.region(.body, id).?.rect;
const gutter = body.x;
- const at_rest = [_][]const u8{ s.at(gutter, body.y).grapheme(), s.at(gutter, body.y + 4).grapheme(), s.at(gutter, body.y + 6).grapheme() };
- for (at_rest) |g| try std.testing.expect(!std.mem.eql(u8, g, "p") and !std.mem.eql(u8, g, "g") and !std.mem.eql(u8, g, "e"));
+ // The number's cells: the gutter less its blank.
+ const number = panes.File.gutterWidth(pane) - 1;
+ const Field = struct {
+ /// Row `y`'s number field, its blanks trimmed.
+ fn of(sf: *pardes.Surface, x: u16, y: u16, n: u16, buf: *[16]u8) []const u8 {
+ var w = std.Io.Writer.fixed(buf);
+ for (0..n) |i| w.writeAll(sf.at(x + @as(u16, @intCast(i)), y).grapheme()) catch {};
+ return std.mem.trim(u8, w.buffered(), " ");
+ }
+ };
+ var buf: [16]u8 = undefined;
+ try std.testing.expectEqualStrings("5", Field.of(s, gutter, body.y + 4, number, &buf));
const plain_bg = s.at(gutter + panes.File.gutterWidth(pane) + 4, body.y + 1).style.bg;
- // `]`: nothing until its level shows; then `p` on the next paragraph.
+ // `]`: nothing until its level shows; then `p` on the next paragraph's
+ // number, `g` on the edit's, the digits gone.
p.update(.{ .key = .{ .cp = ']' } });
p.advance(p.clock.now_ns);
_ = frame.reset(.retain_capacity);
s = try p.render(a);
- try std.testing.expect(!std.mem.eql(u8, s.at(gutter, body.y + 4).grapheme(), "p"));
+ try std.testing.expectEqualStrings("5", Field.of(s, gutter, body.y + 4, number, &buf));
p.clock.now_ns = p.view().tag_state.due_ns;
_ = frame.reset(.retain_capacity);
s = try p.render(a);
- try std.testing.expectEqualStrings("p", s.at(gutter, body.y + 4).grapheme());
- p.update(.{ .key = .{ .cp = Key.escape } });
+ try std.testing.expectEqualStrings("p", Field.of(s, gutter, body.y + 4, number, &buf));
+ const key = s.at(gutter + number - 1, body.y + 4);
+ try std.testing.expectEqualStrings("p", key.grapheme());
+ try std.testing.expectEqual(pardes.Color{ .rgb = p.chromeTheme().roles.key }, key.style.fg);
+ try std.testing.expect(key.style.bold);
+ try std.testing.expect(std.mem.indexOfScalar(u8, Field.of(s, gutter, body.y + 5, number, &buf), 'g') != null);
+ try std.testing.expect(std.mem.indexOfAny(u8, Field.of(s, gutter, body.y + 5, number, &buf), "0123456789") == null);
+ // The text never shifts.
+ try std.testing.expectEqualStrings("t", s.at(gutter + panes.File.gutterWidth(pane) + 4, body.y + 5).grapheme());
+ // `]g` goes where its target is.
+ p.update(.{ .key = .{ .cp = 'g', .text = "g" } });
+ try std.testing.expectEqual(@as(i32, 5), pane.body.cur_row);
+ for ("4k") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
// `g`: its first and last lines.
p.update(.{ .key = .{ .cp = 'g' } });
p.advance(p.clock.now_ns);
p.clock.now_ns = p.view().tag_state.due_ns;
_ = frame.reset(.retain_capacity);
s = try p.render(a);
- try std.testing.expectEqualStrings("g", s.at(gutter, body.y).grapheme());
- try std.testing.expectEqualStrings("e", s.at(gutter, body.y + 6).grapheme());
+ try std.testing.expect(std.mem.indexOfScalar(u8, Field.of(s, gutter, body.y, number, &buf), 'g') != null);
+ try std.testing.expect(std.mem.indexOfScalar(u8, Field.of(s, gutter, body.y + 6, number, &buf), 'e') != null);
p.update(.{ .key = .{ .cp = Key.escape } });
// `m` unrolled, its cursor on `i`: the inside of the braces around the
// caret tinted.
@@ -1209,5 +1315,5 @@ test "a motion root's level paints its targets in the gutter: `]` the next parag
p.update(.{ .key = .{ .cp = Key.escape } });
_ = frame.reset(.retain_capacity);
s = try p.render(a);
- try std.testing.expectEqualStrings(at_rest[1], s.at(gutter, body.y + 4).grapheme());
+ try std.testing.expectEqualStrings("5", Field.of(s, gutter, body.y + 4, number, &buf));
}
diff --git a/core/builtins.zig b/core/builtins.zig
index 32af63f7..33f5824f 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -2188,7 +2188,11 @@ pub const Hover = struct {
}
};
-/// List the language server's code actions for the cursor, in a +Lsp.
+/// List the language server's code actions for the cursor, to apply one.
+///
+/// Typed where jumps walk, they are a picker in the pane's tag, the one
+/// under the cursor shown as its edit, applied by Enter or its digit; else
+/// a +Lsp lists them.
pub const CodeAction = struct {
pub fn run(c: Ctx) void {
c.p.lspRequest(c.id, .code_action, "");
diff --git a/core/colors.zig b/core/colors.zig
index ef2d5aae..b2069465 100644
--- a/core/colors.zig
+++ b/core/colors.zig
@@ -287,8 +287,8 @@ pub const Theme = struct {
lineno_active: ?[3]u8 = null,
/// A tag's selection, where it differs from the body's (acme's #9eeeee).
tag_sel_bg: ?[3]u8 = null,
- /// The tag of a reading pane, one a jump steps (Trail.zig): unset, the
- /// page tinted toward the search's ground, so it reads as the body's.
+ /// The tag of a reading pane, one a jump steps (Trail.zig): unset, or
+ /// too near the tag to see, the tag toward paper yellow (readingOf).
tag_reading_bg: ?[3]u8 = null,
/// Each pointer button's sweep, select, exec and look (Mouse.Button
/// order), and the ink over it. Unset, tints of `sel_bg` in `sel_fg`.
@@ -558,10 +558,11 @@ pub const ChromeTheme = struct {
lineno: [3]u8,
scroll_track: [3]u8,
scroll_thumb: [3]u8,
+ roles: Roles,
pub fn fromTheme(th: *const Theme) ChromeTheme {
// The initial chrome is resolved at compile time: contrast takes pow.
- @setEvalBranchQuota(200_000);
+ @setEvalBranchQuota(1_000_000);
const active_bg = focusTint(th);
const active_fg = th.tag_active_fg orelse th.tag_fg;
// A name is always tinted: a theme that names no tint gets one of
@@ -570,6 +571,7 @@ pub const ChromeTheme = struct {
const name_fg = th.tag_name_fg orelse (derivedNameTint(th, th.tag_fg, th.tag_bg) orelse th.tag_fg);
const active_name_fg = th.tag_active_name_fg orelse
(th.tag_name_fg orelse (derivedNameTint(th, active_fg, active_bg) orelse active_fg));
+ const reading = readingOf(th);
return .{
.tag_bg = th.tag_bg,
.tag_fg = th.tag_fg,
@@ -583,7 +585,7 @@ pub const ChromeTheme = struct {
.empty_col = th.empty_col orelse separatorOf(th),
.search_bg = th.search_bg orelse th.sel_bg,
.search_fg = th.search_fg orelse th.sel_fg,
- .tag_reading_bg = th.tag_reading_bg orelse mixOklab(th.bg orelse th.tag_bg, th.search_bg orelse th.sel_bg, 0.4),
+ .tag_reading_bg = reading,
.diagnostic_error = th.diagnostic_error orelse (th.fg orelse th.tag_fg),
.diagnostic_warning = th.diagnostic_warning orelse (th.fg orelse th.tag_fg),
.diagnostic_info = th.diagnostic_info orelse (th.fg orelse th.tag_fg),
@@ -595,10 +597,262 @@ pub const ChromeTheme = struct {
.lineno = th.lineno,
.scroll_track = th.scroll_track,
.scroll_thumb = th.scroll_thumb,
+ .roles = .of(th, th.tag_bg, active_bg, reading),
};
}
};
+/// A tag's ground in the walk UI (UX DESIGN.md D4): the plain tag's, the
+/// focused one's tint, a reading pane's tint, focused or not (its ink is
+/// the focused tag's while it has the keyboard).
+pub const TagGround = enum { plain, focused, reading, reading_focused };
+
+/// The inks drawn on one ground: labels and rows (`text`, 4.5:1 at least),
+/// hints, meta and forward steps (`dim`, 3.5:1, never under 3), and the
+/// spines and the rules between steps (`rule`, 2:1).
+pub const Inks = struct { ground: [3]u8, text: [3]u8, dim: [3]u8, rule: [3]u8 };
+
+/// The walk UI's colour roles (UX DESIGN.md D4), worked out from a theme
+/// once, with its chrome (never a frame), each held to its floor on every
+/// ground it is drawn on: a tag's four (`tag`) and a band's cursor row on
+/// each of them (`selected`, its ground that tag's selection).
+pub const Roles = struct {
+ tag: [4]Inks,
+ selected: [4]Inks,
+ /// The notice row's (the tagline's ground): its dim words.
+ notice: Inks,
+ /// Key cells, a level's or a row's key letters, `▶`, `•`, a target's
+ /// keys: 4.5:1 on every tag ground and on the selection.
+ key: [3]u8,
+ /// The letters a query matched: an ink, never a ground, 4.5:1 on every
+ /// tag ground and on the selection.
+ match: [3]u8,
+ /// The body's places and a preview's landing line, and the current
+ /// one (its matched span): grounds off the page, its ink on them 4.5:1.
+ hit: [3]u8,
+ hit_current: [3]u8,
+ /// A message's ink by its kind (Messages.ink): 4.5:1 on the tags and
+ /// the page.
+ err: [3]u8,
+ warn: [3]u8,
+ question: [3]u8,
+ hint: [3]u8,
+
+ pub const text_floor: f32 = 4.5;
+ pub const dim_floor: f32 = 3;
+ pub const rule_floor: f32 = 1.8;
+ pub const rule_ceiling: f32 = 2.5;
+ pub const ink_floor: f32 = 4.5;
+ pub const hit_floor: f32 = 1.25;
+ pub const hit_current_floor: f32 = 1.6;
+ pub const reading_distance: f32 = 0.04;
+
+ pub fn on(r: *const Roles, ground: TagGround) *const Inks {
+ return &r.tag[@backingInt(ground)];
+ }
+
+ pub fn selectedOn(r: *const Roles, ground: TagGround) *const Inks {
+ return &r.selected[@backingInt(ground)];
+ }
+
+ /// The selection's floor off a tag's ground: 1.4:1 on a dark tag, 1.25
+ /// on a light one.
+ pub fn selectionFloor(ground: [3]u8) f32 {
+ return if (relativeLuminance(ground) < 0.18) 1.4 else 1.25;
+ }
+
+ fn of(th: *const Theme, plain: [3]u8, focused: [3]u8, reading: [3]u8) Roles {
+ const grounds = [4][3]u8{ plain, focused, reading, reading };
+ const plain_ink = th.tag_fg;
+ const focused_ink = th.tag_active_fg orelse th.tag_fg;
+ const texts = [4][3]u8{ plain_ink, focused_ink, plain_ink, focused_ink };
+ var r: Roles = undefined;
+ for (&r.tag, &r.selected, grounds, texts) |*inks, *selected, ground, ink| {
+ inks.* = inksOn(ground, ink);
+ selected.* = inksOn(selectionOf(th.tag_sel_bg orelse th.sel_bg, ground, inks.text), inks.text);
+ }
+ r.notice = inksOn(th.tagline_bg orelse th.tag_bg, th.tagline_fg orelse th.tag_fg);
+ const tag_grounds = [_][3]u8{ plain, focused, reading, r.selected[0].ground, r.selected[1].ground, r.selected[2].ground, r.selected[3].ground };
+ r.key = pushAway(th.box, &tag_grounds, ink_floor);
+ r.match = pushAway(matchHue(th), &tag_grounds, ink_floor);
+ const page = th.bg orelse null_page;
+ const body_ink = th.fg orelse th.tag_fg;
+ const dark = relativeLuminance(page) < 0.18;
+ // The theme's search ground where it stands off the page and the
+ // body reads on it; else the page a little way toward its hue (the
+ // warm accent's without one). The current one as far past the hit
+ // as 32 % is past 18 % (38 past 22 on a light page).
+ const hue = th.search_bg orelse th.num;
+ const own = th.search_bg != null and contrast(hue, page) >= hit_floor and contrast(body_ink, hue) >= ink_floor;
+ const at: f32 = if (own) 1 else if (dark) 0.18 else 0.22;
+ r.hit = if (own) hue else hitOf(page, hue, body_ink, at, hit_floor);
+ const past: f32 = if (dark) 0.32 / 0.18 else 0.38 / 0.22;
+ r.hit_current = hitOf(page, hue, body_ink, at * past, hit_current_floor);
+ // Never fainter than the hit, where the ink holds both short.
+ if (contrast(r.hit_current, page) < contrast(r.hit, page)) r.hit_current = r.hit;
+ const message_grounds = [_][3]u8{ plain, focused, reading, page };
+ const ink = th.fg orelse th.tag_fg;
+ r.err = pushAway(th.diagnostic_error orelse ink, &message_grounds, ink_floor);
+ r.warn = pushAway(th.diagnostic_warning orelse ink, &message_grounds, ink_floor);
+ r.question = pushAway(th.diagnostic_info orelse ink, &message_grounds, ink_floor);
+ r.hint = pushAway(th.diagnostic_hint orelse ink, &message_grounds, ink_floor);
+ return r;
+ }
+};
+
+/// A tag's text, dim and rule inks on `ground`, from its ink (pushed to the
+/// text floor where it has less).
+fn inksOn(ground: [3]u8, ink: [3]u8) Inks {
+ const text = pushAway(ink, &.{ground}, Roles.text_floor);
+ return .{ .ground = ground, .text = text, .dim = toward(text, ground, 3.5), .rule = toward(text, ground, 2) };
+}
+
+/// `ink` mixed toward `ground` (OKLab) by hundredths as far as it still
+/// reads at `floor` on it: found by halves (its contrast falls as it nears
+/// the ground), seven mixes where a walk took up to a hundred (the first
+/// frame's bodyChrome derives them too).
+fn toward(ink: [3]u8, ground: [3]u8, floor: f32) [3]u8 {
+ const a = toOklab(ink);
+ const b = toOklab(ground);
+ var best = ink;
+ var lo: u32 = 0;
+ var hi: u32 = 101;
+ while (hi - lo > 1) {
+ const mid = (lo + hi) / 2;
+ const t = @as(f32, @floatFromInt(mid)) / 100;
+ const c = fromOklab(.{ a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t });
+ if (contrast(c, ground) >= floor) {
+ lo = mid;
+ best = c;
+ } else hi = mid;
+ }
+ return best;
+}
+
+/// `ink` pushed by fiftieths toward white or black, whichever reads better
+/// on all its grounds, until it reads at `floor` on every one; where no ink
+/// does (solarized's mid-grey tag), that end, the most any ink reaches.
+fn pushAway(ink: [3]u8, grounds: []const [3]u8, floor: f32) [3]u8 {
+ const white: [3]u8 = @splat(255);
+ const black: [3]u8 = @splat(0);
+ if (leastContrast(ink, grounds) >= floor) return ink;
+ const end = if (leastContrast(white, grounds) >= leastContrast(black, grounds)) white else black;
+ const a = toOklab(ink);
+ const b = toOklab(end);
+ var step: f32 = 0;
+ while (step <= 50) : (step += 1) {
+ const t = step / 50;
+ const c = fromOklab(.{ a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t });
+ if (leastContrast(c, grounds) >= floor) return c;
+ }
+ return end;
+}
+
+fn leastContrast(ink: [3]u8, grounds: []const [3]u8) f32 {
+ var least: f32 = 21;
+ for (grounds) |g| least = @min(least, contrast(ink, g));
+ return least;
+}
+
+/// The match's hue: the search's ink where it is a hue of its own (a port's
+/// is often the page's or the tag's, set for the search's ground), else the
+/// theme's warm accent.
+fn matchHue(th: *const Theme) [3]u8 {
+ const own = th.search_fg orelse return th.num;
+ const lab = toOklab(own);
+ return if (@sqrt(lab[1] * lab[1] + lab[2] * lab[2]) >= name_tint_chroma) own else th.num;
+}
+
+/// The selection a band's cursor row is drawn on over `ground`: the
+/// theme's where it stands off it, else moved by hundredths toward the
+/// text, then away from it, to the first that does with the text still at
+/// 4.5:1 on it; where none does (a tag whose text has no contrast to
+/// spare), the one furthest off it.
+fn selectionOf(own: [3]u8, ground: [3]u8, text: [3]u8) [3]u8 {
+ var best = own;
+ var best_off: f32 = 0;
+ const away: [3]u8 = if (relativeLuminance(text) > relativeLuminance(own)) @splat(0) else @splat(255);
+ if (contrast(own, ground) >= Roles.selectionFloor(ground) and contrast(text, own) >= Roles.text_floor) return own;
+ const o = toOklab(own);
+ for ([2][3]u8{ text, away }) |end| {
+ const e = toOklab(end);
+ var step: f32 = 0;
+ while (step <= 100) : (step += 1) {
+ const t = step / 100;
+ const c = fromOklab(.{ o[0] + (e[0] - o[0]) * t, o[1] + (e[1] - o[1]) * t, o[2] + (e[2] - o[2]) * t });
+ if (contrast(text, c) < Roles.text_floor) break;
+ const off = contrast(c, ground) / Roles.selectionFloor(ground);
+ if (off >= 1) return c;
+ if (off > best_off) {
+ best = c;
+ best_off = off;
+ }
+ }
+ }
+ return best;
+}
+
+/// A ground off `page` toward `hue` at `t` (past 1, beyond the hue, as far
+/// as the gamut goes), held where the body's `ink` reads on it at 4.5:1
+/// (or its own on the page, where that is less); moved on toward the ink
+/// until it stands off the page at `floor`, as far as the ink allows.
+fn hitOf(page: [3]u8, hue: [3]u8, ink: [3]u8, t: f32, floor: f32) [3]u8 {
+ const a = toOklab(page);
+ const b = toOklab(hue);
+ const ink_floor = @min(Roles.ink_floor, contrast(ink, page));
+ var k = t;
+ var c = fromOklab(.{ a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, a[2] + (b[2] - a[2]) * k });
+ while (contrast(ink, c) < ink_floor and k > 0) {
+ k -= t / 50;
+ c = fromOklab(.{ a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k, a[2] + (b[2] - a[2]) * k });
+ }
+ const start = c;
+ var step: f32 = 1;
+ while (contrast(c, page) < floor and step <= 50) : (step += 1) {
+ const next = mixOklab(start, ink, step / 100);
+ if (contrast(ink, next) < ink_floor) break;
+ c = next;
+ }
+ return c;
+}
+
+/// A reading pane's tag (UX DESIGN.md D4): the theme's own where it stands
+/// off the tag, else the tag shifted toward paper yellow by 0.04 in OKLab
+/// and lighter by half that on a dark tag (darker on a light), so it reads
+/// as a page; then less light, or darker, where its text would lose
+/// contrast, and further where the bytes cannot show so small a step (a
+/// near-black tag).
+fn readingOf(th: *const Theme) [3]u8 {
+ if (th.tag_reading_bg) |own| if (oklabDistance(toOklab(own), toOklab(th.tag_bg)) >= Roles.reading_distance) return own;
+ const tag = toOklab(th.tag_bg);
+ const paper = toOklab(.{ 0xdc, 0xc8, 0x78 });
+ const da = paper[1] - tag[1];
+ const db = paper[2] - tag[2];
+ const n = @max(@sqrt(da * da + db * db), 1e-6);
+ const sign: f32 = if (relativeLuminance(th.tag_bg) < 0.18) 1 else -1;
+ // Away from the text's lightness, where the first lean costs it.
+ const away: f32 = if (relativeLuminance(th.tag_fg) > relativeLuminance(th.tag_bg)) -1 else 1;
+ const inks = [2][3]u8{ th.tag_fg, th.tag_active_fg orelse th.tag_fg };
+ var best = th.tag_bg;
+ var best_text: f32 = -21;
+ var reach = Roles.reading_distance;
+ while (reach <= 0.2) : (reach *= 1.25) {
+ for ([_]f32{ sign * 0.5, 0, away * 0.5, away, away * 1.5 }) |lean| {
+ const c = fromOklab(.{ tag[0] + lean * reach, tag[1] + da / n * reach, tag[2] + db / n * reach });
+ if (oklabDistance(toOklab(c), tag) < Roles.reading_distance) continue;
+ // Each ink by its own floor: 7:1, or what it has on the tag.
+ var text: f32 = 21;
+ for (inks) |ink| text = @min(text, contrast(ink, c) - (@min(7, contrast(ink, th.tag_bg)) - 0.01));
+ if (text >= 0) return c;
+ if (text > best_text) {
+ best = c;
+ best_text = text;
+ }
+ }
+ }
+ return best;
+}
+
pub const initial_chrome = ChromeTheme.fromTheme(&themes[0]);
fn nextThemeFileGeneration(p: *Pardes) u32 {
@@ -1281,3 +1535,89 @@ test "every theme tints its names off the tag's ink, and they read on both groun
}
}
}
+
+test "every theme's walk UI roles meet their floors on every ground they are drawn on, dark and light" {
+ // Where a theme's own colours leave no room for a floor, the most it
+ // allows: an ink's on a mid-grey tag (solarized's) is the better of
+ // white and black there; a ground's is where the ink it carries would
+ // drop under its floor.
+ const white: [3]u8 = @splat(255);
+ const black: [3]u8 = @splat(0);
+ const Reach = struct {
+ fn of(grounds: []const [3]u8) f32 {
+ return @max(leastContrast(white, grounds), leastContrast(black, grounds));
+ }
+ };
+ const a = std.testing.allocator;
+ const Check = struct { what: []const u8, got: f32, floor: f32 };
+ var checks: std.ArrayList(Check) = .empty;
+ defer checks.deinit(a);
+ var failed: usize = 0;
+ for (&themes) |*th| {
+ checks.clearRetainingCapacity();
+ const chrome = ChromeTheme.fromTheme(th);
+ const r = &chrome.roles;
+ const page = th.bg orelse null_page;
+ const body_ink = th.fg orelse th.tag_fg;
+ const tags = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, r.selected[0].ground, r.selected[1].ground, r.selected[2].ground, r.selected[3].ground };
+ const messages = [_][3]u8{ r.tag[0].ground, r.tag[1].ground, r.tag[2].ground, page };
+ for (r.tag ++ r.selected ++ [1]Inks{r.notice}) |inks| {
+ const text = contrast(inks.text, inks.ground);
+ try checks.append(a, .{ .what = "text", .got = text, .floor = @min(Roles.text_floor, Reach.of(&.{inks.ground})) });
+ try checks.append(a, .{ .what = "dim", .got = contrast(inks.dim, inks.ground), .floor = @min(Roles.dim_floor, text) });
+ try checks.append(a, .{ .what = "dim under text", .got = text - contrast(inks.dim, inks.ground), .floor = 0 });
+ }
+ try checks.append(a, .{ .what = "key", .got = leastContrast(r.key, &tags), .floor = @min(Roles.ink_floor, Reach.of(&tags)) });
+ try checks.append(a, .{ .what = "match", .got = leastContrast(r.match, &tags), .floor = @min(Roles.ink_floor, Reach.of(&tags)) });
+ for (r.tag) |inks| {
+ try checks.append(a, .{ .what = "rule", .got = contrast(inks.rule, inks.ground), .floor = Roles.rule_floor });
+ try checks.append(a, .{ .what = "rule ceiling", .got = Roles.rule_ceiling - contrast(inks.rule, inks.ground), .floor = 0 });
+ }
+ for ([_][3]u8{ r.err, r.warn, r.question, r.hint }) |ink|
+ try checks.append(a, .{ .what = "message", .got = leastContrast(ink, &messages), .floor = @min(Roles.ink_floor, Reach.of(&messages)) });
+ // A selection off its tag by 1.4:1 (1.25 light) with the text at
+ // 4.5:1 on it, where the text has that much over the tag.
+ for (r.tag, r.selected) |inks, selected| {
+ const floor = Roles.selectionFloor(inks.ground);
+ const room = contrast(inks.text, inks.ground) >= floor * Roles.text_floor * 1.03;
+ try checks.append(a, .{ .what = "selection", .got = contrast(selected.ground, inks.ground), .floor = if (room) floor else 0 });
+ }
+ try checks.append(a, .{ .what = "reading", .got = oklabDistance(toOklab(chrome.tag_reading_bg), toOklab(th.tag_bg)), .floor = Roles.reading_distance });
+ for ([_][3]u8{ th.tag_fg, th.tag_active_fg orelse th.tag_fg }) |ink|
+ try checks.append(a, .{ .what = "text on reading", .got = contrast(ink, chrome.tag_reading_bg), .floor = @min(7, contrast(ink, th.tag_bg)) - 0.02 });
+ const ink_floor = @min(Roles.ink_floor, contrast(body_ink, page));
+ for ([_][3]u8{ r.hit, r.hit_current }, [_]f32{ Roles.hit_floor, Roles.hit_current_floor }) |ground, floor| {
+ const on = contrast(body_ink, ground);
+ try checks.append(a, .{ .what = "hit", .got = contrast(ground, page), .floor = if (on < ink_floor + 0.3) 0 else floor });
+ try checks.append(a, .{ .what = "ink on hit", .got = on, .floor = ink_floor - 0.01 });
+ }
+ try checks.append(a, .{ .what = "current over hit", .got = contrast(r.hit_current, page) - contrast(r.hit, page), .floor = 0 });
+ for (checks.items) |c| if (c.got < c.floor - 0.005) {
+ failed += 1;
+ std.debug.print("{s}: {s} {d:.2} under {d:.2}\n", .{ th.name, c.what, c.got, c.floor });
+ };
+ }
+ try std.testing.expectEqual(0, failed);
+}
+
+test "neonotte84's and acme's roles are the ones UX derived (DESIGN.md D4, tools/roles.py)" {
+ const Want = struct { name: []const u8, text: ?[3]u8, dim: [3]u8, rule: [3]u8, key: [3]u8, match: [3]u8, reading: [3]u8, hit: [3]u8, hit_current: [3]u8 };
+ const wants = [_]Want{
+ .{ .name = "neonotte84", .text = .{ 0xb5, 0xbf, 0xe3 }, .dim = .{ 0x70, 0x76, 0x8f }, .rule = .{ 0x4c, 0x50, 0x63 }, .key = .{ 0xf8, 0xde, 0xd9 }, .match = .{ 0xf1, 0xa2, 0x71 }, .reading = .{ 0x29, 0x27, 0x1e }, .hit = .{ 0x36, 0x28, 0x2a }, .hit_current = .{ 0x52, 0x38, 0x31 } },
+ // acme's key and match a little darker than UX's #5c5c8d and
+ // #974d00 (which hold on its tag and its #9eeeee): a reading pane's
+ // band's selection is pushed off the reading ground (#9eeeee is
+ // 1.12:1 off #f3f0cc), and they read on that one too.
+ .{ .name = "acme", .text = null, .dim = .{ 0x7a, 0x86, 0x86 }, .rule = .{ 0xa8, 0xb7, 0xb7 }, .key = .{ 0x55, 0x55, 0x83 }, .match = .{ 0x8f, 0x48, 0x00 }, .reading = .{ 0xf3, 0xf0, 0xcc }, .hit = .{ 0xec, 0xd8, 0xbb }, .hit_current = .{ 0xdd, 0xbc, 0x99 } },
+ };
+ for (wants) |want| {
+ const chrome = ChromeTheme.fromTheme(&themes[themeIndex(want.name).?]);
+ const plain = chrome.roles.on(.plain);
+ const got = [_][3]u8{ plain.text, plain.dim, plain.rule, chrome.roles.key, chrome.roles.match, chrome.tag_reading_bg, chrome.roles.hit, chrome.roles.hit_current };
+ const expected = [_][3]u8{ want.text orelse plain.text, want.dim, want.rule, want.key, want.match, want.reading, want.hit, want.hit_current };
+ for (got, expected, 0..) |g, e, i| for (g, e) |x, y| if (@abs(@as(i16, x) - y) > 2) {
+ std.debug.print("{s} role {d}: {x} for {x}\n", .{ want.name, i, g, e });
+ return error.TestUnexpectedResult;
+ };
+ }
+}
diff --git a/core/draw.zig b/core/draw.zig
index 2ef72f0e..a459e3e9 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -173,10 +173,15 @@ pub fn place(p: *Pardes, s: *Surface) void {
/// A pane's grip in the grid: `box` focused, else halfway between its ring
/// and `box_dim`, so it shows on its tag without the ring a pixel shell
/// draws (gui.zig draws its button from the region and Chrome instead).
-fn gripBg(p: *const Pardes, active: bool) [3]u8 {
+/// A grip cell's colour: the focused pane's button, else its ring mixed
+/// with the box's dim fill; where that fill is the tag's own ground
+/// (acme's), a reading pane's is its tint, as a window rings a reading
+/// pane's tag ground (gui.zig gripFill).
+fn gripBg(p: *const Pardes, active: bool, reading: bool) [3]u8 {
const chrome = p.chromeTheme();
if (active) return chrome.box;
- return colors.mix(boxBorder(p), chrome.box_dim);
+ const fill = if (reading and std.mem.eql(u8, &chrome.box_dim, &chrome.tag_bg)) chrome.tag_reading_bg else chrome.box_dim;
+ return colors.mix(boxBorder(p), fill);
}
/// An unfocused grip's ring, and a dirty one's fill (colors.Theme).
@@ -464,7 +469,7 @@ fn renderPane(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r:
// on the dirty colour, a cue that survives any palette.
const band = tagGround(p, pane, active);
const dirty = tagline.dirty(pane);
- const box_bg = gripBg(p, active);
+ const box_bg = gripBg(p, active, pardes.Trail.reading(p, pane));
const box_style: CellStyle = .{
.fg = .{ .rgb = inkOn(box_bg) },
.bg = .{ .rgb = box_bg },
@@ -628,12 +633,21 @@ fn paintNoticeRow(p: *Pardes, s: *Surface) !void {
const layer = &s.tag_layers[pardes.NOTICE_ROW_LAYER];
try renderHeaderLayer(p, layer, .notice_row, 0, viewport, row.text, 0, chrome.tagline_bg, chrome.tagline_fg);
if (layer.rows == 0) return;
- const dim: Color = .{ .rgb = colors.mix(chrome.tagline_fg, chrome.tagline_bg) };
+ // The dim ink of the notice row's ground (colors.Roles: 3:1 at least).
+ const dim: Color = .{ .rgb = chrome.roles.notice.dim };
const ink: Color = .{ .rgb = chrome.tagline_fg };
const cells = layer.cells[0..layer.cols];
const tab = p.settings.tab;
const left = @min(cells.len, panes.File.displayWidth(tab, row.text[0..row.left]));
const right = @min(cells.len, panes.File.displayWidth(tab, row.text[0..row.right]));
+ // A picker's sentence: dim, its address in the text's ink.
+ if (row.quiet_left) {
+ const lo = panes.File.displayWidth(tab, row.text[0..@min(row.word[0], row.left)]);
+ const hi = panes.File.displayWidth(tab, row.text[0..@min(row.word[1], row.left)]);
+ for (cells[0..left], 0..) |*cell, x| if ((x < lo or x >= hi) and std.meta.eql(cell.style.fg, ink)) {
+ cell.style.fg = dim;
+ };
+ }
if (row.lead) |lead| {
if (lead.kind == .@"error" or lead.kind == .warn) if (cells.len > 0 and std.meta.eql(cells[0].style.fg, ink)) {
cells[0].style.fg = .{ .rgb = if (lead.kind == .@"error") chrome.diagnostic_error else chrome.diagnostic_warning };
@@ -879,12 +893,16 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
const layer = &s.tag_layers[pardes.BAND_LAYER];
if (r.w <= TAG_TEXT_INSET) return;
const band = (try pardes.Band.of(p, arena, pane, id)) orelse return;
- const th = p.theme();
const chrome = p.chromeTheme();
const tab = p.settings.tab;
const columns = @max(band.columns, 1);
- const bg = tagGround(p, pane, active);
- const fg = if (active) chrome.tag_active_fg else chrome.tag_fg;
+ // The walk UI's inks on this tag's ground (colors.Roles, UX DESIGN.md
+ // D4), and on its cursor row's selection.
+ const ground = groundOf(p, pane, active);
+ const inks = chrome.roles.on(ground);
+ const selected = chrome.roles.selectedOn(ground);
+ const bg = inks.ground;
+ const fg = inks.text;
const storage = try arena.alloc(Cell, @as(usize, columns) * rows);
@memset(storage, .{});
var t: Surface = .{ .cols = columns, .rows = rows, .cells = storage, .tab = tab };
@@ -893,36 +911,59 @@ fn joinBand(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: R
t.fill(0, row, columns, 1, .{ .bg = .{ .rgb = bg }, .font_role = .tagline });
const ln = try band.line(arena, tab, row);
_ = t.print(0, row, columns, ln.text, .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .font_role = .tagline });
- // The spines and the rules between steps: the key ink.
+ // The spines and the rules between steps in the rule ink; a row's
+ // `▶` (the cursor) and `•` (marked) in the key ink.
var col: u16 = 0;
var at: usize = 0;
while (at < ln.text.len and col < columns) : (col += 1) {
const next = modal.nextGrapheme(ln.text, at);
- if (std.mem.eql(u8, ln.text[at..next], "│")) t.at(col, row).style.fg = .{ .rgb = chrome.box };
- if (std.mem.eql(u8, ln.text[at..next], "▶")) t.at(col, row).style.fg = .{ .rgb = chrome.box };
+ const glyph = ln.text[at..next];
+ if (std.mem.eql(u8, glyph, "│")) t.at(col, row).style.fg = .{ .rgb = inks.rule };
+ if (std.mem.eql(u8, glyph, "▶") or std.mem.eql(u8, glyph, "•")) t.at(col, row).style.fg = .{ .rgb = chrome.roles.key };
at = next;
}
for (ln.parts) |part| {
const end = @min(columns, part.col + part.width);
- // The cursor's row across its step's width, its lead too (UX D5).
- if (part.row.on and part.col < end) t.tint(part.col -| 2, row, end - (part.col -| 2), th.tag_sel_bg orelse th.sel_bg, th.sel_fg);
+ const on = if (part.row.on) selected else inks;
+ // The cursor's row across its step's width, its lead too (UX
+ // D5), the lead's `▶` keeping the key ink (D4).
+ if (part.row.on and part.col < end) {
+ const lead = part.col -| 2;
+ t.tint(lead, row, part.col - lead, selected.ground, null);
+ t.tint(part.col, row, end - part.col, selected.ground, selected.text);
+ }
var c = part.col;
var b: usize = 0;
while (b < part.row.text.len and c < end) : (c += 1) {
const next = modal.nextGrapheme(part.row.text, b);
const style = &t.at(c, row).style;
if (b < part.row.key) {
- style.fg = .{ .rgb = chrome.box };
+ style.fg = .{ .rgb = chrome.roles.key };
style.bold = true;
}
+ // A chord (Help's `SPC h t`): keys, at the text's weight.
+ 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)) style.dim = true;
+ 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 };
+ for (part.row.keys) |k| if (k == b) {
+ style.fg = .{ .rgb = chrome.roles.key };
+ style.bold = true;
+ };
if (part.row.under) style.ul = .single;
+ // A matched letter: the match ink, bold, on the row's own
+ // ground (never a ground of its own: on the cursor row's
+ // selection one vanished).
for (part.row.marks) |m| if (m == b) {
- style.bg = .{ .rgb = chrome.search_bg };
+ style.fg = .{ .rgb = chrome.roles.match };
+ style.bold = true;
};
b = next;
}
+ // Its meta, right-aligned in the part (Band.line), dim.
+ if (pardes.Band.metaShown(tab, part.row, part.width) and part.col + part.width <= columns) {
+ const meta: u16 = @intCast(panes.File.displayWidth(tab, part.row.meta));
+ for (part.col + part.width - meta..part.col + part.width) |x| t.at(@intCast(x), row).style.fg = .{ .rgb = on.dim };
+ }
}
}
const count = @as(usize, columns) * rows;
@@ -968,9 +1009,14 @@ fn inkTag(p: *Pardes, s: *Surface, shown: tagline.Shown, lines: []const []const
/// A pane's tag's ground: a reading pane's tint (its focus is its grip's),
/// else the focused tag's or the tag's.
fn tagGround(p: *Pardes, pane: *const Pane, active: bool) [3]u8 {
- const chrome = p.chromeTheme();
- if (pardes.Trail.reading(p, pane)) return chrome.tag_reading_bg;
- return if (active) chrome.tag_active_bg else chrome.tag_bg;
+ return p.chromeTheme().roles.on(groundOf(p, pane, active)).ground;
+}
+
+/// Which of a tag's grounds pane `pane`'s is: its walk UI inks
+/// (colors.Roles) are that ground's.
+fn groundOf(p: *Pardes, pane: *const Pane, active: bool) colors.TagGround {
+ if (pardes.Trail.reading(p, pane)) return if (active) .reading_focused else .reading;
+ return if (active) .focused else .plain;
}
fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane, r: Rect, id: usize, active: bool) !void {
@@ -982,7 +1028,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const rows = @min(pane.tag_rows -| pane.band_rows, MAX_TAG_ROWS);
const page_rgb = th.bg orelse th.tag_bg;
// Focus is visible along the tag without changing its live text grid.
- const tag_bg = tagGround(p, pane, active);
+ const inks = chrome.roles.on(groundOf(p, pane, active));
+ const tag_bg = inks.ground;
const tag_fg = if (active) chrome.tag_active_fg else chrome.tag_fg;
const tag_style: CellStyle = .{ .fg = .{ .rgb = tag_fg }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline };
// Padding belongs to the same font row but keeps its default ink: a
@@ -996,6 +1043,8 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const head = try TagState.head(p, arena, pane);
const tail = if (head) |h| h.text else tagline.curTail(pane);
const prefix_len = whole.len - tail.len;
+ // Out of rest, the walk UI's text ink (at rest the tag's own, unchanged).
+ const text_style: CellStyle = if (head == null) tag_style else .{ .fg = .{ .rgb = inks.text }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline };
// A row per line shown, from `tag_top`: the tag's first line carries
// the prefix, the rest are the tag's own text alone.
const top = pane.tag_top;
@@ -1033,7 +1082,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
for (lines[0..rows], 0..) |line, row| {
// The scroll is the caret's line's: a shorter row shows nothing.
const start = @min(line.len, panes.File.rawAtDisplay(p.settings.tab, line, pane.tag_scroll));
- _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], tag_style);
+ _ = s.print(tx, tag_y + @as(u16, @intCast(row)), tw, line[start..], text_style);
}
// Out of rest the rows the tag keeps from rest under the head's own:
// the spines on through them, under the key cells (UX D5).
@@ -1044,7 +1093,7 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
if (at > first.len) break;
const col = panes.File.rawDisplayCol(p.settings.tab, first, at);
if (col >= tw) break;
- for (nlines..rows) |row| s.set(tx + @as(u16, @intCast(col)), tag_y + @as(u16, @intCast(row)), "│", .{ .fg = .{ .rgb = chrome.box }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline }); // P2: the rule role (UX D4)
+ for (nlines..rows) |row| s.set(tx + @as(u16, @intCast(col)), tag_y + @as(u16, @intCast(row)), "│", .{ .fg = .{ .rgb = inks.rule }, .bg = .{ .rgb = tag_bg }, .font_role = .tagline });
}
};
// The pane's progress at its first row's right end, where the row has
@@ -1067,22 +1116,22 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
// A walk's forward steps, after the name, dimmed (Trail.zig); its fold
// `+N` too; the word n walks underlined in the key ink (UX D8).
const ahead = tagline.forwardSpan(p, pane);
- if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), chrome.lineno, false);
+ if (ahead[0] < ahead[1]) inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, ahead[0], @min(ahead[1], first_line.len), inks.dim, false);
if (pane.file != null and pane.trail.n > 0 and !pardes.Trail.outOfRest(p, pane)) {
const kept = tagline.folded(p, pane);
const t = &pane.trail;
const first: usize = @intFromBool(t.steps[0] == .owner);
if (t.isFolded(first, kept)) {
const fold = t.spanOf(first, kept);
- inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, fold[0], @min(fold[1], first_line.len), chrome.lineno, false);
+ inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, fold[0], @min(fold[1], first_line.len), inks.dim, false);
}
if (t.walked()) |i| if (!t.isFolded(i, kept)) {
const word = t.spanOf(i, kept);
- inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, word[0], @min(word[1], first_line.len), chrome.box, true); // P2: the key role
+ inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, word[0], @min(word[1], first_line.len), chrome.roles.key, true);
};
}
// A search word its places no longer light, dimmed (Prompt.zig).
- if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), chrome.lineno, false);
+ if (pardes.Prompt.unlit(p, pane)) |span| inkTag(p, s, shown, lines[0..rows], top, tx, tag_y, tw, span[0], @min(span[1], first_line.len), inks.dim, false);
// The head's keys in the key ink, its dimmed, underlined and struck
// words (TagState.Span), over whichever rows they wrapped onto.
if (head) |h| for (h.spans) |span| {
@@ -1100,13 +1149,14 @@ fn paintPaneTag(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane,
const style = &s.at(tx + @as(u16, @intCast(col)), y).style;
switch (span.style) {
.key => {
- style.fg = .{ .rgb = chrome.box };
+ style.fg = .{ .rgb = chrome.roles.key };
style.bold = true;
},
- .dim => style.dim = true,
+ .dim => style.fg = .{ .rgb = inks.dim },
.under => style.ul = .single,
.strike => style.strikethrough = true,
- .err => style.fg = .{ .rgb = chrome.diagnostic_error },
+ .err => style.fg = .{ .rgb = chrome.roles.err },
+ .rule => style.fg = .{ .rgb = inks.rule },
}
}
}
@@ -1180,6 +1230,7 @@ test "an unfocused grip shows on its tag in the grid, in every native theme" {
p.newScratchBelow(0);
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
defer arena.deinit();
+ var ok = true;
for (pardes.themes[0..colors.native_count], 0..) |theme, index| {
colors.setThemeIndex(p, index);
p.view().active = 1;
@@ -1187,12 +1238,16 @@ test "an unfocused grip shows on its tag in the grid, in every native theme" {
const s = try p.render(arena.allocator());
const r = p.view().rects[0];
const grip = s.at(r.x, p.tagTop(p.panes[0].?, r)).style.bg.rgb;
- const ratio = colors.contrast(grip, p.chromeTheme().tag_bg);
+ // Its tag's ground: a reading pane's the reading tint.
+ const ratio = colors.contrast(grip, tagGround(p, p.panes[0].?, false));
// ponytail: dark and helix have always had a faint grip (1.2:1); flagged, not changed here.
const floor: f32 = if (std.mem.eql(u8, theme.name, "dark") or std.mem.eql(u8, theme.name, "helix")) 1.2 else 1.5;
- if (ratio < floor) std.debug.print("{s}: grip {d:.2}\n", .{ theme.name, ratio });
- try std.testing.expect(ratio >= floor);
+ // Against a reading tint (UX D4's, lighter on a dark tag) a little
+ // less: forestbones_dark's 1.486, nordbones' 1.488, monokai's 1.4999.
+ if (ratio < floor - 0.02) std.debug.print("{s}: grip {d:.4}\n", .{ theme.name, ratio });
+ ok = ok and ratio >= floor - 0.02;
}
+ try std.testing.expect(ok);
}
test "a grip's four states, focused or not and clean or dirty, are each its own in every native theme" {
@@ -1777,3 +1832,70 @@ test "progress is said at the right end of its tag: a pane's at its tag's, a ser
s = try p.render(frame.allocator());
try std.testing.expect(std.mem.indexOf(u8, Row.of(s, tag_y, &buf), "\u{22ef}") == null);
}
+
+test "a tag out of rest draws its keys bold in the key ink and its hint in the dim ink, never faint (UX D4)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ const roles = &p.chromeTheme().roles;
+ const inks = roles.on(if (pardes.Trail.reading(p, pane)) .reading_focused else .focused);
+ // SPC's level rolled, after its delay: `␣ ▸ … l lsp… … ↓ unroll · ? help`.
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ p.update(.{ .key = .{ .cp = ' ' } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ p.sync();
+ const s = try p.render(a);
+ const r = p.view().rects[p.view().active];
+ const row = s.cells[@as(usize, r.y) * s.cols ..][0 .. @as(usize, s.cols) * (pane.tag_rows - pane.band_rows)];
+ const Row = struct {
+ fn find(cells: []const Cell, word: []const u8) ?usize {
+ var at: usize = 0;
+ while (at + word.len <= cells.len) : (at += 1) {
+ for (word, cells[at..][0..word.len]) |c, cell| {
+ if (cell.len != 1 or cell.text[0] != c) break;
+ } else return at;
+ }
+ return null;
+ }
+ };
+ const hint = Row.find(row, "unroll").?;
+ try std.testing.expectEqual(Color{ .rgb = inks.dim }, row[hint].style.fg);
+ for (row) |cell| try std.testing.expect(!cell.style.dim);
+ var keys: usize = 0;
+ for (row) |cell| if (std.meta.eql(cell.style.fg, Color{ .rgb = roles.key })) {
+ try std.testing.expect(cell.style.bold);
+ keys += 1;
+ };
+ try std.testing.expect(keys > 3);
+}
+
+test "an unfocused reading pane's box in the grid is its ring round the reading tint where the box's fill is the tag's own ground (acme's), as a window draws it; a held pane's, or another theme's, as before" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ const reader = p.view().active;
+ p.newScratchBelow(reader);
+ colors.setThemeIndex(p, colors.themeIndex("acme").?);
+ p.sync();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ try std.testing.expect(pardes.Trail.reading(p, pane) and p.view().active != reader);
+ var s = try p.render(frame.allocator());
+ const r = p.view().rects[reader];
+ const want = colors.mix(boxBorder(p), p.chromeTheme().tag_reading_bg);
+ for (0..config.GUTTER) |x| try std.testing.expectEqual(Color{ .rgb = want }, s.at(r.x + @as(u16, @intCast(x)), r.y).style.bg);
+ // Held, the ring round the plain box.
+ pane.trail.held = true;
+ s = try p.render(frame.allocator());
+ try std.testing.expectEqual(Color{ .rgb = colors.mix(boxBorder(p), p.chromeTheme().tag_bg) }, s.at(r.x, r.y).style.bg);
+ // orchard's box has a fill of its own: a reader's keeps it.
+ pane.trail.held = false;
+ colors.setThemeIndex(p, colors.themeIndex("orchard").?);
+ s = try p.render(frame.allocator());
+ try std.testing.expectEqual(Color{ .rgb = colors.mix(boxBorder(p), p.chromeTheme().box_dim) }, s.at(r.x, r.y).style.bg);
+}
diff --git a/core/fs.zig b/core/fs.zig
index 6b43ba67..594c89cf 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", "refused", "failure", "failure_len", "no_pane_slot", "no_pane_slot_len",
+ "serving", "typed", "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",
@@ -910,6 +910,10 @@ pub const Namespace = struct {
/// A 9P request is being served (Pardes.serveFs): a prompt it opens is
/// a question for the log (`ask`), answered with `answer`.
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 dea0236f..696bd659 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -2033,8 +2033,17 @@ fn ownerOf(ch: *const Changes, f: *const File.State, row: usize) PinIndex {
/// with none shown, or none that way, or none in the `most` lines looked
/// at (a body's painted targets look at the rows shown alone).
pub fn nextChange(p: *Pardes, pane: *const Pane, from: usize, forward: bool, most: usize) ?usize {
- if (pane.layers.lanes == 0) return null;
const f = if (pane.file) |*file| file else return null;
+ // No changes shown: the last edit not saved yet is one (POLISH 11:
+ // `]g` and its painted target found nothing in an edited file).
+ if (pane.layers.lanes == 0) {
+ if (f.revision == f.saved_revision) return null;
+ const at = pane.body.last_edit orelse return null;
+ const line: usize = @intCast(@max(0, at.row));
+ if (forward and line > from and line - from <= most) return line;
+ if (!forward and line < from and from - line <= most) return line;
+ return null;
+ }
const ch = answered(p, f.layer.owner) orelse return null;
const n = File.lineCount(f.content);
var row = from;
diff --git a/core/look.zig b/core/look.zig
index 21043250..f9dcfbc3 100644
--- a/core/look.zig
+++ b/core/look.zig
@@ -803,7 +803,7 @@ pub fn advanceLookHover(p: *Pardes) void {
p.look_hover_wait = null;
}
-pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center, keep }) void {
+pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center, third, keep }) void {
if (id >= MAX_PANES) return;
const pane = p.panes[id] orelse return;
p.view().active = id;
@@ -822,7 +822,9 @@ pub fn focusPaneLine(p: *Pardes, id: usize, at_in: Spot, landing: enum { center,
if (at.line > panes.File.nlines(p.gpa, f)) return;
// centred (its first row of text half the body's rows down, as
// zz), clamped at the top; a text that fits is shown whole
- if (landing == .center) panes.File.setTop(pane, if (pane.textFits()) .{ .line = 0 } else panes.File.walkRows(p.settings.tab, pane, .{ .line = at.line - 1, .row = panes.File.rowOf(p.settings.tab, pane, at.line - 1, 0) }, -@as(i64, pane.rows / 2)).to);
+ // or a third of them down (a picker's preview, UX D7: context above
+ // its landing line, the rest below)
+ if (landing != .keep) panes.File.setTop(pane, if (pane.textFits()) .{ .line = 0 } else panes.File.walkRows(p.settings.tab, pane, .{ .line = at.line - 1, .row = panes.File.rowOf(p.settings.tab, pane, at.line - 1, 0) }, -@as(i64, if (landing == .third) (pane.rows + 2) / 3 else pane.rows / 2)).to);
}
pane.body.cur_row = std.math.cast(i32, at.line - 1) orelse return;
pane.body.cur_col = columnOn(pane, pane.body.cur_row, at.col);
@@ -1609,6 +1611,9 @@ fn lookOpenFailed(p: *Pardes, id: usize, path: []const u8, err: anyerror) void {
pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
const v = p.view();
const pane = p.panes[id] orelse return;
+ // A question's answer word on the pane it waits on, Looked at (a click,
+ // B3 on `Reload` in its tag): answered, as Exec answers it.
+ if (pardes.Messages.answerWord(p, id, operand_raw)) return;
// `~/x`, `~/x:12`, `~/x:/re/`: home, before anything reads the text.
// Anything else as written: a look of ` return x` is of those blanks
// too (the path, address and command readings below trim for
@@ -2960,3 +2965,28 @@ test "Plumb: a commit hash looked at in a git work tree is git show's, paged; ou
};
try std.testing.expect(paged);
}
+
+test "a Look at a question's answer word in its pane answers it, as an Exec does: B3 on Reload reads the file again" {
+ const p = try Pardes.init(std.testing.allocator, .{ .cols = 120, .rows = 20 });
+ defer p.deinit();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.zig", .data = "one\n" });
+ var dir: [4096]u8 = undefined;
+ const path = try std.fmt.allocPrint(std.testing.allocator, "{s}/c.zig", .{dir[0..try tmp.dir.realPath(std.testing.io, &dir)]});
+ defer std.testing.allocator.free(path);
+ const pane = try p.setTestFile("one\n");
+ const id = p.view().active;
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try p.gpa.dupe(u8, path);
+ pane.file.?.saved_hash = panes.File.fileHash(&pane.file.?);
+ for ([_]u21{ 'G', 'o', 't', 'w', 'o', Key.escape }) |cp| p.update(.{ .key = .{ .cp = cp } });
+ const disk = "zero\none\n";
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.zig", .data = disk });
+ p.update(.{ .file_changed = .{ .pane = .at(id), .bytes = disk } });
+ try std.testing.expect(p.messages.waiting(pane) != null);
+ lookAt(p, id, "Reload");
+ while (p.nextEffect()) |_| {}
+ try std.testing.expect(p.messages.waiting(pane) == null);
+ try std.testing.expectEqualStrings(disk, p.panes[id].?.file.?.content);
+}
diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig
index 6e6f87e5..0f4f39dc 100644
--- a/core/lsp/Ask.zig
+++ b/core/lsp/Ask.zig
@@ -38,9 +38,10 @@ wait: ?struct {
arg: Effect.Buf(128),
row: i32 = 0,
col: i32 = 0,
- /// A hover asked from the keyboard where jumps walk (Pick.asked, when
- /// asked: a 9P script's answer comes after its write): drawn as ghost
- /// lines, no +Hover pane.
+ /// A hover or code actions asked from the keyboard where jumps walk
+ /// (Pick.asked, when asked: a 9P script's answer comes after its write):
+ /// a hover drawn as ghost lines, no +Hover pane; the actions a picker
+ /// in the pane's tag, no +Lsp.
ghost: bool = false,
} = null,
/// A hover asked from the keyboard (where the walk is on), drawn as ghost
@@ -125,7 +126,7 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
.arg = .from(arg),
.row = pane.body.cur_row,
.col = pane.body.cur_col,
- .ghost = kind == .hover and pardes.Pick.asked(p),
+ .ghost = (kind == .hover or kind == .code_action) and pardes.Pick.asked(p),
};
p.emit(.{ .lsp = .{
.id = p.lsp_ask.seq,
@@ -136,11 +137,12 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
} });
}
-const LspEdit = struct { start: usize, end: usize, text: []const u8 };
+pub const LspEdit = struct { start: usize, end: usize, text: []const u8 };
-fn parseLspEdits(p: *Pardes, bytes: []const u8, fallback: ?[]const u8) ?[]LspEdit {
+/// The client's edit records (`@put`, or `@edit` with `fallback`'s text),
+/// in `a`; null for anything else or a malformed one.
+pub fn parseLspEdits(a: std.mem.Allocator, bytes: []const u8, fallback: ?[]const u8) ?[]LspEdit {
if (bytes.len == 0 or bytes[bytes.len - 1] != '\n') return null;
- const a = p.scratch.allocator();
const edits = a.alloc(LspEdit, std.mem.count(u8, bytes, "\n")) catch return null;
var lines = std.mem.splitScalar(u8, bytes, '\n');
var n: usize = 0;
@@ -205,6 +207,14 @@ fn mapLspEditOffset(edits: []const LspEdit, old: usize) usize {
return new_at + (old - old_at);
}
+/// A code action's edit records (Pick.zig's actions) made in pane `pane`,
+/// whose text they are of at `revision`: one undo step; false when they
+/// are not (malformed, of another revision, changing nothing).
+pub fn applyAction(p: *Pardes, pane: *Pane, revision: u32, records: []const u8) bool {
+ const edits = parseLspEdits(p.scratch.allocator(), records, null) orelse return false;
+ return applyLspEdits(p, pane, revision, edits);
+}
+
/// The server's edits, of the file's text (its offsets; the `Changes`
/// layer's lines are none of it), made as the file's new text (File.load).
fn applyLspEdits(p: *Pardes, pane: *Pane, revision: u32, edits: []const LspEdit) bool {
@@ -357,7 +367,7 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
}
if (w.kind == .rename or w.kind == .format) {
const fallback: ?[]const u8 = if (w.kind == .rename) w.arg.slice() else null;
- if (parseLspEdits(p, rows, fallback)) |edits| {
+ if (parseLspEdits(p.scratch.allocator(), rows, fallback)) |edits| {
if (applyLspEdits(p, pane, w.revision, edits)) {
var buf: pardes.Kind.Buf(64) = .{};
const verb: []const u8 = if (w.kind == .rename) "renamed" else "formatted";
@@ -397,8 +407,25 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
p.lsp_ask.hover = .{ .serial = pane.serial, .row = w.row, .revision = w.revision, .text = .from(rows[0..cut]) };
return;
}
+ // Code actions asked from the keyboard: a picker of them in the pane's
+ // own tag, each previewed as its edit and applied by Enter or its digit.
+ if (w.kind == .code_action and w.ghost) {
+ pardes.Pick.open(p, asked, .actions, "", "", rows);
+ if (pardes.Pick.live(p)) |pk| pk.revision = w.revision;
+ return;
+ }
+ // Anyone else's: their titles alone, in a +Lsp.
+ const listed_rows = if (w.kind == .code_action) titles: {
+ var kept: std.ArrayList(u8) = .empty;
+ var lines = std.mem.splitScalar(u8, rows, '\n');
+ while (lines.next()) |ln| if (ln.len > 0 and ln[0] != '@') {
+ kept.appendSlice(p.scratch.allocator(), ln) catch |err| return p.reportError(w.pane, lspWord(w.kind), err);
+ kept.append(p.scratch.allocator(), '\n') catch |err| return p.reportError(w.pane, lspWord(w.kind), err);
+ };
+ break :titles kept.items;
+ } else rows;
const from: panes.Output.Origin = .{ .query = w.kind };
- const nrows = std.mem.count(u8, rows, "\n");
+ const nrows = std.mem.count(u8, listed_rows, "\n");
if ((panes.Output.traits(from).jumps or w.kind == .diagnostics) and nrows == 1) {
const ln = std.mem.trimEnd(u8, rows, "\n");
const place = ln[0..panes.Output.location(ln).end];
@@ -452,7 +479,7 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
return;
};
const dir = if (pane.file) |f| panes.Dir.ofName(f.path) else pane.cwdSlice();
- const content = p.gpa.dupe(u8, rows) catch |err| return p.reportError(w.pane, lspWord(w.kind), err);
+ const content = p.gpa.dupe(u8, listed_rows) catch |err| return p.reportError(w.pane, lspWord(w.kind), err);
const serial_before = p.next_serial;
p.fs.refilled = null;
panes.Output.fillResults(p, asked, dir, from, w.arg.slice(), content, null) catch |err| {
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig
index 637999c2..2411b20f 100644
--- a/core/ninep/ctl.zig
+++ b/core/ninep/ctl.zig
@@ -890,6 +890,8 @@ 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;
var it = view.iterator();
var mods: pardes.Key = .{ .cp = 0 };
while (it.nextCodepointSlice()) |rune| {
@@ -944,6 +946,8 @@ 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;
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/normal.zig b/core/normal.zig
index 2579fab6..3aad765d 100644
--- a/core/normal.zig
+++ b/core/normal.zig
@@ -260,7 +260,9 @@ fn objectJump(e: Editor, t: *Text, text: []const u8, range: modal.Selection, obj
const tree = nodeTree(e, t, text) orelse return;
var last = range;
for (0..count) |_| {
- const s = syntax.objectNext(tree.path, tree.root, tree.text, object, forward, tree.in(modal.selectionCursor(text, last)), null) orelse break;
+ var found: [1]?syntax.Span = undefined;
+ syntax.objectNext(tree.path, tree.root, tree.text, &.{object}, forward, tree.in(modal.selectionCursor(text, last)), null, &found);
+ const s = found[0] orelse break;
const next: modal.Selection = .{ .anchor = tree.out(s.from, false), .head = tree.out(s.to, s.to > s.from) };
if (std.meta.eql(next, last)) break;
last = next;
diff --git a/core/panes.zig b/core/panes.zig
index e4ed3e9d..c984a73e 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -26,13 +26,17 @@ const effect_path_cap = pardes.effect_path_cap;
/// Files use row zero; terminal overlays may begin anywhere in scrollback.
pub const EditText = struct { text: []u8, row0: i32 };
+/// What a pane's `]` and `[` tree targets were found for (Pane.targets):
+/// its text's revision, the caret's byte, the lines shown, the way.
+pub const TargetsKey = struct { revision: u32, at: usize, lo: usize, hi: usize, forward: bool };
+
pub const Pane = struct {
/// What the replay digest leaves out (core/walk.zig): the view's geometry,
/// made again from the rest (File.geometry); the other views' share of
/// it (views.zig). (The 9P server's part of `fs` says so in its type.)
pub const replica = .{
.local = .{ "pv", "pv_known" },
- .derived = .{ "band_rows", "ghost_at", "ghost_rows", "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "top_skip", "notices", "pan" },
+ .derived = .{ "band_rows", "ghost_at", "ghost_rows", "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "top_skip", "notices", "pan", "targets" },
.len = .{ .{ "question", "question_len" }, .{ "shell_tail", "shell_tail_len" }, .{ "sel_snap", "nsel_snap" } },
// A picture's memory is its own allocator's (a dump loaded makes
// it there).
@@ -367,6 +371,9 @@ pub const Pane = struct {
/// `ghost_at` (its line's last), the rows below drawn that many lower.
/// The mouse reads it, so that a click lands on what is drawn under it.
ghost_at: u16 = 0,
+ /// `]`'s and `[`'s tree targets as the body drawn last found them
+ /// (body_layer.treeTargets), and what for.
+ targets: struct { key: ?TargetsKey = null, lines: [3]?usize = @splat(null) } = .{},
ghost_rows: u16 = 0,
/// Each other view's share of this pane, while it is not live
/// (views.zig): its cursor, scroll and place in that view's layout.
@@ -1254,7 +1261,9 @@ pub fn teardownPane(p: *Pardes, pane: *Pane) void {
pane.jump.deinit(p.gpa);
pane.places.deinit(p.gpa);
p.gpa.free(pane.recipe_sels);
- @import("jj.zig").forget(p, pane.serial);
+ // A pane that walked on (Trail.show) is the same pane on another file:
+ // what jj answers now is its own.
+ if (p.paneBySerial(pane.serial) == null) @import("jj.zig").forget(p, pane.serial);
if (pane.query) |q| {
q.deinit(p.gpa);
p.gpa.destroy(q);
diff --git a/core/root.zig b/core/root.zig
index d1a25d21..66e9e0e8 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -779,6 +779,7 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{
.{ "panes.zig views.zig", "notices", "made again from the step's state at the top of update and presented, and at sync (Messages.collectNotices); a frame's are its own" },
.{ "panes.zig", "ghost_at", "where a message's detail is drawn under the caret's line (Messages.detailUnder), made again from the step's state with the notices (Messages.collectNotices: at the top of update, presented, sync, place); a frame's are its own" },
.{ "panes.zig", "ghost_rows", "the detail's rows there, made again with ghost_at" },
+ .{ "panes.zig", "targets", "`]`'s and `[`'s tree targets as the body drawn last found them (body_layer.treeTargets), keyed by the text's revision, the caret, the lines shown and the way, so a frame asks again only when one moved; the draw's alone, no step reads it" },
.{ "panes.zig views.zig", "band_rows", "the band's rows under a tag (Band.takes), made again from the view's tag state at every sync before anything reads them (layout.floorRows reads the last sync's, as it reads tag_rows)" },
.{ "panes.zig views.zig", "pan", "written by steps only (sync, a view unparked) from the pane and its terminal" },
.{ "File.zig", "cap line_starts line_cap widest", "the text's line index, of its bytes, and the widest line it found (an upper bound: which walk answers, never what)" },
diff --git a/core/syntax.zig b/core/syntax.zig
index a388573b..5c05300e 100644
--- a/core/syntax.zig
+++ b/core/syntax.zig
@@ -566,34 +566,39 @@ pub fn objectAt(path: []const u8, tree_ptr: *anyopaque, text: []const u8, object
/// `]f`/`[f` and kin: the next object starting after byte `at`, or the
/// previous one ending before it (helix goto_treesitter_object), from the
/// first of `.movement`, `.around`, `.inside` the query names.
-pub fn objectNext(path: []const u8, tree_ptr: *anyopaque, text: []const u8, object: Object, forward: bool, at: usize, within: ?[2]usize) ?Span {
- const q = objectQuery(path) orelse return null;
- var buf: [32]u8 = undefined;
- const capture = for ([_][]const u8{ "movement", "around", "inside" }) |kind| {
- const want = std.fmt.bufPrint(&buf, "{s}.{s}", .{ objectName(object), kind }) catch return null;
- if (captureId(q, want)) |id| break id;
- } else return null;
+pub fn objectNext(path: []const u8, tree_ptr: *anyopaque, text: []const u8, objects: []const Object, forward: bool, at: usize, within: ?[2]usize, out: []?Span) void {
+ @memset(out, null);
+ const q = objectQuery(path) orelse return;
+ // Each object's capture; one pass of the query finds them all (`]`'s
+ // three painted targets, body_layer.treeTargets).
+ var captures: [8]?u32 = @splat(null);
+ for (objects, captures[0..objects.len]) |object, *capture| {
+ var buf: [32]u8 = undefined;
+ capture.* = for ([_][]const u8{ "movement", "around", "inside" }) |kind| {
+ const want = std.fmt.bufPrint(&buf, "{s}.{s}", .{ objectName(object), kind }) catch break null;
+ if (captureId(q, want)) |id| break id;
+ } else null;
+ }
const tree: *const ts.Tree = @ptrCast(@alignCast(tree_ptr));
const cursor = ts.QueryCursor.create();
defer cursor.destroy();
// Only the objects these bytes hold (a body's rows shown): its painted
// targets (body_layer.paintTargets).
- if (within) |w| cursor.setByteRange(@intCast(w[0]), @intCast(w[1])) catch return null;
+ if (within) |w| cursor.setByteRange(@intCast(w[0]), @intCast(w[1])) catch return;
cursor.exec(q, tree.rootNode());
- var best: ?Span = null;
- while (cursor.nextMatch()) |match| {
- const s = matchSpan(q, match, capture, text) orelse continue;
+ while (cursor.nextMatch()) |match| for (captures[0..objects.len], out) |capture, *best| {
+ const s = matchSpan(q, match, capture orelse continue, text) orelse continue;
if (forward) {
if (s.from <= at) continue;
- if (best == null or s.from < best.?.from or (s.from == best.?.from and s.to > best.?.to)) best = s;
+ if (best.* == null or s.from < best.*.?.from or (s.from == best.*.?.from and s.to > best.*.?.to)) best.* = s;
} else {
if (s.to >= at) continue;
- if (best == null or s.to > best.?.to or (s.to == best.?.to and s.from < best.?.from)) best = s;
+ if (best.* == null or s.to > best.*.?.to or (s.to == best.*.?.to and s.from < best.*.?.from)) best.* = s;
}
- }
- const s = best orelse return null;
- if (s.from >= text.len or s.to >= text.len) return null;
- return s;
+ };
+ for (out) |*best| if (best.*) |s| if (s.from >= text.len or s.to >= text.len) {
+ best.* = null;
+ };
}
/// Owned source analysis. Both slices use the allocator passed to analyzeSource.