diff options
Diffstat (limited to 'src/ninep/events.zig')
| -rw-r--r-- | src/ninep/events.zig | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/ninep/events.zig b/src/ninep/events.zig index be0c4141..b00df909 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -174,7 +174,7 @@ pub fn noteLogAs(p: *Pardes, kind: LogKind, pane: *Pane, path: []const u8) void var name_buf: [4 * 4096]u8 = undefined; // As /index shows it: a newline in the name is `\n`. const name = shown(path, &name_buf); - pushLog(p, std.fmt.bufPrint(&buf, "{s} {d} {s}\n", .{ @tagName(kind), pane.serial, name[0..@min(name.len, name_buf.len)] }) catch unreachable); // an enum's name, a u32 and name_buf's 4 * 4096 fit 64 more + pushLog(p, std.fmt.bufPrint(&buf, "{s} {d} {s}\n", .{ @tagName(kind), pane.serial, name[0..@min(name.len, name_buf.len)] }) catch return); // no record rather than one cut short } /// Records `msg <serial> <text>` for what the editor said, `-` for no pane. @@ -191,7 +191,7 @@ pub fn noteMessage(p: *Pardes, serial: u32, said_stamped: []const u8) void { pushCounting(p, (if (serial == 0) std.fmt.bufPrint(&buf, "msg - {s}{s}\n", .{ kept[0..@min(kept.len, pardes.Messages.LoggedMessage.cap)], cut }) else - std.fmt.bufPrint(&buf, "msg {d} {s}{s}\n", .{ serial, kept[0..@min(kept.len, pardes.Messages.LoggedMessage.cap)], cut })) catch unreachable, said); // a u32, cap and 9 fit cap + 32 + std.fmt.bufPrint(&buf, "msg {d} {s}{s}\n", .{ serial, kept[0..@min(kept.len, pardes.Messages.LoggedMessage.cap)], cut })) catch return, said); // no record rather than one cut short } /// `notePath` for an `err` record: the same one again straight after is @@ -207,7 +207,7 @@ pub fn noteErrCounted(p: *Pardes, text: []const u8) void { pub fn notePath(p: *Pardes, what: []const u8, path: []const u8) void { bootFirst(p); var buf: [pardes.memory.limits.host_path_cap + 16]u8 = undefined; - pushLog(p, std.fmt.bufPrint(&buf, "{s} {s}\n", .{ what[0..@min(what.len, 14)], path[0..@min(path.len, buf.len - 16)] }) catch unreachable); // 14, buf.len - 16 and 2 fit buf.len + pushLog(p, std.fmt.bufPrint(&buf, "{s} {s}\n", .{ what[0..@min(what.len, 14)], path[0..@min(path.len, buf.len - 16)] }) catch return); // no record rather than one cut short } /// Records `err <serial|-> <file>: <why>` for a write that was refused or @@ -217,7 +217,7 @@ pub fn notePath(p: *Pardes, what: []const u8, path: []const u8) void { /// nothing: a per-pane readable error file would be a second. pub fn noteError(p: *Pardes, req: Req, reply: Reply) void { const why = if (reply.ename.len > 0) reply.ename else cloud9.fs.errString(reply.errno); - var name: [32]u8 = undefined; + var name: pardes.Kind.Buf(32) = .{}; var serial: []const u8 = "-"; var file: []const u8 = "os"; if (req.node & tree.sources.archive_node != 0) file = "src"; @@ -228,17 +228,17 @@ pub fn noteError(p: *Pardes, req: Req, reply: Reply) void { // The root's exec or look ran at the keyboard's pane: its // failure is that pane's, as a click there would be. if ((f == .exec or f == .look) and p.fs.ran_at != 0) - serial = std.fmt.bufPrint(&name, "{d}", .{p.fs.ran_at}) catch unreachable; // a u32 fits 32 + serial = name.print("{d}", .{p.fs.ran_at}); }, .col => |c| { serial = "-"; - file = (if (c.file == .dir) - std.fmt.bufPrint(&name, "col/{d}", .{c.serial}) + file = if (c.file == .dir) + name.print("col/{d}", .{c.serial}) else - std.fmt.bufPrint(&name, "col/{d}/{s}", .{ c.serial, @tagName(c.file) })) catch unreachable; // a u32 and a file's name fit 32 + name.print("col/{d}/{s}", .{ c.serial, @tagName(c.file) }); }, .pane => |pt| { - serial = std.fmt.bufPrint(&name, "{d}", .{pt.serial}) catch unreachable; // a u32 fits 32 + serial = name.print("{d}", .{pt.serial}); file = switch (pt.file) { .pty_ctl => "pty/ctl", .pty_status => "pty/status", @@ -255,7 +255,7 @@ pub fn noteError(p: *Pardes, req: Req, reply: Reply) void { const reason = if (why.len > file.len + 2 and std.ascii.startsWithIgnoreCase(why, file) and std.mem.startsWith(u8, why[file.len..], ": ")) why[file.len + 2 ..] else why; // A long reason is cut between words, with an ellipsis, never mid-word. const kept = pardes.Messages.clip(reason, 200); - const record = std.fmt.bufPrint(&buf, "err {s} {s}: {s}{s}\n", .{ serial[0..@min(serial.len, 32)], file[0..@min(file.len, 32)], kept[0..@min(kept.len, 200)], if (kept.len < reason.len) "…" else "" }) catch unreachable; // 32 + 32 + 200 + 11 fit 288 + const record = std.fmt.bufPrint(&buf, "err {s} {s}: {s}{s}\n", .{ serial[0..@min(serial.len, 32)], file[0..@min(file.len, 32)], kept[0..@min(kept.len, 200)], if (kept.len < reason.len) "…" else "" }) catch return; // no record rather than one cut short for (record[0 .. record.len - 1]) |*c| if (c.* < ' ') { c.* = ' '; }; |
