diff options
Diffstat (limited to 'src/message.zig')
| -rw-r--r-- | src/message.zig | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/message.zig b/src/message.zig index 0935ce96..0855c448 100644 --- a/src/message.zig +++ b/src/message.zig @@ -43,6 +43,25 @@ extern "c" fn localtime_r(timep: *const libc.time_t, result: *Tm) ?*Tm; /// clock cannot live in a golden — but a message that vanished under the /// harness could not be pinned at all, so the row still renders, still says /// what happened, and still occupies the same columns. +/// The stamped text WITHOUT its clock — what two of these rows have in common +/// when they say the same thing at different times. +/// +/// The message log de-duplicates on this rather than on the whole row, because +/// the clock makes every host message unique by construction: `saved x` at +/// 14:32:07 and at 14:32:09 are different strings, so a watched file rebuilt +/// in a loop filled the ring with identical-looking rows, each counted once. +/// That is exactly the case the de-duplication exists for. +pub fn body(text: []const u8) []const u8 { + // `HH:MM:SS ` — ten bytes, digits or the `--:--:--` the harness blanks + // them to. Anything else is a message that was never stamped. + if (text.len < 10) return text; + if (text[2] != ':' or text[5] != ':' or text[8] != ' ' or text[9] != ' ') return text; + for ([_]usize{ 0, 1, 3, 4, 6, 7 }) |i| { + if (!std.ascii.isDigit(text[i]) and text[i] != '-') return text; + } + return text[10..]; +} + pub fn stamp(buf: []u8, verb: []const u8, subject: []const u8) []const u8 { var clock: [8]u8 = "--:--:--".*; const notime = if (libc.getenv("PARDES_NOTIME")) |v| std.mem.span(v).len != 0 else false; |
