summaryrefslogtreecommitdiff
path: root/core/Messages.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 19:09:49 -0300
committerGabriel Schneider <[email protected]>2026-11-24 19:20:32 -0300
commitb7d275ab179635f1bf69bdb50833303c6942ff47 (patch)
tree3d7c50dd234e2cdff1bd2e567a400ed4546cc786 /core/Messages.zig
parent51766ee8e7c4a3e1f19d1dce4dcc2785a5eb0efb (diff)
downloadpardes-b7d275ab179635f1bf69bdb50833303c6942ff47.tar.gz
pardes-b7d275ab179635f1bf69bdb50833303c6942ff47.zip
TagState, keys: which-key, rolled (walk UI, pick-ui SPEC.md §3.2-§3.4, §3.7, item 2 of line A): a view's tag out of rest is its own (View.tag_state: the root the last key left current, when its level shows on the session's clock, whether it is unrolled, its cursor, the key it missed, the leaf each group ran last; in the dump and the digest, wire 36); the root and its keys are what the core already holds (SPC's leader keys, window mode's outline, the helix prefix the text with the keyboard waits on: TagState.current reads View.prefix and Text.normal.prefix both); a key that strikes a root starts its delay at the next advance, whose clock it is (TagState.asked, as Del's question), and the loop wakes for it (nextWake): SPC writes its key cell at once and shows its level 250 ms on, " and C-w the same (300, 250), g m z Z [ ] change nothing until 500 ms pass with no next key, so gg and gd never touch the tag; the head is computed tag text after the prefix in place of the tag's own text, never written into it (the coordinator's R1: tagline.shownTail, which tagText, sync's wrap and paintPaneTag read; an edit of the tag while it shows is refused): ` ␣ l ▸ a CodeAction b Callstack … ↓ unroll · ? help`, wrapped to three rows at most, keys in the key ink, LSP leaves dimmed in a pane no server speaks for, the leaf its group ran last underlined and said on the leader band's line (`k Hover: … (last used here)`, Messages.leaderText, where the SPC chip was); leaderKey on the binding tree (a level's children, not every builtin's row a key): a group goes down, a leaf runs and is remembered, a key with no child is struck and the level stays (was: the leader left), Backspace goes up a level, Enter runs the cursor's leaf (rolled: the last one run here); Down unrolls (the band is item 3), Up on the first row rolls up, Right/M-l and Left/M-h enter and leave a group; the helix prefixes take the same keys before their own (prefixKey), a key the root binds staying its (z Down scrolls); THE FAULT IT MET: walk.Get's list of a damaged image whose count runs past its elements left the rest undefined (fuzz.zig's "a dump and an image cut", restore seed 781 on this layout: a pane loaded with 256 location rows of 0xAA, freed by a key: integer overflow in SafeAllocator) and the load is now refused (core/walk.zig, after listInto); TESTS: TagState.zig's three (SPC at once then 250 ms, g at 500 ms, gg never; a leaf remembered, underlined, said and run again by Enter; a missed key struck, Backspace up), config.zig's Space-k test (a missed key is struck now, Esc leaves), Messages.zig's two chips (the leader's line); core-test 996 pass, 166 skip, 0 fail
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/Messages.zig')
-rw-r--r--core/Messages.zig43
1 files changed, 22 insertions, 21 deletions
diff --git a/core/Messages.zig b/core/Messages.zig
index 040b8d2c..6b406e91 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -56,18 +56,14 @@ pub const LoggedMessage = struct {
}
};
-/// `SPC` plus the chord keys typed so far, spaced out the way the help
-/// index spells a leader path.
-fn leaderText(p: *const Pardes, buf: *[16]u8) []const u8 {
- buf.* = @splat(' ');
- @memcpy(buf[0..3], "SPC");
- var end: usize = 3;
- for (p.view().leader_keys[0..p.view().leader_n]) |ch| {
- if (end + 2 > buf.len) break;
- buf[end + 1] = ch;
- end += 2;
- }
- return buf[0..end];
+/// The room the leader band's line takes (TagState.lastUsed): a leaf's
+/// key, word and summary (builtins.summary_max), and "(last used here)".
+pub const leader_room = 192;
+
+/// The leaf the current which-key level ran last, and what it does: the
+/// line under a rolled level (walk UI SPEC §3.7).
+fn leaderText(p: *const Pardes, buf: *[leader_room]u8) []const u8 {
+ return pardes.TagState.lastUsed(p, p.view(), buf) orelse "";
}
pub const Message = struct {
@@ -316,7 +312,7 @@ pub fn messageFrames(ms: u16) u16 {
/// 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(p: *const Pardes, pane: *const Pane, i: usize, leader_buf: *[16]u8) []const u8 {
+pub fn noticeText(p: *const Pardes, pane: *const Pane, i: usize, leader_buf: *[leader_room]u8) []const u8 {
return switch (pane.notices.kinds[i]) {
.message => pane.msg[0..pane.msg_len],
.older => pane.msg_older[pane.notices.index[i]].slice(),
@@ -497,7 +493,7 @@ pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void {
// draws, and a chip narrower than its text there would clip it.
const tx = r.x + config.GUTTER;
const tw = r.w -| config.GUTTER;
- var leader_buf: [16]u8 = undefined;
+ var leader_buf: [leader_room]u8 = undefined;
for (0..pane.notices.len) |i| {
const chip = panes.File.displayWidth(p.settings.tab, noticeText(p, pane, i, &leader_buf)) + 2;
pane.notices.left[i] = if (tw == 0) std.math.maxInt(u16) else tx + tw - @as(u16, @intCast(@min(chip, tw)));
@@ -514,7 +510,8 @@ pub fn bands(p: *const Pardes, v: *const Pardes.View, pane: *const Pane, tag_row
// new one lands under them; when rows run out the oldest go first.
for (pane.msg_older[0..pane.msg_older_len], 0..) |line, i| n.pushAt(.older, @intCast(i), line.slot);
if (pane.msg_len > 0) n.pushAt(.message, 0, pane.msg_slot);
- if (id == v.active and v.prefix == .leader) n.push(.leader);
+ var used_buf: [leader_room]u8 = undefined;
+ if (id == v.active and pardes.TagState.lastUsed(p, v, &used_buf) != null) n.push(.leader);
// Del's question shows once its delay is up: answered before that, it
// was never there.
const del_waiting = pane.prompt == .del_side and pane.question_due_ns > p.clock.now_ns;
@@ -834,7 +831,7 @@ test "a builtin announces itself on the message row, and Verbose silences it" {
}
test "notices stack over the body's top rows without moving them" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 24 });
defer p.deinit();
const id = p.view().active;
const pane = p.panes[id].?;
@@ -845,11 +842,15 @@ test "notices stack over the body's top rows without moving them" {
const r = p.view().rects[id];
const top = p.bodyTop(pane, r);
- // A message and a leader prefix at once: two chips, in the order
- // collectNotices chose, each one row tall and each one row further down.
- try std.testing.expect(p.executeBuiltinLine(id, "Msg first"));
+ // A message and the leader's line (a shown level's last leaf) at once:
+ // two chips, in the order collectNotices chose, each one row tall and
+ // each one row further down.
+ try std.testing.expect(p.executeBuiltinLine(id, "Msg first message here"));
p.view().prefix = .leader;
p.view().leader_n = 0;
+ p.view().tag_state.used[0] = 'q';
+ p.view().tag_state.due_ns = 1;
+ p.clock.now_ns = 1;
_ = frame.reset(.retain_capacity);
_ = try p.render(frame.allocator());
try std.testing.expectEqual(@as(u8, 2), pane.notices.len);
@@ -869,8 +870,8 @@ test "notices stack over the body's top rows without moving them" {
seen += 1;
}
try std.testing.expectEqual(@as(usize, 2), seen);
- // "first" is longer than "SPC", so its chip is wider.
- try std.testing.expect(pane.notices.left[0] < pane.notices.left[1]);
+ // The leader's line is longer than the message, so its chip is wider.
+ try std.testing.expect(pane.notices.left[0] > pane.notices.left[1]);
// Gone with the notices: no stale chip left behind.
p.view().prefix = .none;