summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/Core.zig22
-rw-r--r--core/Kind.zig2
-rw-r--r--core/Layer.zig4
-rw-r--r--core/Messages.zig81
-rw-r--r--core/draw.zig7
-rw-r--r--core/panes.zig4
6 files changed, 66 insertions, 54 deletions
diff --git a/core/Core.zig b/core/Core.zig
index e8b5c024..96fd547e 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -1708,7 +1708,7 @@ fn updateInner(p: *Pardes, ev: Event) void {
// Its bands as its state stands: a step reads them (a press on a chip, a
// body's top under them), and what a frame drew, a view put back or a
// dump left in Pane.notices (derived) is not what every core has.
- for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id], id);
+ for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id]);
defer pardes.panes.File.syncTwins(p);
defer p.reportFocus();
// A tick with no deadline due is the one event that cannot change
@@ -1913,7 +1913,7 @@ fn noteLateFailureInner(p: *Pardes, id: Pane.Id) void {
pub const presented = pardes.tape.taped(presentedInner);
fn presentedInner(p: *Pardes) void {
const v = p.view();
- for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id], id);
+ for (p.panes, 0..) |slot, id| if (slot) |pane| Messages.collectNotices(p, pane, v.rects[id]);
if (v.pointer_inside and v.drag != .none) {
v.hover_col = v.pointer_raw_col;
v.hover_row = v.pointer_raw_row;
@@ -2078,7 +2078,7 @@ pub fn sync(p: *Pardes) void {
}.ready, .{pane}));
// Which bands a pane shows is the step's, as its geometry is:
// what is drawn under them, and where a click lands, read it.
- Messages.collectNotices(p, pane, r, id);
+ Messages.collectNotices(p, pane, r);
// The greeting `ls` of a new terminal in a directory is typed at
// its shell's FIRST prompt, or never: typed later it would land
// in whatever runs then, or in the middle of a line someone
@@ -2651,22 +2651,6 @@ test "TreeContext rows in the tag style keep the message rows" {
p.sync();
_ = try p.render(p.scratch.allocator());
try std.testing.expectEqual(full_height, p.surface.body_layers[0].viewport.h);
- // ...and the leader's chip (a shown level's last leaf) is an overlay
- // at the body's top (the level itself wraps the tag: TagState).
- const r = p.view().rects[0];
- 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;
- p.sync();
- _ = try p.render(p.scratch.allocator());
- const band = for (p.surface.tagLayers()) |*layer| {
- if (layer.rows != 0 and layer.kind == .notice) break layer;
- } else return error.NoNoticeBand;
- try std.testing.expectEqual(p.bodyTop(pane, r), band.viewport.y);
- try std.testing.expectEqual(r.x + r.w, band.viewport.x + band.viewport.w);
- p.view().prefix = .none;
}
test "TreeContext command and custom tag survive a workspace round trip" {
diff --git a/core/Kind.zig b/core/Kind.zig
index 806cd858..4e1aa469 100644
--- a/core/Kind.zig
+++ b/core/Kind.zig
@@ -766,7 +766,7 @@ pub fn viewOf(p: *const Pardes, k: u8, id: usize) c.pa_view {
if (collapsed) return out;
// Its bands made again, never the copy a step or a park left: they are
// derived, so a client joined from a dump has none.
- const notices = pardes.Messages.bands(p, v, pane, tag_rows, r, id).span();
+ const notices = pardes.Messages.bands(p, pane, tag_rows, r).span();
const th = p.theme();
const rgb = struct {
fn f(x: [3]u8) u32 {
diff --git a/core/Layer.zig b/core/Layer.zig
index df86821a..43c8191c 100644
--- a/core/Layer.zig
+++ b/core/Layer.zig
@@ -16,8 +16,8 @@ const layout = @import("layout.zig");
const Layer = @This();
-/// `notice` is a pane's transient line -- a builtin's name, a pending leader
-/// chord -- carried as a tagline-shaped band so it gets the tagline's height,
+/// `notice` is a pane's transient line -- a prompt waiting for input --
+/// carried as a tagline-shaped band so it gets the tagline's height,
/// small-font metrics, band offset and border instead of being a body-grid row
/// wearing a tagline font.
/// `band` is the rows a pane's tag unrolls into below it (Band.zig).
diff --git a/core/Messages.zig b/core/Messages.zig
index 3fef1842..8ecf2919 100644
--- a/core/Messages.zig
+++ b/core/Messages.zig
@@ -3,8 +3,8 @@
//! that explain it, kept in a fixed list while it lives; the log of
//! everything said behind them (the history, `SPC h m`, and 9P `/log`);
//! the notice row at the window's foot that indexes them; and the
-//! transient bands a pane shows over its body's top rows (the pending
-//! leader chord, a prompt waiting for input).
+//! transient band a pane shows over its body's top rows (a prompt waiting
+//! for input).
const pardes = @import("root.zig");
const memory = @import("memory.zig");
const std = @import("std");
@@ -190,16 +190,6 @@ pub const LoggedMessage = struct {
}
};
-/// 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 {
const libc = std.c;
const Tm = extern struct {
@@ -683,6 +673,8 @@ pub const Row = struct {
left: usize = 0,
right: usize = 0,
text: []const u8 = "",
+ /// The message the left says, when it says one.
+ lead: ?*const Said = null,
};
/// Room for the notice row's line: the widest window's at the tagline's
@@ -691,6 +683,15 @@ pub const notice_row_cap = 1024;
pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row {
const m = &p.messages;
+ const tab = p.settings.tab;
+ // A rolled level's last leaf, while the level shows: what it does, the
+ // whole row (SPEC §3.7's first mockup).
+ if (pardes.TagState.lastUsed(p, p.view(), out)) |used| {
+ var end = @min(used.len, panes.File.rawAtDisplay(tab, used, width));
+ while (end > 0 and panes.File.displayWidth(tab, used[0..end]) > width) end -= 1;
+ while (end > 0 and end < used.len and used[end] & 0xC0 == 0x80) end -= 1;
+ return .{ .left = end, .right = end, .text = used[0..end] };
+ }
var w: std.Io.Writer = .fixed(out);
var live: usize = 0;
var questions: usize = 0;
@@ -723,7 +724,6 @@ pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row {
r.print("{d} message{s} \u{b7} SPC h m", .{ m.len, if (m.len == 1) "" else "s" }) catch {};
const tail = r.buffered();
// The left cut to make room for the right, a blank between them.
- const tab = p.settings.tab;
const tail_w = panes.File.displayWidth(tab, tail);
const room = width -| (tail_w + 1);
var cut = left_end;
@@ -739,14 +739,13 @@ 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() };
+ return .{ .left = cut, .right = right_at, .text = w.buffered(), .lead = lead };
}
/// 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: *[leader_room]u8) []const u8 {
+pub fn noticeText(pane: *const Pane, i: usize) []const u8 {
return switch (pane.notices.kinds[i]) {
- .leader => leaderText(p, leader_buf),
.prompt => pane.promptText() orelse "",
};
}
@@ -915,8 +914,8 @@ pub fn reportFailure(p: *Pardes, id: usize, text: []const u8) void {
/// in what order. Everything downstream reads the answer: the body layer
/// so it does not paint under them, and the paint pass so it can stack
/// them instead of letting the last one win the row.
-pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void {
- pane.notices = bands(p, p.view(), pane, pane.tag_rows, r, id);
+pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect) void {
+ pane.notices = bands(p, pane, pane.tag_rows, r);
// Each band's chip at the right edge, as wide as its own text and a
// blank cell either side, the pane's width at most: a click finds it
// whether or not a frame has drawn it. An overlay over the body's top
@@ -925,21 +924,18 @@ 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: [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;
+ const chip = panes.File.displayWidth(p.settings.tab, noticeText(pane, i)) + 2;
pane.notices.left[i] = if (tw == 0) std.math.maxInt(u16) else tx + tw - @as(u16, @intCast(@min(chip, tw)));
}
}
-/// The bands pane `id` shows in view `v`, over `r` below its `tag_rows`:
-/// the live view's each step, and any view's for its kind's facts
-/// (Kind.viewOf), made from what a dump keeps (the bands are derived).
-pub fn bands(p: *const Pardes, v: *const Pardes.View, pane: *const Pane, tag_rows: u16, r: Rect, id: usize) Pane.Notices {
+/// The bands a pane shows over `r` below its `tag_rows`: the live view's
+/// each step, and any view's for its kind's facts (Kind.viewOf), made from
+/// what a dump keeps (the bands are derived).
+pub fn bands(p: *const Pardes, pane: *const Pane, tag_rows: u16, r: Rect) Pane.Notices {
var n: Pane.Notices = .{};
if (r.w <= config.GUTTER or r.h <= tag_rows) return n;
- 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;
@@ -1195,6 +1191,39 @@ test "the notice row leads with the most important live message, its count and p
try std.testing.expect(std.mem.endsWith(u8, row.text, "+2 \u{b7} 1 question \u{b7} SPC e"));
}
+test "a rolled level's last leaf is said on the notice row, the whole row, never in a chip over the body; at rest the row is the messages' again" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 30 });
+ defer p.deinit();
+ const pane = try p.setTestFile("one\n");
+ p.messages.live_len = 0;
+ p.clock.now_ns = 5 * std.time.ns_per_s;
+ p.clock.stepped_ns = p.clock.now_ns;
+ // SPC t w: Wrap, run from SPC t; then SPC t again, shown.
+ for (" tw t") |c| p.update(.{ .key = .{ .cp = c } });
+ p.advance(p.clock.now_ns);
+ p.clock.now_ns = p.view().tag_state.due_ns;
+ p.sync();
+ _ = try p.render(p.scratch.allocator());
+ var buf: [notice_row_cap]u8 = undefined;
+ var row = noticeRow(p, 110, &buf);
+ try std.testing.expect(std.mem.startsWith(u8, row.text, "w Wrap: "));
+ try std.testing.expect(std.mem.endsWith(u8, row.text, " (last used here)"));
+ try std.testing.expectEqual(row.text.len, row.right);
+ try std.testing.expect(row.lead == null);
+ try std.testing.expectEqual(@as(u8, 0), pane.notices.len);
+ // Narrower than the line: cut to the width, never past it.
+ row = noticeRow(p, 12, &buf);
+ try std.testing.expectEqualStrings("w Wrap: Long", row.text);
+ // Esc: at rest, the messages' (Wrap's echo), and with none where the
+ // caret is.
+ p.update(.{ .key = .{ .cp = pardes.Key.escape } });
+ row = noticeRow(p, 110, &buf);
+ try std.testing.expect(row.lead != null);
+ p.messages.live_len = 0;
+ row = noticeRow(p, 110, &buf);
+ try std.testing.expect(std.mem.startsWith(u8, row.text, "/test.txt:1"));
+}
+
test "an idle core wants no wake, and a message wakes it once, when it dims" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
diff --git a/core/draw.zig b/core/draw.zig
index f7b2cd3f..125cf54f 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -95,7 +95,7 @@ pub fn place(p: *Pardes, s: *Surface) void {
for (&p.panes, 0..) |*slot, id| {
const pane = slot.* orelse continue;
paneFacts(p, &p.facts, id, pane);
- Messages.collectNotices(p, pane, v.rects[id], id);
+ Messages.collectNotices(p, pane, v.rects[id]);
const r = v.rects[id];
if (r.w <= config.GUTTER or r.h == 0) continue;
const owner: u8 = @intCast(id);
@@ -230,8 +230,7 @@ fn joinNotice(p: *Pardes, s: *Surface, arena: std.mem.Allocator, region: Region)
const kind = pane.notices.kinds[i];
const r = v.rects[id];
const chip = region.rect.w;
- var leader_buf: [Messages.leader_room]u8 = undefined;
- const text = Messages.noticeText(p, pane, i, &leader_buf);
+ const text = Messages.noticeText(pane, i);
const bg = chrome.tag_bg;
const fg = chrome.tag_fg;
// Nothing to say, or too narrow for a layer: a blank chip on the grid.
@@ -640,7 +639,7 @@ fn paintNoticeRow(p: *Pardes, s: *Surface) !void {
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]));
- if (p.messages.headline()) |lead| {
+ 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 };
};
diff --git a/core/panes.zig b/core/panes.zig
index 47765d90..f9c63e37 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -352,7 +352,7 @@ pub const Pane = struct {
ovl: ?Text.EditBuffer = null,
tty_filter: bool = false,
/// The transient lines this pane shows between its body and its tagline:
- /// the pending leader chord, a prompt waiting for input. Rebuilt every frame from the state that owns each one, so a
+ /// a prompt waiting for input. Rebuilt every frame from the state that owns each one, so a
/// line that goes away is simply not added again and the rest close the
/// gap -- there is no second copy of the truth to fall out of step. The
/// body layer reserves exactly `len` rows for them, the way it already
@@ -386,7 +386,7 @@ pub const Pane = struct {
pub const Notices = struct {
/// Painted bottom-up in this order, so a prompt keeps the row nearest
/// the tagline that it has always had, and its cursor with it.
- pub const Kind = enum { leader, prompt };
+ pub const Kind = enum { prompt };
pub const max = @typeInfo(Kind).@"enum".field_names.len;
kinds: [max]Kind = undefined,