diff options
Diffstat (limited to 'core/Messages.zig')
| -rw-r--r-- | core/Messages.zig | 43 |
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; |
