summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Band.zig60
-rw-r--r--core/Messages.zig174
-rw-r--r--core/Pick.zig86
-rw-r--r--core/Prompt.zig85
-rw-r--r--core/TagState.zig279
-rw-r--r--core/Trail.zig10
-rw-r--r--core/bindings.zig2
-rw-r--r--core/colors.zig2
-rw-r--r--core/fuzz.zig10
-rw-r--r--core/panes.zig23
10 files changed, 671 insertions, 60 deletions
diff --git a/core/Band.zig b/core/Band.zig
index 7d874319..cd4ca75b 100644
--- a/core/Band.zig
+++ b/core/Band.zig
@@ -178,8 +178,10 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band {
at = i;
};
const node = bindings.nodeAt(root, path);
- band.add(try levelStep(arena, pane, level, at, if (node) |n| s.used[n.group] else 0));
- band.add(try docStep(p, arena, root, path, level[at]));
+ if (level.len > 0) {
+ band.add(try levelStep(arena, pane, level, at, if (node) |n| s.used[n.group] else 0));
+ band.add(try docStep(p, arena, root, path, level[at]));
+ }
try band.place(p, arena, pane, id);
return band;
},
@@ -212,8 +214,12 @@ pub fn of(p: *Pardes, arena: std.mem.Allocator, pane: *Pane, id: usize) !?Band {
for (level, 0..) |c, i| if (c.key == (if (s.hi != 0) s.hi else used)) {
at = i;
};
- band.add(try levelStep(arena, pane, level, at, used));
- band.add(try docStep(p, arena, cur.root, cur.path, level[at]));
+ // A level with no children (an addon's group, the addon gone while it
+ // was shown) gives no rows.
+ if (level.len > 0) {
+ band.add(try levelStep(arena, pane, level, at, used));
+ band.add(try docStep(p, arena, cur.root, cur.path, level[at]));
+ }
try band.place(p, arena, pane, id);
return band;
}
@@ -1062,3 +1068,49 @@ test "a band is drawn in the theme's roles (UX D4): spines in the rule ink, a ch
}
try std.testing.expect(dimmed > 0 and why);
}
+
+test "an empty level gives no rows: SPC unrolled on an addon's group, or describe-key on its word, the addon gone, draws and takes keys" {
+ const Key = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\ntwo\n");
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ // An addon's word `SPC X a`, under a group of its own (the registry as
+ // Addon.take leaves it); its kind is never run here.
+ p.kinds.words[0] = .{ .kind = 0 };
+ p.kinds.words[0].name.set("Probe");
+ p.kinds.words[0].leader.set("Xa");
+ p.kinds.nwords = 1;
+ var children: [bindings.max_children]bindings.Child = undefined;
+ for ([_]u21{ ' ', 'X', Key.down }) |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expect(p.view().prefix == .leader and p.view().tag_state.unrolled);
+ try std.testing.expectEqualStrings("X", p.view().leader_keys[0..p.view().leader_n]);
+ try std.testing.expectEqual(@as(usize, 1), bindings.level(p, .leader, "X", &children).len);
+ _ = try p.render(a);
+ // The addon gone (Addon.drop) while its group is unrolled: the level
+ // has no children, the band no rows, and its keys pass.
+ p.kinds.nwords = 0;
+ try std.testing.expectEqual(@as(usize, 0), bindings.level(p, .leader, "X", &children).len);
+ _ = try p.render(a);
+ try std.testing.expectEqual(@as(usize, 0), (try of(p, a, p.panes[p.view().active].?, p.view().active)).?.nsteps);
+ for ([_]u21{ Key.down, Key.up, Key.enter, Key.backspace }) |c| {
+ p.update(.{ .key = .{ .cp = c } });
+ _ = try p.render(a);
+ }
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // describe-key found on the word, then the addon gone: its level, the
+ // word's group's, has no children.
+ p.kinds.nwords = 1;
+ for (" hk Xa") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expect(p.view().tag_state.kind == .describe and p.view().tag_state.found);
+ _ = try p.render(a);
+ p.kinds.nwords = 0;
+ _ = try p.render(a);
+ try std.testing.expectEqual(@as(usize, 0), (try of(p, a, p.panes[p.view().active].?, p.view().active)).?.nsteps);
+ for ([_]u21{ Key.down, Key.backspace, Key.enter }) |c| {
+ p.update(.{ .key = .{ .cp = c } });
+ _ = try p.render(a);
+ }
+}
diff --git a/core/Messages.zig b/core/Messages.zig
index 72d5193d..6233f7e5 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -297,8 +297,16 @@ pub fn say(p: *Pardes, kind: Kind, id: usize, text: []const u8) *Said {
/// A pane as a message names its cause: a file's path (a kind's too), else
/// `@pN` and the command it runs.
fn causeWord(pane: *const Pane, out: *Buf(96)) void {
- if (pane.file) |f| return out.set(f.path);
- if (pane.addon) |k| if (k.path.len > 0) return out.set(k.path);
+ const path = if (pane.file) |f| f.path else if (pane.addon) |k| k.path else "";
+ if (path.len > 0) {
+ if (path.len <= out.bytes.len) return out.set(path);
+ // Longer than the room: its end, `…` first, so its name is whole
+ // (UX D2: a path is cut from the left).
+ var from = path.len - (out.bytes.len - "\u{2026}".len);
+ while (from < path.len and path[from] & 0xC0 == 0x80) from += 1;
+ _ = out.print("\u{2026}{s}", .{path[from..]});
+ return;
+ }
const line = pane.command orelse {
_ = out.print(config.pane_addr ++ "{d}", .{pane.serial});
return;
@@ -306,7 +314,8 @@ fn causeWord(pane: *const Pane, out: *Buf(96)) void {
const first = line[0 .. std.mem.indexOfAny(u8, line, "\r\n") orelse line.len];
var cut = @min(first.len, 64);
while (cut < first.len and cut > 0 and first[cut] & 0xC0 == 0x80) cut -= 1;
- _ = out.print(config.pane_addr ++ "{d} {s}", .{ pane.serial, first[0..cut] });
+ // A command cut shows it (UX F2: every cut ends in `…`).
+ _ = out.print(config.pane_addr ++ "{d} {s}{s}", .{ pane.serial, first[0..cut], if (cut < first.len) "\u{2026}" else "" });
}
/// Make a message live, and return it (for its places and its detail):
@@ -725,13 +734,23 @@ pub fn noticeRow(p: *Pardes, width: usize, out: *[notice_row_cap]u8) Row {
var doc_buf: [notice_row_cap]u8 = undefined;
const doc = if (said == null) pardes.Band.docLeft(p, &doc_buf) else null;
const lead = if (said == null and doc == null) m.headline() else null;
+ // A message's cause, in bytes of `out`: the first item to give way.
+ var cause_at: [2]usize = .{ 0, 0 };
if (said != null) {} else if (doc) |line| {
w.writeAll(line) catch {};
} else if (lead) |s| {
w.print("{s} ", .{s.kind.glyph()}) catch {};
- // Its cause first, unless its words name it already.
+ // Its cause first, unless its words name it already (a cut one by
+ // what it kept).
const words = s.words();
- if (s.src.len > 0 and std.mem.indexOf(u8, words, s.src.slice()) == null) w.print("{s} ", .{s.src.slice()}) catch {};
+ const cause = s.src.slice();
+ const named = if (std.mem.startsWith(u8, cause, "\u{2026}")) cause["\u{2026}".len..] else cause;
+ cause_at = .{ w.end, w.end };
+ if (cause.len > 0 and std.mem.indexOf(u8, words, named) == null) {
+ w.writeAll(cause) catch {};
+ cause_at[1] = w.end;
+ w.writeByte(' ') catch {};
+ }
w.writeAll(words) catch {};
if (s.n > 1) w.print(" \u{d7}{d}", .{s.n}) catch {};
for (s.places[0..s.places_len], 0..) |*place, i| w.print("{s} {s}:{d}:{d}", .{ if (i > 0) " \u{b7}" else "", place.path.slice(), place.line, place.col }) catch {};
@@ -774,14 +793,38 @@ pub fn noticeRow(p: *Pardes, width: usize, out: *[notice_row_cap]u8) Row {
w.writeAll(name) catch {};
cut = w.end;
} else {
- cut = panes.File.rawAtDisplay(tab, out[0..left_end], room -| 1);
- while (cut > 0 and panes.File.displayWidth(tab, out[0..cut]) > room -| 1) {
- cut -= 1;
- while (cut > 0 and out[cut] & 0xC0 == 0x80) cut -= 1;
+ // A message (UX D2, F2): its cause gives way first (a path down
+ // to its name, `…Query.zig`; a command down to its pane,
+ // `@p2…`), then each path its words and places name, down to
+ // its name; its words are cut last, from the right below.
+ if (lead != null) {
+ var over = panes.File.displayWidth(tab, out[0..left_end]) - room;
+ var kept: [notice_row_cap]u8 = undefined;
+ var k: std.Io.Writer = .fixed(&kept);
+ k.writeAll(out[0..cause_at[0]]) catch {};
+ const cause = out[cause_at[0]..cause_at[1]];
+ over -|= giveWay(tab, &k, cause, over, !std.mem.startsWith(u8, cause, config.pane_addr) and std.mem.indexOfScalar(u8, cause, '/') != null);
+ var items = std.mem.splitScalar(u8, out[cause_at[1]..left_end], ' ');
+ var first = true;
+ while (items.next()) |item| {
+ if (!first) k.writeByte(' ') catch {};
+ first = false;
+ if (std.mem.indexOfScalar(u8, item, '/') != null) over -|= giveWay(tab, &k, item, over, true) else k.writeAll(item) catch {};
+ }
+ cut = k.end;
+ @memcpy(out[0..cut], k.buffered());
+ }
+ if (panes.File.displayWidth(tab, out[0..cut]) > room) {
+ const end = cut;
+ cut = panes.File.rawAtDisplay(tab, out[0..end], room -| 1);
+ while (cut > 0 and panes.File.displayWidth(tab, out[0..cut]) > room -| 1) {
+ cut -= 1;
+ while (cut > 0 and out[cut] & 0xC0 == 0x80) cut -= 1;
+ }
+ w.end = cut;
+ w.writeAll(if (room > 0) "…" else "") catch {};
+ cut = w.end;
}
- w.end = cut;
- w.writeAll(if (room > 0) "…" else "") catch {};
- cut = w.end;
}
}
w.end = cut;
@@ -792,6 +835,38 @@ pub fn noticeRow(p: *Pardes, width: usize, out: *[notice_row_cap]u8) Row {
return .{ .left = cut, .right = right_at, .text = w.buffered(), .lead = lead, .quiet_left = said != null, .word = said orelse .{ 0, 0 } };
}
+/// `item` written to `w` with `over` cells of it given back where it has
+/// them, `…` in their place (UX D2): a path from its left, never into its
+/// name (what follows its last `/`); anything else from its right, never
+/// into its first word. The cells it gave.
+fn giveWay(tab: u16, w: *std.Io.Writer, item: []const u8, over: usize, path: bool) usize {
+ var edge: usize = if (path) 0 else item.len;
+ var cells: usize = 0;
+ if (path) {
+ const name = if (std.mem.lastIndexOfScalar(u8, item, '/')) |slash| slash + 1 else 0;
+ while (edge < name and cells < over + 1) {
+ const next = @min(item.len, edge + (std.unicode.utf8ByteSequenceLength(item[edge]) catch 1));
+ cells += panes.File.displayWidth(tab, item[edge..next]);
+ edge = next;
+ }
+ } else {
+ const first = std.mem.indexOfScalar(u8, item, ' ') orelse item.len;
+ while (edge > first and cells < over + 1) {
+ var prev = edge - 1;
+ while (prev > first and item[prev] & 0xC0 == 0x80) prev -= 1;
+ cells += panes.File.displayWidth(tab, item[prev..edge]);
+ edge = prev;
+ }
+ }
+ // The `…` takes a cell of what was given.
+ if (cells < 2) {
+ w.writeAll(item) catch {};
+ return 0;
+ }
+ if (path) w.print("\u{2026}{s}", .{item[edge..]}) catch {} else w.print("{s}\u{2026}", .{item[0..edge]}) catch {};
+ return cells - 1;
+}
+
/// What notice band `i` says. The grid pass and the band layers both
/// read it here, so a terminal and a pixel shell show the same line.
pub fn noticeText(pane: *const Pane, i: usize) []const u8 {
@@ -1680,3 +1755,78 @@ test "the notice row's left is cut with `…` two blanks before its right block
row = noticeRow(p, 200, &buf);
try std.testing.expect(std.mem.indexOf(u8, row.text, "…") == null);
}
+
+test "a cause longer than its word's room keeps the path's end, `…` first, so the file's name is whole (S2 08b at 16 px: `…/core/Query.zi`, its last letter lost)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 24 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ const id = p.view().active;
+ const long = "/tmp/claude-1000/wS2g16/proj/a/rather/long/way/down/to/the/sources/of/this/project/core/Query.zig";
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try p.gpa.dupe(u8, long);
+ p.messages.live_len = 0;
+ const s = say(p, .notice, id, "the build finished");
+ try std.testing.expect(std.mem.startsWith(u8, s.src.slice(), "\u{2026}"));
+ try std.testing.expect(std.mem.endsWith(u8, long, s.src.slice()["\u{2026}".len..]));
+ // The notice row names the file whole, its words after it.
+ var buf: [notice_row_cap]u8 = undefined;
+ var row = noticeRow(p, 190, &buf);
+ try std.testing.expect(std.mem.endsWith(u8, row.text[0..row.left], "/core/Query.zig the build finished"));
+ // Words that name the path already leave the cause out, cut or not
+ // (S2 08a: `saved PATH`).
+ p.messages.live_len = 0;
+ _ = say(p, .notice, id, "saved " ++ long);
+ row = noticeRow(p, 190, &buf);
+ try std.testing.expectEqualStrings("\u{b7} saved " ++ long, row.text[0..row.left]);
+}
+
+test "a message too wide for the notice row gives way by its items, each cut showing `…`: its cause first (a path down to its name, a command down to its pane), then the paths it names down to theirs, then its words from the right; its right part whole, two blanks before it (UX D2, F2; S2 08a, 08b, 09a at 26 px)" {
+ 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 id = p.view().active;
+ const long = "/tmp/claude-1000/wS2g26/proj/a/rather/long/way/down/to/the/sources/of/this/project/core/Query.zig";
+ p.gpa.free(pane.file.?.path);
+ pane.file.?.path = try p.gpa.dupe(u8, long);
+ p.messages.live_len = 0;
+ p.messages.len = 0;
+ const tab = p.settings.tab;
+ var buf: [notice_row_cap]u8 = undefined;
+ // 08b: the cause a long path, the words longer than the row.
+ _ = say(p, .notice, id, "the build in the other column finished with three warnings and one error, the error in a file this pane does not show");
+ var row = noticeRow(p, 97, &buf);
+ var left = row.text[0..row.left];
+ try std.testing.expect(std.mem.startsWith(u8, left, "\u{b7} \u{2026}Query.zig the build in the other column finished"));
+ try std.testing.expect(std.mem.endsWith(u8, left, "\u{2026}"));
+ try std.testing.expect(row.right - row.left >= 2);
+ try std.testing.expectEqual(@as(usize, 97), panes.File.displayWidth(tab, row.text));
+ // 08a: the words name a path: it is cut from its left, its name whole.
+ p.messages.live_len = 0;
+ _ = say(p, .notice, id, "saved " ++ long);
+ row = noticeRow(p, 97, &buf);
+ left = row.text[0..row.left];
+ try std.testing.expect(std.mem.startsWith(u8, left, "\u{b7} saved \u{2026}"));
+ try std.testing.expect(std.mem.endsWith(u8, left, "/core/Query.zig"));
+ try std.testing.expect(row.right - row.left >= 2);
+ // 09a: a command pane's cause gives way from its right, down to its
+ // `@pN`, before the place it names: the place stays whole.
+ p.messages.live_len = 0;
+ const err = keep(p, .@"error", 0, "@p2 sh -c 'printf \"Store.zig:20:5: error: expected 2 argument(s), found 3", "exit 1");
+ err.places[0] = .{ .line = 20, .col = 5 };
+ err.places[0].path.set("/tmp/claude-1000/wS2g26/proj/core/Store.zig");
+ err.places_len = 1;
+ row = noticeRow(p, 97, &buf);
+ left = row.text[0..row.left];
+ try std.testing.expect(std.mem.startsWith(u8, left, "\u{2717} @p2 sh -c"));
+ try std.testing.expect(std.mem.endsWith(u8, left, "\u{2026} exit 1 /tmp/claude-1000/wS2g26/proj/core/Store.zig:20:5"));
+ try std.testing.expect(std.mem.endsWith(u8, row.text, "SPC e walk"));
+ try std.testing.expect(row.right - row.left >= 2);
+ // A command's echo cut for its word ends in `…` too (S2 09a: `fo exit 1`).
+ pane.command = try p.gpa.dupe(u8, "sh -c 'printf \"Store.zig:20:5: error: expected 2 argument(s), found 3\\n\"; exit 1'");
+ const file = pane.file;
+ pane.file = null;
+ defer pane.file = file;
+ var word: Buf(96) = .{};
+ causeWord(pane, &word);
+ try std.testing.expect(std.mem.endsWith(u8, word.slice(), "\u{2026}"));
+}
diff --git a/core/Pick.zig b/core/Pick.zig
index 10c80dfc..b76020ca 100644
--- a/core/Pick.zig
+++ b/core/Pick.zig
@@ -57,8 +57,9 @@ const Key = pardes.Key;
/// (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`).
+/// Each source's word in the tag and its key cells (`␣ f Find`); a
+/// source whose Backspace leaves it (`back`) goes back to the SPC level of
+/// those keys: a group's.
const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8 }).init(.{
.find = .{ .word = "Find", .keys = "f" },
.grep = .{ .word = "Grep", .keys = "f" },
@@ -68,7 +69,7 @@ const words = std.EnumArray(Source, struct { word: []const u8, keys: []const u8
.all = .{ .word = "All", .keys = "" },
.jumplist = .{ .word = "Jumplist", .keys = "j" },
.list = .{ .word = "List", .keys = "l" },
- .messages = .{ .word = "Messages", .keys = "hm" },
+ .messages = .{ .word = "Messages", .keys = "h" },
.themes = .{ .word = "Themes", .keys = "t" },
.actions = .{ .word = "Actions", .keys = "la" },
});
@@ -120,8 +121,9 @@ aside: ?File.State = null,
aside_row: i32 = 0,
aside_col: i32 = 0,
aside_top: usize = 0,
-/// The row the preview shows (`no_row`: none yet); asked again on the
-/// frame after the cursor moves, never on the key that moved it.
+/// What the row the preview shows is (`idOf`; `no_row`: none yet): asked
+/// again on the frame after the cursor moves to another, never on the key
+/// that moved it, and on the frame a row first comes under it.
shown: u32 = no_row,
/// The preview on (M-p).
previews: bool = true,
@@ -437,7 +439,8 @@ pub fn produceAll(p: *Pardes, tick: bool) void {
/// The frames a live picker still owes: scoring, a preview (nextWake's).
pub fn busy(p: *const Pardes) bool {
for (p.picks) |slot| if (slot) |pk| if (pk.unrolled) {
- if (pk.names.busy() or (pk.previews and pk.shown != p.view().tag_state.rows.at)) return true;
+ const at = p.view().tag_state.rows.at;
+ if (pk.names.busy() or (pk.previews and at < count(p, pk) and pk.shown != idOf(pk, at))) return true;
};
return false;
}
@@ -764,7 +767,7 @@ pub fn landingLine(p: *Pardes, arena: std.mem.Allocator, pane: *const Pane) ?usi
// 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;
+ if (s.rows.at >= count(p, pk) or pk.shown != idOf(pk, s.rows.at)) return null;
const row = rowAt(p, pk, arena, s.rows.at) catch return null;
const place = switch (row.target) {
.place => |t| t,
@@ -802,9 +805,11 @@ pub fn sentence(p: *const Pardes, w: *std.Io.Writer) ?[2]usize {
/// open pane shows is taken from it; any other is read.
fn preview(p: *Pardes, pk: *Pick) void {
const s = &p.view().tag_state;
- if (pk.shown == s.rows.at or !pk.previews) return;
- pk.shown = s.rows.at;
- if (count(p, pk) == 0) return;
+ // No row yet: none shown, so the first to come is (a Find's listing
+ // and a Grep's lines come frames after the field asked).
+ if (!pk.previews or s.rows.at >= count(p, pk)) return;
+ if (pk.shown == idOf(pk, s.rows.at)) return;
+ pk.shown = idOf(pk, s.rows.at);
var frame = std.heap.ArenaAllocator.init(p.gpa);
defer frame.deinit();
const row = rowAt(p, pk, frame.allocator(), s.rows.at) catch return;
@@ -2554,3 +2559,64 @@ test "code actions: a row that cannot be applied (a command's, an edit reaching
};
try std.testing.expectEqual(@as(?u16, @intCast((pane.rows + 2) / 3)), row_at);
}
+
+test "a picker previews the row under its cursor from the frame its rows come, when a frame with none came first: a Find's listing, a Grep's lines after their pause (UX D7)" {
+ 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();
+ const a_path = try testFile(p, &tmp, "alpha.zig", "const alpha = 1;\npub fn a() void {}\n");
+ defer p.gpa.free(a_path);
+ _ = try p.setTestFile("held\n");
+ const asker = p.view().active;
+ Trail.keep(p.panes[asker].?);
+ p.gpa.free(p.panes[asker].?.file.?.path);
+ p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ std.Io.Dir.path.dirname(a_path).?, "held.txt" });
+ p.stream.engine = .walk;
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ // Find, its field empty: a frame before the listing comes (a host's
+ // worker sends it by an input of its own, after the step that asked).
+ open(p, asker, .find, "", "", "");
+ const reader = p.paneBySerial(live(p).?.landing).?;
+ produceAll(p, true);
+ try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?));
+ // No rows: no frame owed for a preview.
+ try std.testing.expect(!busy(p));
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 1), count(p, live(p).?));
+ try std.testing.expectEqualStrings(a_path, p.panes[reader].?.file.?.path);
+ try std.testing.expectEqual(@as(?usize, 0), landingLine(p, frame.allocator(), p.panes[reader].?));
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ // Grep: its lines come once the typing pauses, frames with none before.
+ open(p, asker, .grep, "", "", "");
+ const greader = p.paneBySerial(live(p).?.landing).?;
+ for ("pub") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ p.update(.tick);
+ try std.testing.expectEqual(@as(usize, 0), count(p, live(p).?));
+ try std.testing.expect(!busy(p));
+ p.clock.now_ns = p.stream.due_ns.?;
+ settle(p);
+ try std.testing.expectEqual(@as(usize, 1), count(p, live(p).?));
+ try std.testing.expectEqualStrings(a_path, p.panes[greader].?.file.?.path);
+ try std.testing.expectEqual(@as(?usize, 1), landingLine(p, frame.allocator(), p.panes[greader].?));
+}
+
+test "Backspace on a Messages picker's empty field goes back to the level it was run from, SPC h, unrolled and drawn: its keys are its level's, as every other picker's are" {
+ const Key_ = pardes.Key;
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ _ = try p.setTestFile("one\ntwo\n");
+ for (" hm") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expectEqual(Source.messages, live(p).?.source);
+ p.sync();
+ _ = try p.render(frame.allocator());
+ p.update(.{ .key = .{ .cp = Key_.backspace } });
+ try std.testing.expect(p.view().prefix == .leader and p.view().tag_state.unrolled);
+ try std.testing.expectEqualStrings("h", p.view().leader_keys[0..p.view().leader_n]);
+ p.sync();
+ _ = try p.render(frame.allocator());
+}
diff --git a/core/Prompt.zig b/core/Prompt.zig
index 0a288a79..706ff54d 100644
--- a/core/Prompt.zig
+++ b/core/Prompt.zig
@@ -48,8 +48,9 @@ const hit = pardes.hit;
pub const Op = enum(u8) { search, search_back, select, split, keep, remove, pipe, pipe_to, insert, append, keep_pipe, command };
op: Op = .select,
-/// Up and Down's place in its history: 0 the field as typed, n the n-th
-/// newest line.
+/// The line of its history the keys are on: 0 the field as typed, n the
+/// n-th newest line, in the field when Up or Down brought it, under the
+/// cursor of the history unrolled (`historyAt`).
recall: u8 = 0,
/// Ctrl-r: its history unrolled under the tag, filtered by the field.
history: bool = false,
@@ -257,6 +258,34 @@ pub fn key(p: *Pardes, k: Key) void {
const plain = !k.ctrl and !k.alt;
const ctrl = k.ctrl and !k.alt;
if (hit(k, config.escape)) return cancel(p, pane);
+ // Its history unrolled is a list like any other (UX D5): Down and C-n,
+ // Up and C-p move its cursor to the next line it shows, older or newer,
+ // the field kept as typed; Enter takes the line under it.
+ if (s.prompt.history) {
+ const down = (plain and k.cp == Key.down) or (ctrl and k.cp == 'n');
+ const up = (plain and k.cp == Key.up) or (ctrl and k.cp == 'p');
+ const r = ring(p, s.prompt.op);
+ const at = historyAt(p);
+ if (down or up) {
+ var newer: u8 = 0;
+ var older: u8 = 0;
+ var rows: usize = 0;
+ var back: u8 = 1;
+ while (back <= r.n and rows < Band.Cursor.shown) : (back += 1) {
+ if (std.mem.indexOf(u8, r.get(back).?, s.field.text()) == null) continue;
+ rows += 1;
+ if (back < at) newer = back;
+ if (back > at and older == 0) older = back;
+ }
+ const to = if (down) older else newer;
+ if (to != 0) s.prompt.recall = to;
+ return;
+ }
+ if (plain and k.cp == Key.enter and at != 0) {
+ s.field.set(r.get(at).?);
+ live(p, pane);
+ }
+ }
if (s.prompt.op == .command and Command.key(p, id, pane, k)) return;
if (plain and k.cp == Key.enter) return commit(p, id, pane);
if (k.alt and !k.ctrl and k.cp == Key.enter) return asList(p, id, pane);
@@ -1236,7 +1265,7 @@ fn historyRows(p: *Pardes) u16 {
}
/// The prompt's steps in its band: its history, newest first, the lines
-/// holding the field, the one Up recalled on.
+/// holding the field, its cursor on one.
pub fn steps(p: *Pardes, arena: std.mem.Allocator, out: *[Band.max_steps]Band.Step) ![]Band.Step {
const s = &p.view().tag_state;
var made: usize = 0;
@@ -1265,22 +1294,37 @@ pub fn steps(p: *Pardes, arena: std.mem.Allocator, out: *[Band.max_steps]Band.St
return out[0 .. made + try historyStep(p, arena, &out[made])];
}
+/// The line of its history the cursor of the history unrolled is on: the
+/// one the keys moved to (`recall`), else the newest holding the field;
+/// 0 with none.
+fn historyAt(p: *Pardes) u8 {
+ const s = &p.view().tag_state;
+ if (s.prompt.recall != 0) return s.prompt.recall;
+ const r = ring(p, s.prompt.op);
+ var back: u8 = 1;
+ while (back <= r.n) : (back += 1) {
+ if (std.mem.indexOf(u8, r.get(back).?, s.field.text()) != null) return back;
+ }
+ return 0;
+}
+
/// A history step's row's index: its line's place in the ring with this
/// bit, which a click tells from the other steps' rows (Command.point).
pub const history_row: u16 = 0x8000;
/// The history step (Ctrl-r): its lines newest first, those holding the
-/// field, the one Up recalled on.
+/// field, its cursor on one.
fn historyStep(p: *Pardes, arena: std.mem.Allocator, out: *Band.Step) !usize {
const s = &p.view().tag_state;
const r = ring(p, s.prompt.op);
var rows: std.ArrayList(Band.Row) = .empty;
const q = s.field.text();
+ const at = historyAt(p);
var back: u8 = 1;
while (back <= r.n and rows.items.len < Band.Cursor.shown) : (back += 1) {
const l = r.get(back).?;
if (std.mem.indexOf(u8, l, q) == null) continue;
- try rows.append(arena, .{ .text = l, .on = back == s.prompt.recall, .index = history_row | back });
+ try rows.append(arena, .{ .text = l, .on = back == at, .index = history_row | back });
}
if (rows.items.len == 0) try rows.append(arena, .{ .text = if (r.n == 0) "no history yet" else "no line holds it", .dim = true });
out.* = .{ .rows = rows.items };
@@ -1728,3 +1772,34 @@ test "a search's count keeps ` · N lines` after it in the dim ink, and drops it
typeKeys(p, "/dirty");
try std.testing.expect(has(try tagOf(p), "1/7 \u{21bb} \u{b7} 5 lines \u{23ce} land"));
}
+
+test "C-r's history has the band's cursor like any list (UX D5): `▶` on its newest line, Down and C-n, Up and C-p move it, Enter takes the line under it" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 });
+ defer p.deinit();
+ while (p.nextEffect()) |_| {}
+ _ = try p.setTestFile("self.a = 1;\npub fn b() void {}\nself.c = 2;\n");
+ typeKeys(p, "/self");
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ typeKeys(p, "/pub");
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ typeKeys(p, "/");
+ p.update(.{ .key = .{ .cp = 'r', .ctrl = true } });
+ var out: [Band.max_steps]Band.Step = undefined;
+ const a = p.scratch.allocator();
+ var rows = (try steps(p, a, &out))[0].rows;
+ try std.testing.expectEqual(@as(usize, 2), rows.len);
+ try std.testing.expectEqualStrings("pub", rows[0].text);
+ try std.testing.expect(rows[0].on and !rows[1].on);
+ for ([_]Key{ .{ .cp = 'n', .ctrl = true }, .{ .cp = Key.up }, .{ .cp = Key.down }, .{ .cp = 'p', .ctrl = true }, .{ .cp = 'n', .ctrl = true } }, [_]bool{ false, true, false, true, false }) |k, first| {
+ p.update(.{ .key = k });
+ rows = (try steps(p, a, &out))[0].rows;
+ try std.testing.expect(rows[0].on == first and rows[1].on == !first);
+ // The field as typed: the rows stay those it filters.
+ try std.testing.expectEqualStrings("", p.view().tag_state.field.text());
+ }
+ // Enter: the line under the cursor, `self`, searched for and kept.
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ try std.testing.expectEqual(TagState.Kind.rest, p.view().tag_state.kind);
+ try std.testing.expectEqualStrings("self", p.registers.value('/', 0).?);
+ try std.testing.expectEqualStrings("self", p.prompt_history.search.get(1).?);
+}
diff --git a/core/TagState.zig b/core/TagState.zig
index 761eec48..1e8b4dea 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -268,23 +268,71 @@ pub fn wake(p: *const Pardes) ?u64 {
return soonest;
}
-/// Each view's tag state as a dump gave it, held to what it indexes: Help's
-/// hits in the tree and the registry, its rows' cursor in them, the field's
-/// caret in its text, describe-key's found leaf or struck key in its keys.
-/// One that is not (a damaged dump: the fuzz's cut and flipped bytes) is
-/// at rest, its memory of leaves kept (dump.zig afterLoad).
+/// Each view's tag state as a dump gave it, held to what its state reads
+/// (dump.zig afterLoad); one that is not (a damaged dump: the fuzz's cut
+/// and flipped bytes) is at rest, its memory of leaves kept. Each state's
+/// own fields alone: what another state left in it (describe-key's `found`
+/// under Help, a picker's cursor past Help's rows) is as the session has
+/// it, and so is its digest. Every state: the field's caret in its text, a
+/// struck key a cell (keyName's table). Help: its hits leaves of the tree
+/// or SPC words of the registry, its cursor in them, its scope what `?` was
+/// struck under (SPC's keys to a group, as many as SPC's path holds: its
+/// Backspace unrolls them, keys.helpBack; else none). describe-key: its
+/// keys cells; found, a root's keys to a leaf, whose level Band.of
+/// replays; with no root, nothing typed or the one key struck. A picker:
+/// its cursor in its rows (Pick.rowAt; All's are found again at each
+/// read). And the view's SPC keys, every level's path (`current`): cells
+/// to a group, else the view is out of SPC too.
pub fn loaded(p: *Pardes) void {
for (&p.views) |*slot| if (slot.*) |*v| {
const s = &v.tag_state;
- var held = s.field.caret <= s.field.len and s.nhits <= max_hits and s.rows.at < @max(1, s.nhits) and !(s.found and s.scope_n == 0) and !(s.missed and s.scope_root == null and s.scope_n == 0);
- // `:`'s hits index its own rows (the themes, the settings: Command.zig,
- // which holds each where it reads it); the rest the tree's leaves.
- const command = s.kind == .prompt and s.prompt.op == .command;
- for (s.hits[0..@min(s.nhits, max_hits)]) |at| held = held and (command or at < bindings.flat.len + p.kinds.nwords);
+ const keys = s.scope[0..s.scope_n];
+ var held = s.field.caret <= s.field.len and s.nhits <= max_hits and (s.miss == 0 or cells(&.{s.miss}));
+ switch (s.kind) {
+ .help => {
+ for (s.hits[0..@min(s.nhits, max_hits)]) |at| held = held and (at < bindings.flat.len or at - bindings.flat.len < p.kinds.nwords and p.kinds.words[at - bindings.flat.len].leader.len > 0);
+ held = held and s.rows.at < @max(1, s.nhits) and
+ if (s.scope_root == .leader) keys.len <= v.leader_keys.len and cells(keys) and reaches(p, .leader, keys, false) else keys.len == 0;
+ },
+ .describe => held = held and cells(keys) and !(s.found and s.missed) and if (s.scope_root) |r|
+ r != .register and (!s.found or keys.len > 0 and reaches(p, r, keys, true))
+ else
+ !s.found and keys.len == @intFromBool(s.missed),
+ .pick => if (@import("Pick.zig").byId(p, s.pick)) |pk| {
+ held = held and (pk.source == .all or s.rows.at < @max(1, @import("Pick.zig").count(p, pk)));
+ },
+ .rest, .prompt, .rename => {},
+ }
+ const spc = v.leader_keys[0..v.leader_n];
+ if (v.prefix == .leader and !(cells(spc) and reaches(p, .leader, spc, false))) {
+ v.prefix = .none;
+ v.leader_n = 0;
+ held = false;
+ }
if (!held) s.* = .{ .used = s.used };
};
}
+/// Whether each of `keys` is a cell keyName names.
+fn cells(keys: []const u8) bool {
+ for (keys) |k| if (k < ' ' or k > '~') return false;
+ return true;
+}
+
+/// Whether `path` under `root` is a group (`leaf` false) or a leaf of the
+/// tree or of the registry's SPC words. Every builtin's, whichever view's
+/// frontend took it (bindings.level drops the live view's others): a load
+/// holds each view the same in every process.
+fn reaches(p: *const Pardes, root: Root, path: []const u8, leaf: bool) bool {
+ if (bindings.nodeAt(root, path)) |n| if (if (leaf) n.leaf != null else n.children.len > 0) return true;
+ if (root != .leader) return false;
+ for (p.kinds.words[0..p.kinds.nwords]) |*w| {
+ const keys = w.leader.slice();
+ if (if (leaf) std.mem.eql(u8, keys, path) else keys.len > path.len and std.mem.startsWith(u8, keys, path)) return true;
+ }
+ return false;
+}
+
/// Asking (SPEC §3.2, §10.2): a question waiting on the pane, its tag at
/// rest, in place of the tag's own text: what it asks, `▸`, each answer's
/// key and word, and how to give one (`Esc later` while SPC e has given it
@@ -734,13 +782,20 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
};
level = level[0..n];
}
+ // Its hints on its last row, by the right block's rule (UX D3): a
+ // level that wraps gives them its spare row, its last child going to
+ // it to leave them room; a level of one row or of all its rows keeps
+ // its rows, and they drop where they do not fit.
+ const hint = "↓ unroll · ? help";
+ const hinted = 2 + panes.File.displayWidth(tab, hint);
var rows: usize = 1;
for (level, 0..) |c, i| {
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) {
+ const last: usize = if (i + 1 == level.len and rows > 1) struck + hinted else 0;
+ if (b.col() + gap + w + more(level.len - i - 1, rows == most) + (if (rows == most) struck else last) > b.width and rows < most and b.col() > indent) {
try b.row(indent);
rows += 1;
gap = 0;
@@ -767,9 +822,8 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?Head {
if (b.col() + struck > b.width and rows < most) try b.row(indent) else try b.put(" ");
try b.styled(bindings.keyName(s.miss), .strike);
}
- // Its hints on its last row, by the right block's rule (UX D3).
const hints = b.text.items.len;
- try b.styled("↓ unroll · ? help", .dim);
+ try b.styled(hint, .dim);
try b.right(hints, hints);
return b.done();
}
@@ -1364,3 +1418,202 @@ test "a click that gives the keyboard to another pane ends a level as Esc does;
click(p, rt.x + config.GUTTER + 1, rt.y + pardes.BOX_H);
try std.testing.expect(p.view().tag_state.kind == .rest and hostOf(p) == null);
}
+
+test "a rolled level that wraps has its hints on its last row at every width that leaves it a row to spare: `]` and `g` as SPC (UX D3)" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ const a = frame.allocator();
+ for (" ]g") |root| for (40..161) |cols| {
+ p.update(.{ .resize = .{ .cols = @intCast(cols), .rows = 40 } });
+ p.update(.{ .key = .{ .cp = root } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ try std.testing.expect(hostOf(p) != null);
+ const tag = try testTag(p, a);
+ if (std.mem.count(u8, tag, "\n") == 1) try std.testing.expect(std.mem.endsWith(u8, tag, " ↓ unroll · ? help"));
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ try std.testing.expect(hostOf(p) == null);
+ };
+}
+
+test "a dump holding describe-key's state, or Help's, or a level's, damaged where a draw or a key indexes it, loads to rest and draws and takes keys" {
+ const Key = pardes.Key;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\ntwo\nthree\n");
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ const typed = struct {
+ fn keys(q: *Pardes, cps: []const u8) void {
+ for (cps) |c| q.update(.{ .key = .{ .cp = c } });
+ }
+ }.keys;
+ // Each case: the state a session made (describe-key's `g d` found,
+ // Help under `SPC t`, SPC's level rolled), then a field of it as a cut
+ // or flipped dump gives it.
+ const Case = struct { keys: []const u8, damage: *const fn (v: *View) void };
+ const cases = [_]Case{
+ // Found with no root (Band.takes, Band.of: `scope_root.?`).
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope_root = null;
+ }
+ }.f },
+ // Found on keys no leaf of the tree is: `SPC z z` (its level
+ // empty, Band.of's `level[at]`), `SPC t` (a group), `g z` (none).
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope_root = .leader;
+ v.tag_state.scope[0..2].* = "zz".*;
+ v.tag_state.scope_n = 2;
+ }
+ }.f },
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope_root = .leader;
+ v.tag_state.scope[0] = 't';
+ }
+ }.f },
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0] = 'z';
+ }
+ }.f },
+ // Found and missed at once; a register's root, which describe-key
+ // never takes.
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.missed = true;
+ }
+ }.f },
+ .{ .keys = " hkgd", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope_root = .register;
+ }
+ }.f },
+ // A struck key past keyName's table, with no root (`s.scope[0]`)
+ // and under one (bindings.chord).
+ .{ .keys = " hkq", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0] = 0x01;
+ }
+ }.f },
+ .{ .keys = " hkgq", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0] = 0x7f;
+ }
+ }.f },
+ // Help's scope: more keys than SPC's path holds (Backspace copies
+ // them into it: keys.helpBack), keys to no group (Backspace unrolls
+ // their level), a key past keyName's table (its key cells).
+ .{ .keys = " t?", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0..6].* = "tttttt".*;
+ v.tag_state.scope_n = 6;
+ }
+ }.f },
+ .{ .keys = " t?", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0..2].* = "zz".*;
+ v.tag_state.scope_n = 2;
+ }
+ }.f },
+ .{ .keys = " t?", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.scope[0] = 0x01;
+ }
+ }.f },
+ // SPC's level rolled and shown: a struck key past keyName's table
+ // (`s.miss`); unrolled on SPC keys to no group (Band.of's
+ // `level[at]`); SPC's keys past the table (their cells, the chord).
+ .{ .keys = " ", .damage = struct {
+ fn f(v: *View) void {
+ v.tag_state.due_ns = 1;
+ v.tag_state.miss = 0x05;
+ }
+ }.f },
+ .{ .keys = " ", .damage = struct {
+ fn f(v: *View) void {
+ v.leader_keys[0..2].* = "zz".*;
+ v.leader_n = 2;
+ v.tag_state.unrolled = true;
+ }
+ }.f },
+ .{ .keys = " ", .damage = struct {
+ fn f(v: *View) void {
+ v.leader_keys[0] = 0x01;
+ v.leader_n = 1;
+ v.tag_state.due_ns = 1;
+ }
+ }.f },
+ };
+ for (cases) |case| {
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ typed(p, case.keys);
+ try std.testing.expect(p.view().tag_state.kind != .rest or p.view().prefix == .leader);
+ case.damage(p.view());
+ const bytes = try pardes.dump.byteDump(p);
+ defer gpa.free(bytes);
+ // The session itself at rest again: the damage is the dump's.
+ p.view().tag_state = .{};
+ p.view().prefix = .none;
+ p.view().leader_n = 0;
+ var notes: std.ArrayList(u8) = .empty;
+ defer notes.deinit(gpa);
+ const q = try pardes.dump.load(gpa, .{ .cols = 120, .rows = 40 }, bytes, &notes);
+ defer q.deinit();
+ const s = &q.view().tag_state;
+ try std.testing.expect(s.kind == .rest and s.root == null and !s.unrolled and s.miss == 0);
+ // SPC's own keys kept only where they reach a group: none here.
+ try std.testing.expect(q.view().prefix != .leader or q.view().leader_n == 0);
+ // Drawn, then keys a state reads (Enter, Backspace, Down), drawn.
+ q.clock.now_ns = 10 * std.time.ns_per_s;
+ var frame = std.heap.ArenaAllocator.init(gpa);
+ defer frame.deinit();
+ q.sync();
+ _ = try q.render(frame.allocator());
+ for ([_]u21{ Key.backspace, Key.down, Key.enter, Key.backspace }) |cp| {
+ q.update(.{ .key = .{ .cp = cp } });
+ q.sync();
+ _ = try q.render(frame.allocator());
+ }
+ }
+}
+
+test "a tag state a session made loads as it was, its digest the session's: Help after describe-key found a leaf, a picker's cursor past Help's rows" {
+ const Key = pardes.Key;
+ const gpa = std.testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\ntwo\nthree\n");
+ const same = struct {
+ fn digest(q: *Pardes) !void {
+ const bytes = try pardes.dump.byteDump(q);
+ defer std.testing.allocator.free(bytes);
+ const r = try pardes.dump.load(std.testing.allocator, .{ .cols = 120, .rows = 40 }, bytes, null);
+ defer r.deinit();
+ try std.testing.expectEqual(q.view().tag_state.kind, r.view().tag_state.kind);
+ try std.testing.expectEqual(q.view().tag_state.rows.at, r.view().tag_state.rows.at);
+ try std.testing.expectEqual(pardes.tape.digestOf(q), pardes.tape.digestOf(r));
+ }
+ }.digest;
+ // A picker of three rows, its cursor on the third (Help never opened:
+ // no hits), then rolled up.
+ pardes.Pick.open(p, 0, .list, "Refs", "", "a\nb\nc\n");
+ for (0..2) |_| p.update(.{ .key = .{ .cp = Key.down } });
+ try std.testing.expect(p.view().tag_state.kind == .pick and p.view().tag_state.rows.at == 2);
+ try same(p);
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ try same(p);
+ // describe-key's `g d` found, then Help over every root: `found` is
+ // describe-key's alone, left as it was.
+ for (" hkgd") |c| p.update(.{ .key = .{ .cp = c } });
+ p.update(.{ .key = .{ .cp = Key.escape } });
+ for (" ?") |c| p.update(.{ .key = .{ .cp = c } });
+ try std.testing.expect(p.view().tag_state.kind == .help and p.view().tag_state.found);
+ try same(p);
+}
diff --git a/core/Trail.zig b/core/Trail.zig
index ddc350ca..73ea1ffb 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -55,13 +55,13 @@ pub const Step = union(enum) {
/// the first step.
owner: u32,
/// A list the pane came through (`Find pick 3/6 •2`, §5.6): its word
- /// and the pickers' index for it. Made by the pickers (not yet).
+ /// and the pickers' index for it. Made as a picker lands (Pick.listed).
list: Word,
- /// A search made in the pane (`/dirty/ 3/7`, §7.3). Made by the
- /// prompts (not yet).
+ /// A search made in the pane (`/dirty/ 3/7`, §7.3). Made by a search
+ /// prompt (Prompt.word).
search: Word,
- /// A chain of selection prompts as an Edit line (§7.5). Made by the
- /// prompts (not yet).
+ /// A chain of selection prompts as an Edit line (§7.5). Made by the sam
+ /// prompts (Prompt.link).
recipe: Word,
};
pub const Place = struct { path: Kind.Buf(max_text) = .{}, line: u32 = 0, col: u32 = 0 };
diff --git a/core/bindings.zig b/core/bindings.zig
index a8b81842..ab00c1da 100644
--- a/core/bindings.zig
+++ b/core/bindings.zig
@@ -582,7 +582,7 @@ test "\" shows the registers rolled, the ones holding something, each its value
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);
+ try p.registers.put(p.gpa, 'p', "/home/user/proj/core/Query.zig", 0, 1, true);
var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
defer frame.deinit();
const a = frame.allocator();
diff --git a/core/colors.zig b/core/colors.zig
index 4f58aed5..61af2e4a 100644
--- a/core/colors.zig
+++ b/core/colors.zig
@@ -733,7 +733,7 @@ fn toward(ink: [3]u8, ground: [3]u8, floor: f32) [3]u8 {
/// `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 {
+pub 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;
diff --git a/core/fuzz.zig b/core/fuzz.zig
index 091eca63..56ded66b 100644
--- a/core/fuzz.zig
+++ b/core/fuzz.zig
@@ -803,6 +803,14 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan
defer gpa.free(bytes);
const image = try pardes.dump.dumpBytes(p);
defer gpa.free(image);
+ // And one with describe-key's state (SPC h k, `g d` found: a root, its
+ // keys, the leaf whose level the band replays), Help's fields as Help
+ // left them.
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ for (" hkgd") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ try testing.expect(p.view().tag_state.kind == .describe and p.view().tag_state.found);
+ const described = try pardes.dump.byteDump(p);
+ defer gpa.free(described);
// Seconds a road, each core used (`use`). The image's past 1779 seeds
// reach xitdb's own reader (a slot's tag past its kinds: a `switch` on
// it), a dependency's.
@@ -816,7 +824,7 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan
// `live` (the core read in place, its own `live` undefined), a live
// message's `src` length 0xAAAA when the digest walked it.
try loadSeed(bytes, .join, 6356);
- for ([_][]const u8{ bytes, image }, [_]Road{ .join, .restore }, [_]u64{ 2048, 1024 }) |whole, road, n| {
+ for ([_][]const u8{ bytes, described, image }, [_]Road{ .join, .join, .restore }, [_]u64{ 2048, 2048, 1024 }) |whole, road, n| {
try loadSeed(whole, road, 0);
for (1..n + 1) |seed| try loadSeed(whole, road, seed);
}
diff --git a/core/panes.zig b/core/panes.zig
index 6fcb15b6..fe127acd 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -1071,6 +1071,14 @@ pub const Pane = struct {
}
var buf: [16]u8 = undefined;
const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit status fits 16
+ // A failed run's last rows, read before its `exit N` goes under
+ // them: a report's places are at its end, and its detail is the
+ // tool's lines, not the run's status (UX F2).
+ const rows: ?[]const []const u8 = if (status == 0) null else if (pane.terminal) |state| read: {
+ const grid = Term.grid(state);
+ const first = grid.total -| 400;
+ break :read Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch null;
+ } else null;
var said: pardes.Kind.Buf(32) = .{};
const lead = if (Term.grid(pane.terminal).cursor_x != 0) "\r\n" else "";
pane.feedOutput(p, said.print("{s}exit {s}\r\n", .{ lead, code }));
@@ -1078,21 +1086,17 @@ pub const Pane = struct {
p.needs_frame = true;
// A failed run whose report names places (a compiler's
// `path:line:col: error: ...`): an error of this pane, the places
- // its words, the rows after its first its detail (SPEC §10.2). Its
- // last rows only: a report's places are at its end.
- if (status != 0) if (pane.terminal) |state| report: {
- const grid = Term.grid(state);
- const first = grid.total -| 400;
- const rows = Term.editRows(state, p.scratch.allocator(), first, grid.total - first) catch break :report;
+ // its words, the rows after its first its detail (SPEC §10.2).
+ if (rows) |report_rows| report: {
var found: pardes.Messages.Said = .{};
- if (pardes.Messages.readPlaces(&found, pane.cwdSlice(), rows) == 0) break :report;
+ if (pardes.Messages.readPlaces(&found, pane.cwdSlice(), report_rows) == 0) break :report;
var words: pardes.Kind.Buf(32) = .{};
const kept = pardes.Messages.say(p, .@"error", id, words.print("exit {s}", .{code}));
kept.places = found.places;
kept.places_len = found.places_len;
kept.detail = found.detail;
kept.detail_len = found.detail_len;
- };
+ }
}
};
@@ -1981,6 +1985,9 @@ test "a command whose run fails naming places is an error of its pane, those pla
try std.testing.expectEqual(@as(u8, 1), said.places_len);
try std.testing.expectEqualStrings("/tmp/pardes-cmd/core/pick.zig", said.places[0].path.slice());
try std.testing.expectEqualStrings(" const best = rank(q, name, 3);", said.detail[0].slice());
+ // The tool's lines alone: pardes's own `exit 1` under them is the run's
+ // status, in the command's tag and on the notice row (UX F2).
+ try std.testing.expectEqual(@as(u8, 1), said.detail_len);
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
const s = try p.render(frame.allocator());