diff options
Diffstat (limited to 'core/Messages.zig')
| -rw-r--r-- | core/Messages.zig | 1291 |
1 files changed, 873 insertions, 418 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 6b406e91..3fef1842 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -1,6 +1,10 @@ -//! The message row: messages and statuses a pane shows between its body and -//! its tagline, how each line lingers once dismissed, the notices -//! built from them every frame, and the log of everything said. +//! The session's messages (pick-ui SPEC §10): each a kind, its cause as a +//! word a Look understands, its text, the places it names and the lines +//! 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). const pardes = @import("root.zig"); const memory = @import("memory.zig"); const std = @import("std"); @@ -16,12 +20,14 @@ const BOX_H = pardes.BOX_H; const Key = pardes.Key; const Rect = layout.Rect; const Pardes = pardes.Pardes; +const Buf = pardes.Kind.Buf; const Messages = @This(); /// Where its ring's next line goes and how many it holds, held to the ring -/// where a dump is read back (walk.zig `.place`). -pub const replica = .{ .place = .{ .{ "head", "lastSlot" }, .{ "len", "size" } } }; +/// where a dump is read back (walk.zig `.place`); the live messages as far +/// as they go. +pub const replica = .{ .place = .{ .{ "head", "lastSlot" }, .{ "len", "size" } }, .len = .{.{ "live", "live_len" }} }; /// The message-row log: a fixed ring, never allocated, never grown. See /// `logMessage` and the `Messages` builtin. @@ -29,6 +35,14 @@ log: [limits.message_log]LoggedMessage = @splat(.{}), /// Next slot to write. `len` saturates at the ring's size. head: usize = 0, len: usize = 0, +/// The messages that live, oldest first: what the notice row, the marks +/// and the ghosts at a cause's line are drawn from each frame. +live: [max_live]Said = undefined, +live_len: u8 = 0, + +/// How many messages live at once: past it the oldest that is no +/// question goes (a burst of distinct ones; a repeat only counts). +pub const max_live = 16; pub fn lastSlot(m: *const Messages) usize { return m.log.len - 1; @@ -38,6 +52,125 @@ pub fn size(m: *const Messages) usize { return m.log.len; } +/// What a message is, which says how long it lives (SPEC §10.1): an echo +/// and a notice until the next message, bright for `MessageLinger`; a +/// warning bright twice that, until Esc; an error until Esc or the next +/// error; a question until it is answered; progress while it runs, at the +/// right end of its tag rather than on the notice row. +pub const Kind = enum(u8) { + echo, + notice, + warn, + @"error", + question, + progress, + + pub fn glyph(k: Kind) []const u8 { + return switch (k) { + .echo => "\u{2713}", + .notice => "\u{b7}", + .warn => "!", + .@"error" => "\u{2717}", + .question => "?", + .progress => "\u{22ef}", + }; + } + + /// Which wins the notice row and a mark: error, question, warning, + /// notice, echo; progress never. + pub fn rank(k: Kind) u8 { + return switch (k) { + .progress => 0, + .echo => 1, + .notice => 2, + .warn => 3, + .question => 4, + .@"error" => 5, + }; + } +}; + +/// A place a message names: a file's line and column, and what it says +/// there (a compiler's `error: ...`), which the body shows at that line. +pub const Place = struct { + path: Buf(256) = .{}, + line: u32 = 1, + col: u32 = 1, + text: Buf(128) = .{}, +}; + +/// The questions the session asks in the background, and their answers. +pub const Ask = enum(u8) { + none, + /// A file changed on disk under unsaved text. + disk, + + /// Its answers, as its pane's tag offers them: the key that gives one, + /// and its word (an Exec of the word's first word gives it too). + pub fn answers(a: Ask) []const Answer { + return switch (a) { + .none => &.{}, + .disk => &.{ .{ .key = 'r', .word = "Reload" }, .{ .key = 'k', .word = "Keep mine" }, .{ .key = 'd', .word = "Diff" } }, + }; + } +}; + +pub const Answer = struct { key: u8, word: []const u8 }; + +/// One live message. +pub const Said = struct { + pub const replica = .{ .len = .{ .{ "places", "places_len" }, .{ "detail", "detail_len" } } }; + pub const max_places = 4; + pub const max_detail = 4; + kind: Kind = .notice, + /// Its cause, first, as a word a Look understands: a file's path, a + /// pane's `@pN` (and its command), a server's name. + src: Buf(96) = .{}, + text: Buf(256) = .{}, + places: [max_places]Place = undefined, + places_len: u8 = 0, + /// The lines that explain it, shown under its first place's line while + /// the caret is on it. + detail: [max_detail]Buf(128) = undefined, + detail_len: u8 = 0, + /// The serial of the pane it is about, 0 for none in particular. + pane: u32 = 0, + asks: Ask = .none, + /// Its detail shown under its first place's line whatever the caret + /// (a question's Diff). + open: bool = false, + /// How many times in a row it was said. + n: u16 = 1, + /// When it was last said, on the core's clock (`Pardes.clock.now_ns`). + t: u64 = 0, + + /// Its words without the clock a host stamped on them (Message.stamp). + pub fn words(s: *const Said) []const u8 { + return Message.body(s.text.slice()); + } + + /// Whether it has dimmed: an echo or a notice past `linger_ms`, a + /// warning past twice that. + pub fn faded(s: *const Said, now_ns: u64, linger_ms: u16) bool { + const bright: u64 = switch (s.kind) { + .echo, .notice => linger_ms, + .warn => 2 * @as(u64, linger_ms), + else => return false, + }; + return now_ns -| s.t >= bright * std.time.ns_per_ms; + } + + /// Whether it is about `pane`: said of it, or naming its file (as its + /// cause or among its places). + pub fn about(s: *const Said, pane: *const Pane) bool { + if (s.pane != 0 and s.pane == pane.serial) return true; + const f = pane.file orelse return false; + if (std.mem.eql(u8, s.src.slice(), f.path)) return true; + for (s.places[0..s.places_len]) |*place| if (std.mem.eql(u8, place.path.slice(), f.path)) return true; + return false; + } +}; + pub const LoggedMessage = struct { pub const cap = 256; pub const replica = .{ .len = .{.{ "text", "len" }} }; @@ -50,6 +183,7 @@ pub const LoggedMessage = struct { /// How many times in a row. Saturating: a key held down against the same /// refusal is one event, not four hundred. repeats: u16 = 0, + kind: Kind = .notice, pub fn slice(m: *const LoggedMessage) []const u8 { return m.text[0..m.len]; @@ -133,195 +267,491 @@ pub const Message = struct { } }; -/// A status updates the message line in place (a progress count does not -/// pile up); a message is an event, and stacks. + +/// A status updates its line in place (a progress count does not pile up), +/// and is not logged; a message is an event. pub const setStatus = pardes.tape.taped(setStatusInner); fn setStatusInner(p: *Pardes, id: Pane.Id, text: []const u8) void { - showMessage(p, id.index(), text, false); + // No text: the pane's progress is over, and goes. + if (text.len == 0) { + const serial: u32 = if (id.index() < MAX_PANES) if (p.panes[id.index()]) |pane| pane.serial else 0 else 0; + const m = &p.messages; + for (m.live[0..m.live_len], 0..) |*s, i| if (s.kind == .progress and s.pane == serial) { + m.remove(i); + p.needs_frame = true; + break; + }; + return; + } + _ = say(p, .progress, id.index(), text); } pub const setMessage = pardes.tape.taped(setMessageInner); fn setMessageInner(p: *Pardes, id: Pane.Id, text: []const u8) void { - logMessage(p, id.index(), text); - showMessage(p, id.index(), text, true); + _ = say(p, .notice, id.index(), text); } -fn showMessage(p: *Pardes, id: usize, text: []const u8, stack: bool) void { - if (id >= MAX_PANES) return; - const pane = p.panes[id] orelse return; +/// Say `text`, a message of `kind` about pane `id` (MAX_PANES and up: +/// none in particular), its cause first: logged (progress is not), and +/// live (`keep`); the message, for the places it names. +pub fn say(p: *Pardes, kind: Kind, id: usize, text: []const u8) *Said { + if (kind != .progress) logMessage(p, id, kind, text); + const pane: ?*Pane = if (id < MAX_PANES and !p.fs.session_write) p.panes[id] else null; + var src: Buf(96) = .{}; + if (pane) |cause| causeWord(cause, &src); + return keep(p, kind, if (pane) |cause| cause.serial else 0, src.slice(), text); +} + +/// 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 line = pane.command orelse { + _ = out.print(config.pane_addr ++ "{d}", .{pane.serial}); + return; + }; + 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] }); +} + +/// Make a message live, and return it (for its places and its detail): +/// a new message retires every echo and notice, a new error the error +/// before it; the same message again right after itself is counted. The +/// list is in the order things were said. +pub fn keep(p: *Pardes, kind: Kind, serial: u32, src: []const u8, text: []const u8) *Said { + const m = &p.messages; + p.needs_frame = true; // One row of printable text: a language server's multi-line report // reads as one line, and the cut never leaves half a glyph behind. - var n: usize = @min(text.len, pane.msg.len); + var row: [256]u8 = undefined; + var n: usize = @min(text.len, row.len); if (n < text.len) { while (n > 0 and text[n] & 0xC0 == 0x80) n -= 1; } - const same = pane.msg_len == n and for (text[0..n], pane.msg[0..n]) |c, have| { - if ((if (c < 0x20 or c == 0x7f) ' ' else c) != have) break false; - } else true; - // A new event moves the line on screen up the stack, where it keeps - // its own timing, and falls in below it. - // Only an event stacks on an event: an announcement or a status - // stands in for whatever comes next. - if (stack and pane.msg_len > 0 and !same and !pane.msg_announcement and !pane.msg_status) - pane.pushOlderMessage(); - if (pane.msg_len == 0) pane.msg_slot = pane.freeMessageSlot(); - pane.msg_announcement = false; - pane.msg_sent = false; - pane.msg_status = !stack; - for (text[0..n], pane.msg[0..n]) |c, *cell| cell.* = if (c < 0x20 or c == 0x7f) ' ' else c; - pane.msg_len = @intCast(n); - // The clock when it was said (the session clock is the last pump's, - // and a 9P write after an idle hour would say it an hour ago). - pane.msg_said_ms = p.tape.value(.clock, nowMs, .{}); - p.needs_frame = true; - // New, the same line again or a status update: fresh, so it stays. - pane.msg_life = .{}; + for (text[0..n], row[0..n]) |c, *cell| cell.* = if (c < 0x20 or c == 0x7f) ' ' else c; + const line = row[0..n]; + const now = p.clock.now_ns; + // Progress from the same cause is updated, and is the newest said. + if (kind == .progress) for (m.live[0..m.live_len], 0..) |*s, i| { + if (s.kind != .progress or s.pane != serial or !std.mem.eql(u8, s.src.slice(), src)) continue; + const kept = s.*; + m.remove(i); + const last = &m.live[m.live_len]; + m.live_len += 1; + last.* = kept; + last.text.set(line); + last.t = now; + return last; + }; + if (m.live_len > 0) { + // The NEWEST wording wins, so it carries the latest clock. + const last = &m.live[m.live_len - 1]; + if (last.kind == kind and last.pane == serial and std.mem.eql(u8, last.src.slice(), src) and + std.mem.eql(u8, Message.body(last.text.slice()), Message.body(line))) + { + last.n +|= 1; + last.t = now; + last.text.set(line); + return last; + } + } + if (kind != .progress) { + var i: usize = 0; + while (i < m.live_len) { + const old = m.live[i].kind; + if (old == .echo or old == .notice or (kind == .@"error" and old == .@"error")) m.remove(i) else i += 1; + } + } + if (m.live_len == max_live) { + var oldest: usize = 0; + while (oldest + 1 < m.live_len and m.live[oldest].kind == .question) oldest += 1; + m.remove(oldest); + } + const s = &m.live[m.live_len]; + m.live_len += 1; + s.* = .{ .kind = kind, .pane = serial, .t = now }; + s.src.set(src); + s.text.set(line); + return s; } -/// With no frontend attached no input dismisses a message, and a detached -/// session's /screen and messages kept what was said an hour ago: each -/// pane's lines go once its newest has been up `message_linger_ms`, on the -/// clock, checked as the core is stepped (each event, and each pump after -/// its wait, which a message wakes) -- not as a 9P request is served, since -/// a read is answered while a step is out and must change nothing, nor by -/// the host, whose call is no input a replay makes. -/// ponytail: a pane's older lines go with its newest, not each on its own -/// clock; the render pipeline's clock will give every line its own. -fn nowMs() i64 { - var ts: std.c.timespec = undefined; - if (std.c.clock_gettime(.MONOTONIC, &ts) != 0) return 0; - return @as(i64, ts.sec) * 1000 + @divTrunc(@as(i64, ts.nsec), 1_000_000); +pub fn remove(m: *Messages, i: usize) void { + std.mem.copyForwards(Said, m.live[i .. m.live_len - 1], m.live[i + 1 .. m.live_len]); + m.live_len -= 1; } -pub fn expireUnattended(p: *Pardes) void { - if (!p.unattended) return; - // The clock as the session that recorded read it (core/tape.zig). - const now = p.tape.value(.clock, nowMs, .{}); - for (p.panes) |slot| { - const pane = slot orelse continue; - if (pane.msg_len == 0 and pane.msg_older_len == 0) continue; - if (awaited(p, pane)) continue; - if (now - pane.msg_said_ms < p.settings.message_linger_ms) continue; - pane.msg_len = 0; - pane.msg_life = .{}; - pane.msg_older_len = 0; - p.needs_frame = true; +/// Retire every live message of `kinds` (Esc: the warnings and errors); +/// how many went. +pub fn retire(m: *Messages, kinds: []const Kind) usize { + var gone: usize = 0; + var i: usize = 0; + while (i < m.live_len) { + if (std.mem.indexOfScalar(Kind, kinds, m.live[i].kind) != null) { + m.remove(i); + gone += 1; + } else i += 1; } + return gone; } -/// A message waits for someone to see it, and a view kept for its client's -/// return (views.away: an Upgrade's clients, a divergence's) is someone -/// on the way: what its keyboard's pane says (an Upgrade's outcome, -/// upgrade.zig `tellEveryView`) is that client's until it is back for its -/// view (Pardes.rejoinView: its join's dump has it) or the view's kept -/// time is up; no other view's input and no unattended clock take it. A -/// pair's one client is such a client; the session's own frontend is -/// none (its view is never away). A session no build could load starts -/// afresh with no view kept: a pair's is held attended for its client -/// instead (tui.zig `Own.start`). -fn awaited(p: *const Pardes, pane: *const Pane) bool { - if (p.views_away == 0) return false; - for (p.views, 0..) |slot, k| if (slot) |v| { - if (pardes.views.isAway(p, @intCast(k)) and p.panes[v.active] == pane and - p.clock.now_ns -| v.away_ns < pardes.views.away_kept_ns) return true; - }; - return false; +/// The message the notice row leads with: the highest-ranked, the newest +/// within a rank; progress never. +pub fn headline(m: *const Messages) ?*const Said { + var best: ?*const Said = null; + for (m.live[0..m.live_len]) |*s| { + if (s.kind == .progress) continue; + if (best == null or s.kind.rank() >= best.?.kind.rank()) best = s; + } + return best; } -/// The key or click that used to clear the message row now starts each -/// line's exit: it stays `message_linger_ms`, then goes. A line already -/// on its way out keeps its own timing. -pub fn dismissMessage(p: *Pardes, pane: *Pane) void { - if (awaited(p, pane)) return; - if (pane.msg_len > 0 and dismissLine(p, &pane.msg_life)) { - pane.msg_len = 0; - pane.msg_life = .{}; - } - var i: usize = 0; - while (i < pane.msg_older_len) { - if (dismissLine(p, &pane.msg_older[i].life)) pane.removeOlderMessage(i) else i += 1; +/// The kind a pane's mark shows, one cell after its box (SPEC §10.2): the +/// most important live error, question, warning or progress about it (an +/// echo or a notice marks nothing); null for none. +pub fn markOf(m: *const Messages, pane: *const Pane) ?Kind { + var best: ?Kind = null; + for (m.live[0..m.live_len]) |*s| { + if (s.kind == .echo or s.kind == .notice or !s.about(pane)) continue; + if (best == null or s.kind.rank() > best.?.rank()) best = s.kind; } + return best; } -/// Start one line's exit; true when it is gone at once (no linger). -fn dismissLine(p: *const Pardes, life: *Pane.MessageLife) bool { - if (life.phase == .lingering) return false; - if (p.settings.message_linger_ms == 0) return true; - life.* = .{ .phase = .lingering }; - return false; +/// 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, + }; } -/// One frame of every lingering message line. The one that goes owes a -/// frame: a tick asks for none itself. -pub fn advanceMessages(p: *Pardes) void { - for (p.panes) |slot| { - const pane = slot orelse continue; - if (pane.msg_len > 0 and pane.msg_life.phase != .shown) { - p.needs_frame = true; - if (advanceLine(p, &pane.msg_life)) { - pane.msg_len = 0; - pane.msg_life = .{}; +/// The places a compiler's report names put on `s`: each +/// `path:line:col: error|warning|note: words` row (a relative path is +/// `dir`'s), its words there, and the rows after the first error, up to +/// the next place, its detail. How many it found; none without an error. +pub fn readPlaces(s: *Said, dir: []const u8, rows: []const []const u8) usize { + var errors: usize = 0; + var detailing = false; + for (rows) |raw| { + const row = std.mem.trimEnd(u8, raw, " \t\r\n"); + const found = placeOf(row) orelse { + if (detailing and row.len > 0 and s.detail_len < Said.max_detail) { + s.detail[s.detail_len] = .{}; + s.detail[s.detail_len].set(row); + s.detail_len += 1; } + continue; + }; + detailing = false; + const is_error = std.mem.startsWith(u8, found.text, "error"); + if (is_error) { + detailing = errors == 0; + errors += 1; } - var i: usize = 0; - while (i < pane.msg_older_len) { - if (pane.msg_older[i].life.phase != .shown) p.needs_frame = true; - if (advanceLine(p, &pane.msg_older[i].life)) pane.removeOlderMessage(i) else i += 1; + if (s.places_len == Said.max_places) continue; + const place = &s.places[s.places_len]; + place.* = .{ .line = found.line, .col = found.col }; + if (std.Io.Dir.path.isAbsolute(found.path)) place.path.set(found.path) else _ = place.path.print("{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), found.path }); + place.text.set(if (std.mem.startsWith(u8, found.text, "error: ")) found.text["error: ".len..] else found.text); + s.places_len += 1; + } + if (errors == 0) s.places_len = 0; + return s.places_len; +} + +/// A compiler's place row: `path:line:col: error|warning|note...`. +fn placeOf(row: []const u8) ?struct { path: []const u8, line: u32, col: u32, text: []const u8 } { + const a = std.mem.indexOfScalar(u8, row, ':') orelse return null; + const path = row[0..a]; + if (path.len == 0 or std.mem.indexOfAny(u8, path, " \t") != null) return null; + var rest = row[a + 1 ..]; + const b = std.mem.indexOfScalar(u8, rest, ':') orelse return null; + const line = std.fmt.parseInt(u32, rest[0..b], 10) catch return null; + rest = rest[b + 1 ..]; + const c = std.mem.indexOfScalar(u8, rest, ':') orelse return null; + const col = std.fmt.parseInt(u32, rest[0..c], 10) catch return null; + const text = std.mem.trim(u8, rest[c + 1 ..], " "); + for ([_][]const u8{ "error", "warning", "note" }) |word| { + if (std.mem.startsWith(u8, text, word)) return .{ .path = path, .line = line, .col = col, .text = text }; + } + return null; +} + +/// The question waiting on `pane`, an index into `live`; null for none. +pub fn waiting(m: *const Messages, pane: *const Pane) ?usize { + for (m.live[0..m.live_len], 0..) |*s, i| if (s.kind == .question and s.pane == pane.serial) return i; + return null; +} + +/// The answers of the question waiting on `pane`: what a `:` lists first +/// (pick-ui SPEC §10.4); none without one. +pub fn waitingAnswers(m: *const Messages, pane: *const Pane) []const Answer { + const i = m.waiting(pane) orelse return &.{}; + return m.live[i].asks.answers(); +} + +/// The waiting question's words as its pane's tag asks them, while the tag +/// is at rest (SPEC §3.2 asking): what it asks, its answers, and how to +/// give one. `answering`: SPC e gave it the keyboard. +pub fn askingText(m: *const Messages, pane: *const Pane, answering: bool, out: []u8) []const u8 { + const i = m.waiting(pane) orelse return ""; + const s = &m.live[i]; + var w: std.Io.Writer = .fixed(out); + w.print("{s} \u{25b8}", .{s.words()}) catch {}; + for (s.asks.answers()) |a| w.print(" {c} {s} ", .{ a.key, a.word }) catch {}; + w.writeAll(if (answering) "\u{b7} Esc later" else "\u{b7} SPC e to answer") catch {}; + return w.buffered(); +} + +/// Answer live question `i` with `key`: `r` reads the file again over its +/// unsaved text, `k` keeps the text and lets the disk's be, `d` shows (or +/// hides again) the disk's lines where they differ, as ghosts in its +/// body. False for a key that is none of its answers. +pub fn answer(p: *Pardes, i: usize, key: u8) bool { + const m = &p.messages; + const s = &m.live[i]; + const a = for (s.asks.answers()) |a| { + if (a.key == key) break a; + } else return false; + p.needs_frame = true; + const id = p.paneBySerial(s.pane) orelse { + m.remove(i); + return true; + }; + var said: Buf(256) = .{}; + if (key == 'd') { + if (s.open) { + s.open = false; + return true; } + diskDiff(p, s, id); + return true; } + logMessage(p, id, .echo, said.print("{s} {s} \u{b7} answered {s}", .{ s.src.slice(), s.words(), a.word })); + m.remove(i); + if (key == 'r') { + const pane = p.panes[id].?; + // The answer is the consent Get would ask for. + if (pane.file) |f| pane.discard_warned = .{ .revision = f.revision, .by = .get }; + pardes.exec.runBuiltin(p, .Get, id, "", null); + } else _ = say(p, .echo, id, "kept yours; the disk's is not read"); + return true; +} + +/// SPC e (the Message word, SPEC §10.4), on the message the notice row +/// leads with: an error that names places lists them in a +Search under +/// pane `id`, where n and N walk them, the first landed on, and the error +/// goes; a question takes the keyboard in its pane's tag; anything else, +/// or nothing, opens the history. +pub fn act(p: *Pardes, id: usize) void { + const m = &p.messages; + const lead = m.headline() orelse return openHistory(p, id); + if (lead.kind == .question) { + p.view().answering = lead.pane; + p.needs_frame = true; + return; + } + if (lead.kind != .@"error" or lead.places_len == 0 or id >= MAX_PANES) return openHistory(p, id); + const pane = p.panes[id] orelse return; + var rows: std.Io.Writer.Allocating = .init(p.gpa); + errdefer rows.deinit(); + for (lead.places[0..lead.places_len]) |*place| rows.writer.print("{s}:{d}:{d} {s}\n", .{ place.path.slice(), place.line, place.col, place.text.slice() }) catch |err| return reportError(p, .at(id), "Message", err); + const cause = lead.src; + const lead_at = for (m.live[0..m.live_len], 0..) |*s, k| { + if (s == lead) break k; + } else return; + m.remove(lead_at); + const content = rows.toOwnedSlice() catch |err| return reportError(p, .at(id), "Message", err); + pardes.panes.Output.fillResults(p, id, pardes.panes.paneDir(pane), .search, cause.slice(), content, null) catch |err| return reportError(p, .at(id), "Message", err); + _ = @import("look.zig").searchStep(p, id, 1); } -/// One frame of one line's life; true once it has gone. -fn advanceLine(p: *const Pardes, life: *Pane.MessageLife) bool { - if (life.phase == .shown) return false; - life.frame +|= 1; - return life.frame >= messageFrames(p.settings.message_linger_ms); +fn openHistory(p: *Pardes, id: usize) void { + pardes.panes.Output.openMessages(p, id) catch |err| reportError(p, .at(id), "messages", err); } -/// Move every lingering message line `frames` along its linger at once: -/// how `advance` jumps a wait instead of stepping it frame by frame. -pub fn holdMessages(p: *Pardes, frames: u64) void { - const n: u16 = @intCast(@min(frames, std.math.maxInt(u16))); - for (p.panes) |slot| { - const pane = slot orelse continue; - if (pane.msg_len > 0 and pane.msg_life.phase == .lingering) pane.msg_life.frame +|= n; - for (pane.msg_older[0..pane.msg_older_len]) |*line| { - if (line.life.phase == .lingering) line.life.frame +|= n; +/// An Exec of an answer's word in the tag of a pane a question waits on +/// (B2 on `Reload`): that answer. False for any other word. +pub fn answerWord(p: *Pardes, id: usize, word: []const u8) bool { + if (id >= MAX_PANES) return false; + const pane = p.panes[id] orelse return false; + const i = p.messages.waiting(pane) orelse return false; + const typed = std.mem.trim(u8, word, " \t\r\n"); + for (p.messages.live[i].asks.answers()) |a| { + const first = a.word[0 .. std.mem.indexOfScalar(u8, a.word, ' ') orelse a.word.len]; + if (std.mem.eql(u8, typed, first)) return answer(p, i, a.key); + } + return false; +} + +/// A question's Diff: the disk's text read (the host's read, taped) and +/// set against the buffer's, the lines they share at either end left out; +/// where they part, its place, and up to `Said.max_detail` of the lines +/// there, the disk's `+` and then the buffer's `-`, its detail, shown. +fn diskDiff(p: *Pardes, s: *Said, id: usize) void { + const pane = p.panes[id].?; + const f = if (pane.file) |*file| file else return; + const disk = @import("fs.zig").read(p, f.path) catch |err| return pardes.Messages.reportError(p, .at(id), "Diff", err); + defer p.gpa.free(disk); + const mine = pardes.panes.File.fileText(f, p.scratch.allocator()) catch return; + var a = std.mem.splitScalar(u8, mine, '\n'); + var b = std.mem.splitScalar(u8, disk, '\n'); + var line: u32 = 1; + var ours: []const u8 = ""; + var theirs: []const u8 = ""; + while (true) : (line += 1) { + const x = a.next(); + const y = b.next(); + if (x == null and y == null) return; + if (x != null and y != null and std.mem.eql(u8, x.?, y.?)) continue; + ours = if (x) |l| mine[@intFromPtr(l.ptr) - @intFromPtr(mine.ptr) ..] else ""; + theirs = if (y) |l| disk[@intFromPtr(l.ptr) - @intFromPtr(disk.ptr) ..] else ""; + break; + } + // The lines both end with, left out. + var ours_end = ours.len; + var theirs_end = theirs.len; + while (ours_end > 0 and theirs_end > 0) { + const ol = std.mem.lastIndexOfScalar(u8, ours[0 .. ours_end - 1], '\n'); + const tl = std.mem.lastIndexOfScalar(u8, theirs[0 .. theirs_end - 1], '\n'); + const o_line = ours[if (ol) |nl| nl + 1 else 0..ours_end]; + const t_line = theirs[if (tl) |nl| nl + 1 else 0..theirs_end]; + if (!std.mem.eql(u8, o_line, t_line)) break; + ours_end = if (ol) |nl| nl + 1 else 0; + theirs_end = if (tl) |nl| nl + 1 else 0; + } + s.places[0] = .{ .line = line, .col = 1 }; + s.places[0].path.set(f.path); + s.places[0].text.set("the disk's differs here"); + s.places_len = 1; + s.detail_len = 0; + // The disk's first: it is what the answer shows. + for ([_]struct { []const u8, []const u8 }{ .{ "+", theirs[0..theirs_end] }, .{ "-", ours[0..ours_end] } }) |side| { + var rows = std.mem.splitScalar(u8, std.mem.trimEnd(u8, side[1], "\n"), '\n'); + while (rows.next()) |row| { + if (side[1].len == 0 or s.detail_len == Said.max_detail) break; + s.detail[s.detail_len] = .{}; + _ = s.detail[s.detail_len].print("{s}{s}", .{ side[0], row }); + s.detail_len += 1; } } + s.open = true; +} + +/// The words the newest live message said of `pane` has, "" for none: +/// what its band shows, and what a write that failed on it answers. +pub fn saidBy(m: *const Messages, pane: *const Pane) []const u8 { + var i = m.live_len; + while (i > 0) { + i -= 1; + if (m.live[i].pane == pane.serial) return m.live[i].text.slice(); + } + return ""; } -/// Frames until this pane's message lines next change: the rest of a -/// linger, null when every line just shows. -pub fn messageWake(p: *const Pardes, pane: *const Pane) ?u64 { +/// When the next live message dims, on the core's clock; null for none. +pub fn dimDue(p: *const Pardes) ?u64 { + const m = &p.messages; + if (p.settings.message_linger_ms == 0) return null; var soonest: ?u64 = null; - const linger = messageFrames(p.settings.message_linger_ms); - for (0..@as(usize, pane.msg_older_len) + 1) |i| { - const life = if (i < pane.msg_older_len) pane.msg_older[i].life else if (pane.msg_len > 0) pane.msg_life else continue; - if (life.phase == .shown) continue; - const frames: u64 = @max(1, linger -| life.frame); - soonest = if (soonest) |n| @min(n, frames) else frames; + for (m.live[0..m.live_len]) |*s| { + const bright: u64 = switch (s.kind) { + .echo, .notice => p.settings.message_linger_ms, + .warn => 2 * @as(u64, p.settings.message_linger_ms), + else => continue, + }; + const due = s.t + bright * std.time.ns_per_ms; + if (due <= p.clock.stepped_ns) continue; + soonest = if (soonest) |first| @min(first, due) else due; } return soonest; } -/// Frames a message timing lasts; at least one. -pub fn messageFrames(ms: u16) u16 { - return @intCast(@max(1, (@as(u32, ms) + pardes.frame_ms - 1) / pardes.frame_ms)); +/// The notice row's line (SPEC §10.3), `width` columns: on the left the +/// message the row leads with (`headline`), its glyph, its cause, its +/// words, `×n` and the places it names; on the right how many more live, +/// the questions waiting, or the way to the history. With nothing live the +/// left says where the focused pane's caret is. Built each frame from the +/// state, in `out`. +pub const Row = struct { + /// The left part's end and the right part's start, in bytes of `text`. + left: usize = 0, + right: usize = 0, + text: []const u8 = "", +}; + +/// Room for the notice row's line: the widest window's at the tagline's +/// pitch (Layer.capacity) is cut to it. +pub const notice_row_cap = 1024; + +pub fn noticeRow(p: *const Pardes, width: usize, out: *[notice_row_cap]u8) Row { + const m = &p.messages; + var w: std.Io.Writer = .fixed(out); + var live: usize = 0; + var questions: usize = 0; + for (m.live[0..m.live_len]) |*s| { + if (s.kind == .progress) continue; + live += 1; + if (s.kind == .question) questions += 1; + } + const lead = m.headline(); + if (lead) |s| { + w.print("{s} ", .{s.kind.glyph()}) catch {}; + // Its cause first, unless its words name it already. + 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 {}; + 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 {}; + } else if (p.panes[p.view().active]) |pane| { + if (pane.file) |f| w.print("{s}:{d}", .{ f.path, pane.body.cur_row + 1 }) catch {} else w.writeAll(pane.cwdSlice()) catch {}; + } + const left_end = w.end; + var right: [64]u8 = undefined; + var r: std.Io.Writer = .fixed(&right); + if (live > 1) r.print("+{d} \u{b7} ", .{live - 1}) catch {}; + if (questions > 0) + r.print("{d} question{s} \u{b7} SPC e", .{ questions, if (questions == 1) "" else "s" }) catch {} + else if (lead != null and lead.?.kind == .@"error" and lead.?.places_len > 0) + r.writeAll("SPC e walk") catch {} + else if (m.len > 0) + 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; + if (panes.File.displayWidth(tab, out[0..cut]) > room) { + cut = panes.File.rawAtDisplay(tab, out[0..left_end], room); + while (cut > 0 and panes.File.displayWidth(tab, out[0..cut]) > room) { + cut -= 1; + while (cut > 0 and out[cut] & 0xC0 == 0x80) cut -= 1; + } + } + w.end = cut; + const gap = width -| (panes.File.displayWidth(tab, out[0..cut]) + tail_w); + for (0..gap) |_| w.writeByte(' ') catch {}; + const right_at = w.end; + w.writeAll(tail) catch {}; + return .{ .left = cut, .right = right_at, .text = w.buffered() }; } /// 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 { return switch (pane.notices.kinds[i]) { - .message => pane.msg[0..pane.msg_len], - .older => pane.msg_older[pane.notices.index[i]].slice(), .leader => leaderText(p, leader_buf), .prompt => pane.promptText() orelse "", }; } -fn logMessage(p: *Pardes, id: usize, text: []const u8) void { +fn logMessage(p: *Pardes, id: usize, kind: Kind, text: []const u8) void { if (text.len == 0) return; const serial: u32 = if (p.fs.session_write) 0 else if (id < MAX_PANES) if (p.panes[id]) |pane| pane.serial else 0 else 0; const kept = text[0..@min(text.len, LoggedMessage.cap)]; @@ -345,6 +775,7 @@ fn logMessage(p: *Pardes, id: usize, text: []const u8) void { @memcpy(slot.text[0..slot.len], kept); slot.serial = serial; slot.repeats = 1; + slot.kind = kind; p.messages.head = (p.messages.head + 1) % limits.message_log; p.messages.len = @min(p.messages.len + 1, limits.message_log); } @@ -474,9 +905,10 @@ pub fn reportFailure(p: *Pardes, id: usize, text: []const u8) void { if (failing_write) { p.fs.unlogged = true; defer p.fs.unlogged = false; - return setMessage(p, .at(id), text); + _ = say(p, .@"error", id, text); + return; } - setMessage(p, .at(id), text); + _ = say(p, .@"error", id, text); } /// The one place that decides which transient lines a pane is showing and @@ -506,10 +938,6 @@ pub fn collectNotices(p: *Pardes, pane: *Pane, r: Rect, id: usize) void { pub fn bands(p: *const Pardes, v: *const Pardes.View, pane: *const Pane, tag_rows: u16, r: Rect, id: usize) Pane.Notices { var n: Pane.Notices = .{}; if (r.w <= config.GUTTER or r.h <= tag_rows) return n; - // Oldest message line on top, so lines already up do not move when a - // 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); 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 @@ -522,28 +950,18 @@ pub fn bands(p: *const Pardes, v: *const Pardes.View, pane: *const Pane, tag_row // into blind. A two-row pane spends its only body row on one notice, // which is what the single shared row used to do anyway. const room: u8 = @intCast(@min(@as(u16, Pane.Notices.max), r.h - tag_rows)); - if (n.span() <= room) return n; - // Too short for the gaps: close them up in screen order, and if even - // that does not fit, the top bands go. - var i: usize = 1; - while (i < n.len) : (i += 1) { - var j = i; - while (j > 0 and n.row[j - 1] > n.row[j]) : (j -= 1) { - std.mem.swap(Pane.Notices.Kind, &n.kinds[j - 1], &n.kinds[j]); - std.mem.swap(u8, &n.index[j - 1], &n.index[j]); - std.mem.swap(u8, &n.row[j - 1], &n.row[j]); - } - } - const drop = n.len -| room; - for (0..n.len - drop) |k| { + if (n.len <= room) return n; + // Too short for them all: the top bands go. + const drop = n.len - room; + for (0..room) |k| { n.kinds[k] = n.kinds[k + drop]; - n.index[k] = n.index[k + drop]; n.row[k] = @intCast(k); } - n.len -= @intCast(drop); + n.len = room; return n; } + test "errors are said in words, and a ZON failure names its line" { var buf: [128]u8 = undefined; try std.testing.expectEqualStrings("file not found", errorWords(error.FileNotFound, &buf)); @@ -605,180 +1023,87 @@ test "the message log keeps what the row forgets, and collapses repeats" { try std.testing.expectEqualStrings(want_last, p.messages.at(limits.message_log - 1).?.slice()); } -test "Msg writes the transient row by hand, bare or with text, and input ends it" { +test "Msg says a notice by hand, bare or with text, and the next message retires it" { if (pardes.Term.ops == null) return error.SkipZigTest; // the classic boot's three shells const p = try Pardes.init(std.testing.allocator, .{ .shells = 3, .cols = 100, .rows = 30 }); defer p.deinit(); while (p.nextEffect()) |_| {} - const row = struct { - fn of(pp: *Pardes, i: usize) []const u8 { - const pane = pp.panes[i].?; - return pane.msg[0..pane.msg_len]; - } - }.of; - // the whole tail, spaces and all: the row is a sentence, not a word try std.testing.expect(p.executeBuiltinLine(2, "Msg saved /etc/hosts")); - try std.testing.expectEqualStrings("saved /etc/hosts", row(p, 2)); - // ...on the pane that ran it, and nowhere else - try std.testing.expectEqualStrings("", row(p, 0)); - + try std.testing.expectEqualStrings("saved /etc/hosts", p.messages.saidBy(p.panes[2].?)); + // ...of the pane that ran it, its cause that pane's address + try std.testing.expectEqualStrings("", p.messages.saidBy(p.panes[0].?)); + var want: [16]u8 = undefined; + try std.testing.expectEqualStrings(try std.fmt.bufPrint(&want, "@p{d}", .{p.panes[2].?.serial}), p.messages.headline().?.src.slice()); // Bare, it reports ITSELF through reportError — the `<operation>: <error in words>` - // every failed save and refused Look arrives in. + // every failed save and refused Look arrives in: an error. try std.testing.expect(p.executeBuiltinLine(2, "Msg")); - try std.testing.expectEqualStrings("Msg: no message", row(p, 2)); - - // Input starts its exit: it lingers, and is gone. - p.update(.{ .key = .{ .cp = Key.escape } }); - try std.testing.expectEqualStrings("Msg: no message", row(p, 2)); - for (0..200) |_| p.update(.tick); - try std.testing.expectEqualStrings("", row(p, 2)); - // ...and with no linger it is as old as your last input. - try std.testing.expect(p.executeBuiltinLine(2, "MessageLinger 0")); - try std.testing.expect(p.executeBuiltinLine(2, "Msg gone")); + try std.testing.expectEqualStrings("Msg: no message", p.messages.saidBy(p.panes[2].?)); + try std.testing.expectEqual(Kind.@"error", p.messages.headline().?.kind); + // Input takes nothing away; the next message does what the notice + // was, and the error stays until Esc. p.update(.{ .key = .{ .cp = 'h' } }); - try std.testing.expectEqualStrings("", row(p, 2)); + for (0..200) |_| p.update(.tick); + try std.testing.expectEqualStrings("Msg: no message", p.messages.saidBy(p.panes[2].?)); + try std.testing.expect(p.executeBuiltinLine(2, "Msg next")); + try std.testing.expectEqual(@as(u8, 2), p.messages.live_len); + try std.testing.expectEqual(Kind.@"error", p.messages.headline().?.kind); - // Longer than the row's buffer is CUT, never refused and never overrun: + // Longer than a message's room is CUT, never refused and never overrun: // this word is the only way to reach that boundary without a 300-byte path. var long: [600]u8 = @splat('x'); var line: [608]u8 = undefined; const cmd = try std.fmt.bufPrint(&line, "Msg {s}", .{&long}); try std.testing.expect(p.executeBuiltinLine(2, cmd)); - try std.testing.expectEqual(p.panes[2].?.msg.len, row(p, 2).len); + try std.testing.expectEqual(@as(usize, 256), p.messages.saidBy(p.panes[2].?).len); } -test "with no frontend attached a message goes once it has lingered, on the clock" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true }); +test "an echo or a notice retires those before it, an error the error before it, a repeat counts and progress runs in place" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); defer p.deinit(); - const pane = p.panes[p.view().active].?; - p.setMessage(.at(p.view().active), "said"); - p.setMessage(.at(p.view().active), "said again"); - // Attached: it waits for input, however long. - pane.msg_said_ms -= 60_000; - p.update(.tick); - try std.testing.expect(pane.msg_len > 0); - // Detached with nobody attached: past its linger it is gone, and the - // line above it with it. - p.unattended = true; - // A read served meanwhile changes nothing; the session's step after its - // wait expires, not the host (whose call no replay makes). - _ = p.serveFs(.{ .tag = 1, .op = .read, .node = @backingInt(ctlfs.TopFile.index), .size = 64 }); - try std.testing.expect(pane.msg_len > 0); - try p.pump(.{}); - try std.testing.expectEqual(@as(u16, 0), pane.msg_len); - try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len); - // A fresh one stays until its linger is up. - p.setMessage(.at(p.view().active), "fresh"); - p.update(.tick); - try std.testing.expect(pane.msg_len > 0); -} - -test "a message lingers past the input that dismisses it, and goes" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - const pane = p.panes[p.view().active].?; - try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 160")); - try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello")); - // Shown at once, until input; the same line again stays shown. - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); - try std.testing.expect(!p.animationActive()); - for (0..100) |_| p.update(.tick); - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); - try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello")); - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); - // Input (a key that announces nothing): 160 ms of lingering (ten frames), unaffected by more input... - p.update(.{ .key = .{ .cp = 'h' } }); - try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); - for (0..9) |_| { - p.update(.tick); - p.update(.{ .key = .{ .cp = 'h' } }); + _ = try p.setTestFile("text\n"); + const id = p.view().active; + const m = &p.messages; + m.live_len = 0; + _ = say(p, .notice, id, "first"); + _ = say(p, .echo, id, "second"); + try std.testing.expectEqual(@as(u8, 1), m.live_len); + try std.testing.expectEqualStrings("second", m.headline().?.text.slice()); + _ = say(p, .@"error", id, "broke"); + _ = say(p, .warn, id, "careful"); + // The echo went with the error; the warning stands beside it. + try std.testing.expectEqual(@as(u8, 2), m.live_len); + try std.testing.expectEqual(Kind.@"error", m.headline().?.kind); + _ = say(p, .@"error", id, "broke again"); + try std.testing.expectEqual(@as(u8, 2), m.live_len); + try std.testing.expectEqualStrings("broke again", m.headline().?.text.slice()); + // The same again right after itself: one message, counted, its newest + // wording (and clock) kept. + for (0..9) |_| _ = say(p, .@"error", id, "broke again"); + try std.testing.expectEqual(@as(u8, 2), m.live_len); + try std.testing.expectEqual(@as(u16, 10), m.headline().?.n); + // Progress updates its line in place and retires nothing. + _ = say(p, .progress, id, "Changes: jj 1/4"); + _ = say(p, .progress, id, "Changes: jj 3/4"); + try std.testing.expectEqual(@as(u8, 3), m.live_len); + try std.testing.expectEqualStrings("Changes: jj 3/4", m.saidBy(p.panes[id].?)); + try std.testing.expectEqual(Kind.@"error", m.headline().?.kind); + // Esc in normal mode takes the warnings and errors. + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(@as(u8, 1), m.live_len); + try std.testing.expectEqual(Kind.progress, m.live[0].kind); + try std.testing.expect(m.headline() == null); + // Past the room, the oldest that is no question goes. + m.live_len = 0; + for (0..max_live + 3) |i| { + var buf: [16]u8 = undefined; + _ = say(p, .warn, id, std.fmt.bufPrint(&buf, "w{d}", .{i}) catch unreachable); } - try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); - // ...then it is gone, and the tick that clears it owes the frame that - // shows it gone. - p.needs_frame = false; - p.update(.tick); - try std.testing.expectEqual(@as(u16, 0), pane.msg_len); - try std.testing.expect(p.needs_frame); - try std.testing.expect(!p.animationActive()); - // Shown again while lingering: fresh, so it stays; a status update to a - // line on screen swaps its text in place. - try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg again")); - p.update(.{ .key = .{ .cp = 'h' } }); - try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); - try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg again")); - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); - setStatus(p, .at(p.view().active), "progress 50%"); - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); - try std.testing.expectEqualStrings("progress 50%", pane.msg[0..pane.msg_len]); - try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len); + try std.testing.expectEqual(@as(u8, max_live), m.live_len); + try std.testing.expectEqualStrings("w3", m.live[0].text.slice()); } -test "messages stack, oldest on top, each on its own timing" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); - defer p.deinit(); - while (p.nextEffect()) |_| {} - const pane = p.panes[p.view().active].?; - try std.testing.expect(p.executeBuiltinLine(p.view().active, "Verbose off")); - try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 160")); - // `Verbose off` announced itself before it took effect. - pane.msg_len = 0; - pane.msg_life = .{}; - setMessage(p, .at(p.view().active), "first"); - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); - // A second message stacks under the first instead of replacing it. - setMessage(p, .at(p.view().active), "second"); - try std.testing.expectEqual(@as(u8, 1), pane.msg_older_len); - try std.testing.expectEqualStrings("first", pane.msg_older[0].slice()); - try std.testing.expectEqualStrings("second", pane.msg[0..pane.msg_len]); - collectNotices(p, pane, p.view().rects[p.view().active], p.view().active); - try std.testing.expectEqual(Pane.Notices.Kind.older, pane.notices.kinds[0]); - try std.testing.expectEqual(Pane.Notices.Kind.message, pane.notices.kinds[1]); - // One key dismisses both, each on its own clock: a line already - // lingering keeps its timing. - p.update(.{ .key = .{ .cp = 'h' } }); - try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_older[0].life.phase); - try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); - p.update(.tick); - setMessage(p, .at(p.view().active), "third"); - try std.testing.expectEqual(@as(u8, 2), pane.msg_older_len); - p.update(.{ .key = .{ .cp = 'h' } }); - const linger = messageFrames(p.settings.message_linger_ms); - for (0..linger - 1) |_| p.update(.tick); - // The first two are gone; the third, a frame later, still lingers. - try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len); - try std.testing.expectEqualStrings("third", pane.msg[0..pane.msg_len]); - try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); - p.update(.tick); - try std.testing.expectEqual(@as(u16, 0), pane.msg_len); - try std.testing.expect(!p.animationActive()); - // A status ticking in place does not pile up. - setStatus(p, .at(p.view().active), "lsp 10%"); - setStatus(p, .at(p.view().active), "lsp 20%"); - try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len); - // Lines keep their rows: when the top one leaves, the one under it does - // not move up, and the next message fills the gap instead. - setMessage(p, .at(p.view().active), "top"); - setMessage(p, .at(p.view().active), "under"); - try std.testing.expectEqual(@as(u8, 0), pane.msg_older[0].slot); - try std.testing.expectEqual(@as(u8, 1), pane.msg_slot); - pane.removeOlderMessage(0); - collectNotices(p, pane, p.view().rects[p.view().active], p.view().active); - try std.testing.expectEqual(@as(u8, 1), pane.notices.row[0]); - try std.testing.expectEqual(@as(u8, 2), pane.notices.span()); - setMessage(p, .at(p.view().active), "fills"); - try std.testing.expectEqual(@as(u8, 0), pane.msg_slot); - try std.testing.expectEqual(@as(u8, 1), pane.msg_older[0].slot); - // The stack keeps the newest few. - for ([_][]const u8{ "a", "b", "c", "d", "e" }) |text| setMessage(p, .at(p.view().active), text); - try std.testing.expectEqual(@as(u8, Pane.message_stack), pane.msg_older_len); - try std.testing.expectEqualStrings("b", pane.msg_older[0].slice()); - try std.testing.expectEqualStrings("e", pane.msg[0..pane.msg_len]); -} - -test "a builtin announces itself on the message row, and Verbose silences it" { +test "a builtin announces itself on the notice row, an echo, and Verbose silences it" { if (pardes.Term.ops == null) return error.SkipZigTest; // a terminal's tag row const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 }); defer p.deinit(); @@ -786,136 +1111,266 @@ test "a builtin announces itself on the message row, and Verbose silences it" { p.sync(); try std.testing.expect(p.settings.verbose); - // Wrap, not Collapse: a builtin that folds its own pane away leaves no row - // for its announcement, which is correct and not what this is testing. + // Wrap, not Collapse: a builtin that folds its own pane away is not + // what this is testing. try std.testing.expect(p.executeBuiltinLine(p.view().active, "Wrap")); - try std.testing.expectEqualStrings("Wrap", pane.msg[0..pane.msg_len]); - // A value it does not take is said, in place of the announcement. + try std.testing.expectEqualStrings("Wrap", p.messages.saidBy(pane)); + try std.testing.expectEqual(Kind.echo, p.messages.headline().?.kind); + // A value it does not take is said, an error, and leads the row. const wrapped = p.settings.wrap; try std.testing.expect(p.executeBuiltinLine(p.view().active, "Wrap maybe")); - try std.testing.expectEqualStrings("Wrap: takes on, off", pane.msg[0..pane.msg_len]); + try std.testing.expectEqualStrings("Wrap: takes on, off", p.messages.saidBy(pane)); try std.testing.expectEqual(wrapped, p.settings.wrap); - // The notice list is what the paint pass reads, so the announcement has to - // reach it, not just the buffer. - collectNotices(p, pane, p.view().rects[p.view().active], p.view().active); - try std.testing.expect(pane.notices.len > 0); - try std.testing.expectEqual(Pane.Notices.Kind.message, pane.notices.kinds[0]); - - // ...and it is carried as a tagline band, not a body row: that is what - // gives it the tagline's height, its small font and its border. + // ...on the window's foot row, a tagline-shaped layer, not on a chip + // over the pane's body. var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); - _ = try p.render(frame.allocator()); - const r = p.view().rects[p.view().active]; - 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(@as(u16, 1), band.viewport.h); - try std.testing.expectEqual(r.y + BOX_H, band.viewport.y); - // Right aligned: the text ends at the band's right edge. - const line = band.cells[0..band.cols]; - var last: usize = line.len; - while (last > 0 and line[last - 1].grapheme()[0] == ' ') last -= 1; - try std.testing.expect(last > 0); - try std.testing.expect(line[0].grapheme()[0] == ' '); + const s = try p.render(frame.allocator()); + try std.testing.expectEqual(@as(u8, 0), pane.notices.len); + const row = for (s.tagLayers()) |*layer| { + if (layer.rows != 0 and layer.kind == .notice_row) break layer; + } else return error.NoNoticeRow; + try std.testing.expectEqual(@as(u16, 1), row.viewport.h); + try std.testing.expectEqual(p.view().screen_h - 1, row.viewport.y); + var want: [64]u8 = undefined; + const said = try std.fmt.bufPrint(&want, "\u{2717} @p{d} Wrap: takes on, off", .{pane.serial}); + const grid = s.cells[@as(usize, row.viewport.y) * s.cols ..][0..s.cols]; + var text: std.ArrayList(u8) = .empty; + defer text.deinit(std.testing.allocator); + for (grid) |cell| try text.appendSlice(std.testing.allocator, cell.grapheme()); + try std.testing.expect(std.mem.indexOf(u8, text.items, said) != null); // Msg owns the row itself, so it does not announce over its own text. try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello")); - try std.testing.expectEqualStrings("hello", pane.msg[0..pane.msg_len]); + try std.testing.expectEqualStrings("hello", p.messages.saidBy(pane)); - pane.msg_len = 0; + p.messages.live_len = 0; p.settings.verbose = false; try std.testing.expect(p.executeBuiltinLine(p.view().active, "Wrap")); - try std.testing.expectEqual(@as(u16, 0), pane.msg_len); + try std.testing.expectEqual(@as(usize, 0), p.messages.saidBy(pane).len); } -test "notices stack over the body's top rows without moving them" { - const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 200, .rows = 24 }); +test "the notice row leads with the most important live message, its count and places, and says how many more; with none, where the caret is" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 }); defer p.deinit(); + const pane = try p.setTestFile("one\ntwo\nthree\n"); const id = p.view().active; - const pane = p.panes[id].?; - p.sync(); - var frame = std.heap.ArenaAllocator.init(std.testing.allocator); - defer frame.deinit(); - - const r = p.view().rects[id]; - const top = p.bodyTop(pane, r); - - // 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); - // An overlay, not a reservation: the body still starts where it did. - try std.testing.expectEqual(top, p.bodyTop(pane, r)); - - var seen: usize = 0; - for (p.surface.tagLayers()) |*layer| { - if (layer.rows == 0 or layer.kind != .notice) continue; - try std.testing.expectEqual(@as(u16, 1), layer.viewport.h); - // Sized to its own message, right up against the pane's right edge -- - // not the width of the pane. - try std.testing.expectEqual(r.x + r.w, layer.viewport.x + layer.viewport.w); - try std.testing.expect(layer.viewport.w < r.w - config.GUTTER); - try std.testing.expect(layer.viewport.y == top or layer.viewport.y == top + 1); - try std.testing.expectEqual(pane.notices.left[layer.viewport.y - top], layer.viewport.x); - seen += 1; - } - try std.testing.expectEqual(@as(usize, 2), seen); - // 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; - pane.msg_len = 0; - _ = frame.reset(.retain_capacity); - _ = try p.render(frame.allocator()); - for (p.surface.tagLayers()) |*layer| - try std.testing.expect(layer.rows == 0 or layer.kind != .notice); + p.messages.live_len = 0; + p.messages.len = 0; + pane.body.cur_row = 1; + var buf: [notice_row_cap]u8 = undefined; + var row = noticeRow(p, 60, &buf); + try std.testing.expectEqualStrings("/test.txt:2", row.text[0..row.left]); + try std.testing.expectEqual(@as(usize, 60), panes.File.displayWidth(p.settings.tab, row.text)); + // A notice, then an error and a warning: the error leads, newest first + // within a rank; the others are counted. + _ = say(p, .notice, id, "indexed"); + _ = say(p, .warn, id, "careful"); + _ = say(p, .@"error", id, "broke"); + row = noticeRow(p, 60, &buf); + try std.testing.expectEqualStrings("\u{2717} /test.txt broke", row.text[0..row.left]); + try std.testing.expect(std.mem.endsWith(u8, row.text, "+1 \u{b7} 3 messages \u{b7} SPC h m")); + // A burst of the same: one message, counted; the row keeps its width. + for (0..9) |_| _ = say(p, .@"error", id, "broke"); + row = noticeRow(p, 60, &buf); + try std.testing.expectEqualStrings("\u{2717} /test.txt broke \u{d7}10", row.text[0..row.left]); + try std.testing.expectEqual(@as(usize, 60), panes.File.displayWidth(p.settings.tab, row.text)); + // An error that names places offers the walk, its places as words. + const err = keep(p, .@"error", 0, "@p9 zig build", "exit 1"); + err.places[0] = .{ .line = 25, .col = 12 }; + err.places[0].path.set("core/pick.zig"); + err.places_len = 1; + row = noticeRow(p, 80, &buf); + try std.testing.expectEqualStrings("\u{2717} @p9 zig build exit 1 core/pick.zig:25:12", row.text[0..row.left]); + try std.testing.expect(std.mem.endsWith(u8, row.text, "+1 \u{b7} SPC e walk")); + // Too narrow: the left gives way, the right stays whole. + row = noticeRow(p, 30, &buf); + try std.testing.expect(std.mem.endsWith(u8, row.text, "+1 \u{b7} SPC e walk")); + try std.testing.expect(panes.File.displayWidth(p.settings.tab, row.text) <= 30); + // A question outranks a warning, not an error; it is counted on the right. + _ = keep(p, .question, pane.serial, "/test.txt", "changed on disk"); + row = noticeRow(p, 80, &buf); + try std.testing.expect(std.mem.startsWith(u8, row.text, "\u{2717} @p9")); + try std.testing.expect(std.mem.endsWith(u8, row.text, "+2 \u{b7} 1 question \u{b7} SPC e")); } -test "an idle core wants no wake and a lingering message sleeps to its linger's end" { +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(); while (p.nextEffect()) |_| {} - const frame = pardes.frame_ns; p.advance(1_000_000); + p.messages.live_len = 0; try std.testing.expectEqual(@as(?u64, null), p.nextWake()); - const pane = p.panes[p.view().active].?; - // Shown, a message asks for no wake. + try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 160")); try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg hello")); - try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase); + const said = p.messages.headline().?; + try std.testing.expect(!said.faded(p.clock.now_ns, p.settings.message_linger_ms)); + // The core sleeps to its dimming, not a frame at a time. + const frame = pardes.frame_ns; + const due = said.t + 160 * std.time.ns_per_ms; + const woken = p.nextWake().?; + try std.testing.expect(woken >= due and woken < due + frame); + p.advance(woken); + try std.testing.expect(said.faded(p.clock.now_ns, p.settings.message_linger_ms)); try std.testing.expectEqual(@as(?u64, null), p.nextWake()); - // A key starts the 800 ms linger: the core sleeps to its end, not a - // frame at a time, and the frames it jumps draw nothing. - p.update(.{ .key = .{ .cp = 'x' } }); - try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); - const linger = messageFrames(p.settings.message_linger_ms); - const due = p.clock.stepped_ns + linger * frame; - try std.testing.expectEqual(@as(?u64, due), p.nextWake()); - p.needs_frame = false; - p.advance(due - frame); - try std.testing.expectEqual(@as(?u64, due), p.nextWake()); - try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase); - p.advance(due); - try std.testing.expectEqual(@as(usize, 0), pane.msg_len); + // A warning is bright twice as long; with no linger nothing wakes. + try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 0")); + _ = say(p, .warn, p.view().active, "careful"); try std.testing.expectEqual(@as(?u64, null), p.nextWake()); +} + +test "a compiler's report names its places: each place's words, the first error's rows after it its detail, a relative path the run's directory's" { + var s: Said = .{}; + const rows = [_][]const u8{ + "install", + "+- compile exe pardes Debug native 1 errors", + "core/pick.zig:25:12: error: expected 2 argument(s), found 3", + " const best = rank(q, name, 3) orelse continue;", + " ^~~~", + "core/look.zig:14:5: note: function declared here", + "pub fn rank(q: []const u8, name: []const u8) ?u32 {", + "error: the following command failed with 1 compilation errors:", + }; + try std.testing.expectEqual(@as(usize, 2), readPlaces(&s, "/src/pardes/", &rows)); + try std.testing.expectEqualStrings("/src/pardes/core/pick.zig", s.places[0].path.slice()); + try std.testing.expectEqual(@as(u32, 25), s.places[0].line); + try std.testing.expectEqual(@as(u32, 12), s.places[0].col); + try std.testing.expectEqualStrings("expected 2 argument(s), found 3", s.places[0].text.slice()); + try std.testing.expectEqualStrings("note: function declared here", s.places[1].text.slice()); + try std.testing.expectEqual(@as(u8, 2), s.detail_len); + try std.testing.expectEqualStrings(" const best = rank(q, name, 3) orelse continue;", s.detail[0].slice()); + try std.testing.expectEqualStrings(" ^~~~", s.detail[1].slice()); + // No error among them: no places. + var none: Said = .{}; + try std.testing.expectEqual(@as(usize, 0), readPlaces(&none, "/", &.{ "x.zig:1:1: note: only a note", "grep: nothing" })); +} + +test "a burst of the same message is one message, counted, and moves nothing on the screen" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 20 }); + defer p.deinit(); + const pane = try p.setTestFile("text\n"); + const id = p.view().active; + _ = say(p, .@"error", id, "workspace/didChangeWatchedFiles: 3 files"); + p.sync(); + const rects = p.view().rects; + const tag_rows = pane.tag_rows; + for (0..9) |_| _ = say(p, .@"error", id, "workspace/didChangeWatchedFiles: 3 files"); + p.sync(); + try std.testing.expectEqual(@as(u8, 1), p.messages.live_len); + try std.testing.expectEqual(@as(u16, 10), p.messages.headline().?.n); + try std.testing.expectEqual(rects, p.view().rects); + try std.testing.expectEqual(tag_rows, pane.tag_rows); + var buf: [notice_row_cap]u8 = undefined; + const row = noticeRow(p, 78, &buf); + try std.testing.expect(std.mem.endsWith(u8, row.text[0..row.left], "3 files \u{d7}10")); +} + +test "a file changed on disk under unsaved text asks in its tag and never takes the keyboard: SPC e's keyboard answers, d shows the disk's lines as ghosts, Esc leaves it waiting, B2 on Reload reads it 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\ntwo\nthree\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\ntwo\nthree\n"); + const id = p.view().active; + p.gpa.free(pane.file.?.path); + pane.file.?.path = try p.gpa.dupe(u8, path); + const f = &pane.file.?; + f.saved_hash = panes.File.fileHash(f); + // Unsaved: a line typed at the end. + for ([_]u21{ 'G', 'o', 'f', 'o', 'u', 'r', Key.escape }) |cp| p.update(.{ .key = .{ .cp = cp } }); + try std.testing.expect(f.revision != f.saved_revision); + const disk = "zero\none\ntwo\nthree\n"; + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "c.zig", .data = disk }); + p.update(.{ .file_changed = .{ .pane = .at(id), .bytes = disk } }); + const i = p.messages.waiting(pane) orelse return error.NotAsked; + try std.testing.expectEqual(Kind.question, p.messages.live[i].kind); + // In its tag at rest, its answers offered; its mark `?`. + const prefix = try pardes.tagline.tagPrefix(p, pane); + try std.testing.expect(std.mem.indexOf(u8, prefix, "changed on disk \u{25b8} r Reload k Keep mine d Diff \u{b7} SPC e to answer") != null); + try std.testing.expectEqualStrings("Reload", p.messages.waitingAnswers(pane)[0].word); + // The keyboard is not its: `r` is the body's (helix's replace). + p.update(.{ .key = .{ .cp = 'k' } }); + try std.testing.expect(p.messages.waiting(pane) != null); + // Given the keyboard: `d` shows the disk's lines and keeps asking; Esc + // leaves it waiting. + p.view().answering = pane.serial; + p.update(.{ .key = .{ .cp = 'd' } }); + const asked = &p.messages.live[p.messages.waiting(pane).?]; + try std.testing.expect(asked.open); + try std.testing.expectEqual(@as(u32, 1), asked.places[0].line); + try std.testing.expectEqualStrings("+zero", asked.detail[0].slice()); + try std.testing.expectEqual(pane.serial, p.view().answering); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(@as(u32, 0), p.view().answering); + try std.testing.expect(p.messages.waiting(pane) != null); + // B2 on `Reload` in its tag: read again, the question gone. + try std.testing.expectEqual(@as(?usize, null), pardes.exec.execute(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); +} + +test "SPC e on an error that names places lists them under the pane and lands on the first, on a question gives its tag the keyboard, and on anything else opens the history, the newest first" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile("one\ntwo\nthree\nfour\nfive\n"); + const serial = pane.serial; + p.messages.live_len = 0; + const err = keep(p, .@"error", 0, "@p9 zig build", "exit 1"); + for ([_]u32{ 2, 4 }, 0..) |line, k| { + err.places[k] = .{ .line = line, .col = 1 }; + err.places[k].path.set("/test.txt"); + err.places[k].text.set("bad"); + } + err.places_len = 2; + p.update(.{ .key = .{ .cp = ' ' } }); + p.update(.{ .key = .{ .cp = 'e' } }); + while (p.nextEffect()) |_| {} + try std.testing.expect(p.messages.headline() == null); + const here = p.paneBySerial(serial).?; + const list = p.panes[p.panes[here].?.search_pane orelse return error.NoList].?; + try std.testing.expect(std.mem.indexOf(u8, list.file.?.content, "/test.txt:4:1") != null); + try std.testing.expectEqual(@as(i32, 1), p.panes[here].?.body.cur_row); + // A question: its tag gets the keyboard. + keep(p, .question, serial, "/test.txt", "changed on disk").asks = .disk; + try std.testing.expect(p.executeBuiltinLine(here, "Message")); + try std.testing.expectEqual(serial, p.view().answering); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(@as(u32, 0), p.view().answering); + // Anything else: the history, the newest first, each with its glyph. + p.messages.live_len = 0; + _ = say(p, .notice, here, "older words"); + _ = say(p, .warn, here, "newer words"); + try std.testing.expect(p.executeBuiltinLine(here, "Message")); + const history = for (p.panes) |slot| { + const shown = slot orelse continue; + const f = shown.file orelse continue; + if (std.mem.endsWith(u8, f.path, config.messages_buffer)) break f.content; + } else return error.NoHistory; + const newer = std.mem.indexOf(u8, history, "! ") orelse return error.NoGlyph; + try std.testing.expect(newer < std.mem.indexOf(u8, history, "older words").?); +} - // A long linger ends when it says, jumped in one step, not stretched by - // the cap on catching up with moving frames. - try std.testing.expect(p.executeBuiltinLine(p.view().active, "MessageLinger 5000")); - try std.testing.expect(p.executeBuiltinLine(p.view().active, "Msg again")); - p.update(.{ .key = .{ .cp = 'x' } }); - const long_due = p.clock.stepped_ns + messageFrames(5000) * frame; - try std.testing.expectEqual(@as(?u64, long_due), p.nextWake()); - p.advance(long_due); - try std.testing.expectEqual(@as(usize, 0), pane.msg_len); +test "Esc at rest takes a search's tints first, then the warnings and errors, and only then goes back" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 100, .rows = 30 }); + defer p.deinit(); + const pane = try p.setTestFile("alpha beta alpha\n"); + const id = p.view().active; + p.messages.live_len = 0; + p.update(.{ .key = .{ .cp = '*' } }); + p.update(.{ .key = .{ .cp = 'n' } }); + while (p.nextEffect()) |_| {} + if (pane.places.pattern.len == 0 and pane.places.hits.items.len == 0) return error.NoTints; + _ = say(p, .@"error", id, "broke"); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expect(pane.places.pattern.len == 0 and pane.places.hits.items.len == 0); + try std.testing.expectEqual(@as(u8, 1), p.messages.live_len); + p.update(.{ .key = .{ .cp = Key.escape } }); + try std.testing.expectEqual(@as(u8, 0), p.messages.live_len); + try std.testing.expectEqual(id, p.view().active); } |
