diff options
Diffstat (limited to 'src/Messages.zig')
| -rw-r--r-- | src/Messages.zig | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/Messages.zig b/src/Messages.zig index 7342f726..7dcb22ed 100644 --- a/src/Messages.zig +++ b/src/Messages.zig @@ -51,13 +51,13 @@ pub const LoggedMessage = struct { fn leaderText(p: *const Pardes, buf: *[16]u8) []const u8 { buf.* = @splat(' '); @memcpy(buf[0..3], "SPC"); - var at: usize = 3; + var end: usize = 3; for (p.leader_keys[0..p.leader_n]) |ch| { - if (at + 2 > buf.len) break; - buf[at + 1] = ch; - at += 2; + if (end + 2 > buf.len) break; + buf[end + 1] = ch; + end += 2; } - return buf[0..at]; + return buf[0..end]; } /// How wide a notice chip is, in grid columns: its own text plus a blank @@ -437,7 +437,7 @@ fn logMessage(p: *Pardes, id: usize, text: []const u8) void { } /// The log oldest-first, which is reading order. -pub fn messageLog(m: *const Messages, i: usize) ?*const LoggedMessage { +pub fn at(m: *const Messages, i: usize) ?*const LoggedMessage { if (i >= m.len) return null; const first = (m.head + limits.message_log - m.len) % limits.message_log; return &m.log[(first + i) % limits.message_log]; @@ -503,18 +503,14 @@ pub fn clip(text: []const u8, max: usize) []const u8 { /// reportError with the words already chosen. pub fn reportFailure(p: *Pardes, id: usize, text: []const u8) void { p.fs.failures +%= 1; - // A builtin a ctl write runs: its first error is also the write's, cut - // between words. + // A builtin a ctl write runs: its first error is also the write's, its + // path shortened in the middle if it must be, never its reason. const failing_write = p.fs.no_prompt or p.fs.capturing or p.fs.write_waits; if (failing_write and p.fs.failure_len == 0) { - const kept = if (text.len > p.fs.failure.len) clip(text, p.fs.failure.len - 3) else text; + var room: @TypeOf(p.fs.failure) = undefined; + const kept = pardes.ctlfs.fitErr(text, &room); @memcpy(p.fs.failure[0..kept.len], kept); - var n = kept.len; - if (kept.len < text.len) { - @memcpy(p.fs.failure[n..][0..3], "..."); - n += 3; - } - p.fs.failure_len = @intCast(n); + p.fs.failure_len = @intCast(kept.len); } // The write fails with it, and its err record says it: no msg for it, // so the same failure again is the same record again, counted @@ -584,13 +580,13 @@ test "the message log keeps what the row forgets, and collapses repeats" { setMessage(p, 0, "save: AccessDenied"); try std.testing.expectEqual(@as(usize, 2), p.messages.len); - const first = p.messages.messageLog(0).?; + const first = p.messages.at(0).?; try std.testing.expectEqual(@as(u16, 2), first.repeats); // ...and the NEWEST wording is what survives, so the row carries the last // time it happened rather than the first. try std.testing.expectEqualStrings("14:32:09 saved /x.zig", first.slice()); - try std.testing.expectEqualStrings("save: AccessDenied", p.messages.messageLog(1).?.slice()); - try std.testing.expect(p.messages.messageLog(2) == null); + try std.testing.expectEqualStrings("save: AccessDenied", p.messages.at(1).?.slice()); + try std.testing.expect(p.messages.at(2) == null); // The same text from a DIFFERENT pane is a different event: one pane's // failure must not be recorded as another's. @@ -598,7 +594,7 @@ test "the message log keeps what the row forgets, and collapses repeats" { const other = p.active; setMessage(p, other, "save: AccessDenied"); try std.testing.expectEqual(@as(usize, 3), p.messages.len); - try std.testing.expectEqual(p.panes[other].?.serial, p.messages.messageLog(2).?.serial); + try std.testing.expectEqual(p.panes[other].?.serial, p.messages.at(2).?.serial); // Progress is NOT logged: it arrives several times a second for a whole // index and would push everything else out (`setStatus`). @@ -611,10 +607,10 @@ test "the message log keeps what the row forgets, and collapses repeats" { setMessage(p, 0, std.fmt.bufPrint(&buf, "line {d}", .{i}) catch unreachable); } try std.testing.expectEqual(@as(usize, limits.message_log), p.messages.len); - try std.testing.expectEqualStrings("line 5", p.messages.messageLog(0).?.slice()); + try std.testing.expectEqualStrings("line 5", p.messages.at(0).?.slice()); var last_buf: [32]u8 = undefined; const want_last = std.fmt.bufPrint(&last_buf, "line {d}", .{limits.message_log + 4}) catch unreachable; - try std.testing.expectEqualStrings(want_last, p.messages.messageLog(limits.message_log - 1).?.slice()); + 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" { |
