summaryrefslogtreecommitdiff
path: root/src/ninep/ctl.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 13:16:39 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commit961bea06443e25a92e02be58136065c2a1ea84c1 (patch)
tree983433b6ec9b5855530e187ccc2e8a783b8fd42e /src/ninep/ctl.zig
parent80f4398f1fed8d46d73cab8045005c02189b34fc (diff)
downloadpardes-961bea06443e25a92e02be58136065c2a1ea84c1.tar.gz
pardes-961bea06443e25a92e02be58136065c2a1ea84c1.zip
idioms #15, the catch unreachable sites slice b added, re-classified: 29 that a word, a path, an id or a function's text could reach go back to a cut through Kind.Buf (or, at echoCommand's and Repl's writers, a failure handled once at the writer), 95 stay because every argument is an integer, a literal, a comptime word or a cut in the same statement (one added to Ask's arg, ctl's why, choices, word and the ids and fields paneText writes, events' records and Edit's names), each with its reason on its line
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/ninep/ctl.zig')
-rw-r--r--src/ninep/ctl.zig43
1 files changed, 21 insertions, 22 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(&notice, "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)