diff options
Diffstat (limited to 'src/ninep')
| -rw-r--r-- | src/ninep/ctl.zig | 43 | ||||
| -rw-r--r-- | src/ninep/events.zig | 15 | ||||
| -rw-r--r-- | src/ninep/tree.zig | 2 |
3 files changed, 29 insertions, 31 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 08bad9c3..d21e58a3 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -320,7 +320,7 @@ pub fn captured(p: *Pardes, req: Req, id: usize, exec: bool, text: []const u8, i pub fn failedWrite(p: *Pardes, tag: u64) ?Reply { if (p.fs.failure_len == 0) return null; const failure = p.fs.failure[0..p.fs.failure_len]; - return tree.failText(tag, failureErrno(failure), std.fmt.bufPrint(&p.fs.ename, "{s}", .{failure}) catch unreachable); // failure's 256 bytes fit ename's 320 + return tree.failText(tag, failureErrno(failure), std.fmt.bufPrint(&p.fs.ename, "{s}", .{failure}) catch unreachable); // failure is a slice of fs.failure, a [256]u8, into ename's 320 } /// The errno a builtin's failure answers with: ENOENT for what is not @@ -419,7 +419,6 @@ pub const pane_text_cap = 9 * 12 + 2 * 256 + 4 + "notcurrent ".len + 48 + "colla /// window has the keyboard, `current` or `notcurrent` (rio(4), wctl), and /// a REPL's id. pub fn paneText(p: *Pardes, pane: *Pane, buf: *[pane_text_cap]u8) []const u8 { - // unreachable below: pane_text_cap counts every field at its widest. var w = std.Io.Writer.fixed(buf); w.print("{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} ", .{ pane.serial, @@ -430,30 +429,30 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: *[pane_text_cap]u8) []const u8 { @intFromBool(if (pane.file) |f| f.listing != null else false), @intFromBool(pane_files.dirtyOf(pane)), pane.cols, - }) catch unreachable; + }) catch unreachable; // integers: pane_text_cap counts them at 11 each const font = p.settings.font.effective_name.get(); - writeQuoted(&w, if (font.len == 0) "default" else font) catch unreachable; + writeQuoted(&w, if (font.len == 0) "default" else font) catch unreachable; // a Text(255) quoted is 2 * 256 at most, counted // While a column's or the workspace's tag has the keyboard, no pane does. const current = p.panes[p.view().active] == pane and p.view().header == null; const f = pane_files.fileOf(pane); const undo = if (f) |file| file.history.journal.done > 0 else false; const redo = if (f) |file| file.history.journal.done < file.history.journal.steps.items.len else false; - w.print(" {d:>11} {d:>11} {d:>11} {s} ", .{ config.tab_now, @intFromBool(undo), @intFromBool(redo), if (current) "current" else "notcurrent" }) catch unreachable; + w.print(" {d:>11} {d:>11} {d:>11} {s} ", .{ config.tab_now, @intFromBool(undo), @intFromBool(redo), if (current) "current" else "notcurrent" }) catch unreachable; // integers and a literal, counted // A terminal bound as a REPL ends with its id, `python-a`. var idbuf: [48]u8 = undefined; const id = exec_line.replId(&idbuf, pane); - if (id.len > 0) w.print("{s} ", .{id}) catch unreachable; + if (id.len > 0) w.print("{s} ", .{id[0..@min(id.len, idbuf.len)]}) catch unreachable; // 48, counted // Then what its tag does not say: Collapse, and a kind's own fields (a // PDF's PdfFit and PdfTint, in the words they take). - if (pane.collapsed) w.writeAll("collapsed ") catch unreachable; + if (pane.collapsed) w.writeAll("collapsed ") catch unreachable; // a literal, counted if (pane.addon != null) { var fields: [128]u8 = undefined; const kind_fields = pardes.Kind.ctlRead(pane, &fields); - if (kind_fields.len > 0) w.print("{s} ", .{kind_fields}) catch unreachable; + if (kind_fields.len > 0) w.print("{s} ", .{kind_fields[0..@min(kind_fields.len, fields.len)]}) catch unreachable; // 128 and a blank, counted } // Last, the body's mode, which the tag shows as a box: helix's select // is normal mode extending. - w.print("mode:{s} ", .{if (pane.body.mode == .normal and pane.body.select) "select" else @tagName(pane.body.mode)}) catch unreachable; + w.print("mode:{s} ", .{if (pane.body.mode == .normal and pane.body.select) "select" else @tagName(pane.body.mode)}) catch unreachable; // an enum's name, counted return w.buffered(); } @@ -534,10 +533,10 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ? // terminal, the window's own words in a terminal's view) is known, // and says so rather than sound misspelt. if (builtins.absentWhy(word) orelse if (config.Runtime.find(word) != null or std.meta.stringToEnum(Builtin, word) != null) @as([]const u8, "GUI-only") else null) |absent| { - var why: [64]u8 = undefined; + var why: pardes.Kind.Buf(64) = .{}; // EINVAL, a request this build cannot take, in words 9ns reads // as that: `invalid`. - return refuse(p, req, std.fmt.bufPrint(&why, "{s} is {s}, invalid here", .{ word, absent }) catch unreachable, line); // a known word (15 at most) and 17 fit 64 + return refuse(p, req, why.print("{s} is {s}, invalid here", .{ word, absent }), line); } return refuse(p, req, "unknown control message", line); }; @@ -560,8 +559,8 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ? const tail = "; Themes lists all"; var near: [128]u8 = undefined; const room = @import("cloud9").fs.errmax -| (head.len + tail.len + line.len + 3); - var why: [256]u8 = undefined; - return refuse(p, req, std.fmt.bufPrint(&why, head ++ "{s}" ++ tail, .{pardes.colors.themesNear(near[0..@min(room, near.len)], arg)}) catch unreachable, arg); // 128 of names fit + var why: pardes.Kind.Buf(256) = .{}; + return refuse(p, req, why.print(head ++ "{s}" ++ tail, .{pardes.colors.themesNear(near[0..@min(room, near.len)], arg)}), arg); }, .font => config.Runtime.FontSpec.parse(arg) != null, // Bare, it says the width, as from a pane's exec. @@ -1107,9 +1106,9 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply { const path = if (pane_files.fileOf(pane)) |f| f.path else ""; var why_buf: [48]u8 = undefined; const why = if (pardes.Messages.dialReason(failed)) |r| - std.fmt.bufPrint(&why_buf, "dial failed: {s}", .{r}) catch unreachable // dialReason's words are short + std.fmt.bufPrint(&why_buf, "dial failed: {s}", .{r}) catch unreachable // dialReason's literals and 13 fit 48 else if (errno == E.NOENT) "no such file" else "cannot be read"; - return tree.failText(req.tag, errno, std.fmt.bufPrint(&p.fs.ename, "get: {s}: {s}", .{ path[0..@min(path.len, 256)], why }) catch unreachable); // 256 and 48 fit 320 + return tree.failText(req.tag, errno, std.fmt.bufPrint(&p.fs.ename, "get: {s}: {s}", .{ path[0..@min(path.len, 256)], why[0..@min(why.len, 48)] }) catch unreachable); // 256, 48 and 7 fit 320 } }, .lock => { @@ -1127,7 +1126,7 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply { // With a question up, what it offers. var offered: [64]u8 = undefined; if (keys.questionChoices(p, p.paneBySerial(serial).?, &offered)) |choices| - return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "answer takes {s} or -", .{choices}) catch unreachable); // 64 fit 320 + return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "answer takes {s} or -", .{choices[0..@min(choices.len, 64)]}) catch unreachable); // 64 and 18 fit 320 return tree.failText(req.tag, E.INVAL, "answer takes a choice or -"); }, } else if (std.mem.startsWith(u8, line, "answer ") and p.panes[p.paneBySerial(serial).?].?.prompt == .save) { @@ -1149,9 +1148,9 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply { // Only a choice the question offers answers it; anything // else leaves it standing, and says what it takes. if (!std.mem.eql(u8, choice, "-") and (choice.len != 1 or std.mem.indexOfScalar(u8, choices, choice[0]) == null)) { - var why: [96]u8 = undefined; + var why: pardes.Kind.Buf(96) = .{}; // The choice refused is what is quoted: `answer takes a b or - "z"`. - return refuseQuoting(p, req, std.fmt.bufPrint(&why, "answer takes {s} or -", .{choices}) catch unreachable, choice, ""); // 64 fit 96 + return refuseQuoting(p, req, why.print("answer takes {s} or -", .{choices}), choice, ""); } if (apply) _ = keys.answerQuestion(p, id, if (choice[0] == '-') null else choice[0]); } else if (!apply) { @@ -1223,7 +1222,7 @@ fn acmeCtl(p: *Pardes, req: Req, serial: u32, line: []const u8, apply: bool) Acm .menu, .nomenu => "pardes has no menu", else => "a pane is dumped with the session: Dump and DumpDir on /ctl", }; - return .{ .refused = tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s}: {s}", .{ word, why }) catch unreachable) }; // short literals + return .{ .refused = tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s}: {s}", .{ @tagName(w), why }) catch unreachable) }; // an enum's name and a literal fit 320 }, }; if (!apply) return .done; @@ -1257,11 +1256,11 @@ pub fn getRefused(p: *Pardes, pane: *Pane, word: []const u8) ?[]const u8 { tree.events.noteLog(p, .unsaved, pane); const listed = std.fmt.allocPrint(p.gpa, "{s}: Modified\n\n{s} again to discard\n", .{ f.path, word }) catch null; if (listed) |content| panes.Output.openUnsaved(p, id, content); - var notice: [64]u8 = undefined; + var notice: pardes.Kind.Buf(64) = .{}; p.fs.unlogged = true; - p.setMessage(id, std.fmt.bufPrint(¬ice, "1 unsaved pane \u{2014} {s} again to discard", .{word}) catch unreachable); // word is get, Get or e + p.setMessage(id, notice.print("1 unsaved pane \u{2014} {s} again to discard", .{word})); p.fs.unlogged = false; - return std.fmt.bufPrint(&p.fs.ename, "{s}: Modified ({s} again to discard)", .{ f.path[0..@min(f.path.len, 256)], word }) catch unreachable; // 256 fit 320 + return std.fmt.bufPrint(&p.fs.ename, "{s}: Modified ({s} again to discard)", .{ f.path[0..@min(f.path.len, 256)], word[0..@min(word.len, 16)] }) catch unreachable; // 256, 16 and 33 fit 320 } /// acme's `Get file`, and Edit's `e file`: the file at `path` (absolute) diff --git a/src/ninep/events.zig b/src/ninep/events.zig index a25b97b2..be0c4141 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 }) catch unreachable); // name is at most name_buf's + 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 } /// Records `msg <serial> <text>` for what the editor said, `-` for no pane. @@ -189,9 +189,9 @@ pub fn noteMessage(p: *Pardes, serial: u32, said_stamped: []const u8) void { const cut = if (kept.len < said.len) "…" else ""; bootFirst(p); pushCounting(p, (if (serial == 0) - std.fmt.bufPrint(&buf, "msg - {s}{s}\n", .{ kept, cut }) + 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, cut })) catch unreachable, said); // kept is at most cap + 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 } /// `notePath` for an `err` record: the same one again straight after is @@ -199,7 +199,7 @@ pub fn noteMessage(p: *Pardes, serial: u32, said_stamped: []const u8) void { pub fn noteErrCounted(p: *Pardes, text: []const u8) void { bootFirst(p); var buf: [pardes.memory.limits.host_path_cap + 16]u8 = undefined; - pushCounting(p, std.fmt.bufPrint(&buf, "err {s}\n", .{text[0..@min(text.len, buf.len - 16)]}) catch unreachable, text); + pushCounting(p, std.fmt.bufPrint(&buf, "err {s}\n", .{text[0..@min(text.len, buf.len - 16)]}) catch unreachable, text); // buf.len - 16 and 5 fit buf.len } /// Records `<what> <path>`: `dump <path>` when a Dump is written, @@ -207,8 +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; - // unreachable: a record's word is a short literal, and the path is cut to fit. - pushLog(p, std.fmt.bufPrint(&buf, "{s} {s}\n", .{ what, path[0..@min(path.len, buf.len - 16)] }) catch unreachable); + 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 } /// Records `err <serial|-> <file>: <why>` for a write that was refused or @@ -250,13 +249,13 @@ pub fn noteError(p: *Pardes, req: Req, reply: Reply) void { }, }; } - var buf: [256]u8 = undefined; + var buf: [288]u8 = undefined; // A reason that names its file already (`look: no space...` from a // look) is not prefixed twice: `err 3 look: no space...`. 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, file, kept, if (kept.len < reason.len) "…" else "" }) catch unreachable; // 10 + 32 + 200 + 11 fit 256 + 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 for (record[0 .. record.len - 1]) |*c| if (c.* < ' ') { c.* = ' '; }; diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index 2117916d..fde0054f 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -838,7 +838,7 @@ fn open(p: *Pardes, req: Req, target: Target) Reply { // pane it made, so reading it twice answers the same one and // closing it leaves the pane alone. .new => { - const slot = p.freeSlot() orelse return failText(req.tag, E.NOSPC, std.fmt.bufPrint(&p.fs.ename, "pane/new: " ++ pardes.Messages.no_pane_slots, .{pardes.MAX_PANES}) catch unreachable); // short + const slot = p.freeSlot() orelse return failText(req.tag, E.NOSPC, std.fmt.bufPrint(&p.fs.ename, "pane/new: " ++ pardes.Messages.no_pane_slots, .{pardes.MAX_PANES}) catch unreachable); // a literal and an integer fit 320 p.fs.no_pane_slot = false; // Refused, the open's err is the one record of it (the // one rule): no msg besides. |
