summaryrefslogtreecommitdiff
path: root/src/ninep/ctl.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 12:40:11 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commit36a51ddc67d0beb7d9851fb2425cf780a47fed36 (patch)
treed534d3151d836ea7a275e9f118a89f2bbc0d0448 /src/ninep/ctl.zig
parent4917ae452a15ff4f32d97d215a99fdcfaab29d61 (diff)
downloadpardes-36a51ddc67d0beb7d9851fb2425cf780a47fed36.tar.gz
pardes-36a51ddc67d0beb7d9851fb2425cf780a47fed36.zip
idioms #10, the 9P tree: every bufPrint that fell back to "" or a placeholder is proven to fit (catch unreachable, its why) or cut its argument to fit, /status, /listeners and the 9P reads that staged on gpa answer ENOMEM rather than read short, acme's pane ctl words and pty's files and signals are stringToEnum switches, a dirent's head and name are staged together or not at all, a repeated log record too long to count is pushed as its own line rather than dropped, and daemonList's set is named
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.zig237
1 files changed, 116 insertions, 121 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 53128c5e..08bad9c3 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 failure);
+ return tree.failText(tag, failureErrno(failure), std.fmt.bufPrint(&p.fs.ename, "{s}", .{failure}) catch unreachable); // failure's 256 bytes fit ename's 320
}
/// The errno a builtin's failure answers with: ENOENT for what is not
@@ -382,16 +382,16 @@ pub fn readResults(p: *Pardes, req: Req) Reply {
// ---- /status ----
/// /status's text, in the step's scratch.
-pub fn statusText(p: *Pardes) []const u8 {
+pub fn statusText(p: *Pardes) std.Io.Writer.Error![]const u8 {
var w: std.Io.Writer.Allocating = .init(p.scratch.allocator());
var count: usize = 0;
for (p.panes) |slot| count += @intFromBool(slot != null);
const pid: u32 = @intCast(std.c.getpid());
- w.writer.print("pid {d}\nversion {s}\npanes {d}\n", .{ pid, pardes.version, count }) catch {};
+ try w.writer.print("pid {d}\nversion {s}\npanes {d}\n", .{ pid, pardes.version, count });
// Whether the pointer is over this window: what a grip let go past
// another window's edge asks of every window, to find the one it was
// let go over (Handover.zig), where no window may know another's place.
- if (p.view().frontend.windowed) w.writer.print("pointer {s}\n", .{if (p.view().pointer_inside) "in" else "out"}) catch {};
+ if (p.view().frontend.windowed) try w.writer.print("pointer {s}\n", .{if (p.view().pointer_inside) "in" else "out"});
return w.written();
}
@@ -418,7 +418,8 @@ pub const pane_text_cap = 9 * 12 + 2 * 256 + 4 + "notcurrent ".len + 48 + "colla
/// whether Redo has one. Then pardes's own: rio's word for whether the
/// window has the keyboard, `current` or `notcurrent` (rio(4), wctl), and
/// a REPL's id.
-pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 {
+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,
@@ -429,30 +430,30 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 {
@intFromBool(if (pane.file) |f| f.listing != null else false),
@intFromBool(pane_files.dirtyOf(pane)),
pane.cols,
- }) catch return w.buffered();
+ }) catch unreachable;
const font = p.settings.font.effective_name.get();
- writeQuoted(&w, if (font.len == 0) "default" else font) catch return w.buffered();
+ writeQuoted(&w, if (font.len == 0) "default" else font) catch unreachable;
// 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 {};
+ w.print(" {d:>11} {d:>11} {d:>11} {s} ", .{ config.tab_now, @intFromBool(undo), @intFromBool(redo), if (current) "current" else "notcurrent" }) catch unreachable;
// 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 {};
+ if (id.len > 0) w.print("{s} ", .{id}) catch unreachable;
// 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 {};
+ if (pane.collapsed) w.writeAll("collapsed ") catch unreachable;
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 {};
+ if (kind_fields.len > 0) w.print("{s} ", .{kind_fields}) catch unreachable;
}
// 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 {};
+ w.print("mode:{s} ", .{if (pane.body.mode == .normal and pane.body.select) "select" else @tagName(pane.body.mode)}) catch unreachable;
return w.buffered();
}
@@ -521,7 +522,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
// acme's words: checked as the pardes word they run as, or refused.
const word = for (pardes.exec.acme_words) |w| {
if (!std.mem.eql(u8, typed, w.acme)) continue;
- const now = w.pardes orelse return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s} is not a pardes builtin{s}", .{ w.acme, w.hint }) catch "invalid: an acme word pardes has not");
+ const now = w.pardes orelse return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s} is not a pardes builtin{s}", .{ w.acme, w.hint }) catch unreachable); // acme_words holds short literals
break now;
} else typed;
const arg = if (sp) |s| std.mem.trim(u8, line[s + 1 ..], " \t") else "";
@@ -536,7 +537,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
var why: [64]u8 = undefined;
// 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 "GUI-only, invalid here", line);
+ 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, "unknown control message", line);
};
@@ -560,7 +561,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
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 "bad value in control message", arg);
+ 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
},
.font => config.Runtime.FontSpec.parse(arg) != null,
// Bare, it says the width, as from a pane's exec.
@@ -572,11 +573,11 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
},
};
if (takes) return null;
- var why: [160]u8 = undefined;
+ var why: pardes.Kind.Buf(160) = .{};
// The offending word is the value: quoted, so two bad values read,
// and log, as two.
return refuseQuoting(p, req, if (config.Runtime.takes(setting.action)) |values|
- std.fmt.bufPrint(&why, "bad value in control message; takes {s}", .{values}) catch "bad value in control message"
+ why.print("bad value in control message; takes {s}", .{values})
else
"bad value in control message", arg, "");
}
@@ -643,7 +644,7 @@ fn writeSettingsFor(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer, cap
}
/// The root ctl's text (`writeSettings`), in the step's scratch.
-pub fn settingsText(p: *Pardes) ![]const u8 {
+pub fn settingsText(p: *Pardes) std.Io.Writer.Error![]const u8 {
var text: std.Io.Writer.Allocating = .init(p.scratch.allocator());
try writeSettings(p, &text.writer);
return text.written();
@@ -667,23 +668,23 @@ pub fn writePager(p: *Pardes, req: Req) Reply {
// directory it is, as any other pane's name is.
var home_buf: [4096]u8 = undefined;
const typed = pardes.filesystem.expandHome(std.mem.trim(u8, line, " \t"), &home_buf);
- const dir = if (typed.len > 0 and typed[0] == '/') std.fs.path.resolvePosix(p.scratch.allocator(), &.{typed}) catch typed else typed;
+ const dir = if (typed.len > 0 and typed[0] == '/') std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{typed}) catch typed else typed;
// A directory that is there, or none (the session's): never a +Pager
// named into one missing, nor a relative one quietly taken for none.
if (dir.len > 0 and dir[0] != '/') {
var shown: [256]u8 = undefined;
- return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "pager: invalid directory \"{s}\": must be absolute", .{blanked(dir[0..@min(dir.len, shown.len)], &shown)}) catch "pager: invalid directory: must be absolute");
+ return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "pager: invalid directory \"{s}\": must be absolute", .{blanked(dir[0..@min(dir.len, shown.len)], &shown)}) catch unreachable); // 256 fit 320
}
if (dir.len > 0) if (pardes.filesystem.localPath(dir)) |local| {
// A file there is no directory, ENOTDIR; nothing there, ENOENT.
if (exec_line.kindOf(local) != .directory) {
if (exec_line.kindOf(local) != null)
- return tree.failText(req.tag, E.NOTDIR, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: not a directory", .{dir[0..@min(dir.len, 256)]}) catch "pager: not a directory");
- return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch "pager: no such directory");
+ return tree.failText(req.tag, E.NOTDIR, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: not a directory", .{dir[0..@min(dir.len, 256)]}) catch unreachable); // 256 fit 320
+ return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch unreachable); // 256 fit 320
}
// Nor one that may not be written, as a file's name there is refused.
if (pardes.filesystem.deniedAbove(local))
- return tree.failText(req.tag, E.PERM, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: permission denied", .{dir[0..@min(dir.len, 256)]}) catch "pager: permission denied");
+ return tree.failText(req.tag, E.PERM, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: permission denied", .{dir[0..@min(dir.len, 256)]}) catch unreachable); // 256 fit 320
};
const id = pardes.panes.Output.openPager(p, p.view().active, dir) catch |err|
return tree.failText(req.tag, if (err == error.NoPaneRoom or err == error.NoPaneSlots) E.NOSPC else E.IO, switch (err) {
@@ -910,7 +911,7 @@ fn writeCommands(p: *const Pardes, w: *std.Io.Writer) !void {
}
/// /commands' text (`writeCommands`), in the step's scratch.
-pub fn commandsText(p: *Pardes) ![]const u8 {
+pub fn commandsText(p: *Pardes) std.Io.Writer.Error![]const u8 {
var text: std.Io.Writer.Allocating = .init(p.scratch.allocator());
try writeCommands(p, &text.writer);
return text.written();
@@ -1091,39 +1092,44 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply {
.refused => |r| return r,
.builtin => |word| line = word,
}
- if (std.mem.eql(u8, line, "get")) {
- if (!apply) continue;
- if (@import("../edit_cmd.zig").busyOn(p, p.paneBySerial(serial).?)) return tree.failText(req.tag, E.BUSY, "get: " ++ @import("../edit_cmd.zig").e_busy);
- // It ran and was refused: its words (in ename), not the line
- // quoted, as a builtin's refusal (Save's) says it.
- if (getRefused(p, pane, "get")) |said| return tree.failText(req.tag, E.IO, said);
- var failed: anyerror = error.Unexpected;
- const errno = get(p, pane, &failed);
- // Naming the path, in words 9ns reads as the errno; a peer
- // out of reach as a look or a Save says it.
- if (errno != 0) {
- 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 "dial failed"
- 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 "get: no such file");
- }
- } else if (std.mem.eql(u8, line, "lock")) {
- if (mine == null) return tree.failText(req.tag, E.INVAL, tree.e_bad_ctl);
- if (other) return tree.failText(req.tag, E.BUSY, e_locked);
- held = true;
- if (apply) pane.fs.lock = mine;
- } else if (std.mem.eql(u8, line, "unlock")) {
- if (!held) return tree.failText(req.tag, E.INVAL, e_not_locked);
- held = false;
- if (apply) pane.fs.lock = null;
- } else if (std.mem.eql(u8, line, "answer")) {
- // 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 "answer takes a choice or -");
- return tree.failText(req.tag, E.INVAL, "answer takes a choice or -");
+ if (std.meta.stringToEnum(enum { get, lock, unlock, answer }, line)) |word| switch (word) {
+ .get => {
+ if (!apply) continue;
+ if (@import("../edit_cmd.zig").busyOn(p, p.paneBySerial(serial).?)) return tree.failText(req.tag, E.BUSY, "get: " ++ @import("../edit_cmd.zig").e_busy);
+ // It ran and was refused: its words (in ename), not the line
+ // quoted, as a builtin's refusal (Save's) says it.
+ if (getRefused(p, pane, "get")) |said| return tree.failText(req.tag, E.IO, said);
+ var failed: anyerror = error.Unexpected;
+ const errno = get(p, pane, &failed);
+ // Naming the path, in words 9ns reads as the errno; a peer
+ // out of reach as a look or a Save says it.
+ if (errno != 0) {
+ 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
+ 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
+ }
+ },
+ .lock => {
+ if (mine == null) return tree.failText(req.tag, E.INVAL, tree.e_bad_ctl);
+ if (other) return tree.failText(req.tag, E.BUSY, e_locked);
+ held = true;
+ if (apply) pane.fs.lock = mine;
+ },
+ .unlock => {
+ if (!held) return tree.failText(req.tag, E.INVAL, e_not_locked);
+ held = false;
+ if (apply) pane.fs.lock = null;
+ },
+ .answer => {
+ // 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, "answer takes a choice or -");
+ },
} else if (std.mem.startsWith(u8, line, "answer ") and p.panes[p.paneBySerial(serial).?].?.prompt == .save) {
// Save's path, asked over 9P (`ask <serial> save path`).
if (!apply) continue;
@@ -1131,7 +1137,7 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply {
const asked = p.panes[id].?;
const path = std.mem.trim(u8, line["answer ".len..], " ");
var rec: [300]u8 = undefined;
- pardes.ctlfs.events.notePath(p, "answer", std.fmt.bufPrint(&rec, "{d} {s}", .{ serial, path[0..@min(path.len, 256)] }) catch "");
+ pardes.ctlfs.events.notePath(p, "answer", std.fmt.bufPrint(&rec, "{d} {s}", .{ serial, path[0..@min(path.len, 256)] }) catch unreachable); // a u32 and 256 fit 300
if (!std.mem.eql(u8, path, "-")) exec_line.saveTo(p, id, path);
asked.closePrompt();
} else if (std.mem.startsWith(u8, line, "answer ")) {
@@ -1145,7 +1151,7 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply {
if (!std.mem.eql(u8, choice, "-") and (choice.len != 1 or std.mem.indexOfScalar(u8, choices, choice[0]) == null)) {
var why: [96]u8 = undefined;
// 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 "answer takes a choice or -", choice, "");
+ return refuseQuoting(p, req, std.fmt.bufPrint(&why, "answer takes {s} or -", .{choices}) catch unreachable, choice, ""); // 64 fit 96
}
if (apply) _ = keys.answerQuestion(p, id, if (choice[0] == '-') null else choice[0]);
} else if (!apply) {
@@ -1175,65 +1181,54 @@ fn acmeCtl(p: *Pardes, req: Req, serial: u32, line: []const u8, apply: bool) Acm
const File = tree.PaneFile;
// A word written to one of the pane's own files, as acme's is to its.
const Into = struct { file: File, data: []const u8 };
- // `name` takes all after its one blank, as the name file takes what is
- // written. A second blank after the word is refused, not taken as the
- // name's first byte: a line's words are split at blanks.
- if (std.mem.eql(u8, word, "name") and rest.len > 0 and line[word.len + 1] == ' ')
- return .{ .refused = tree.failText(req.tag, E.INVAL, "bad character in file name: a blank at its start") };
- // `name` with nothing after it names nothing: said so, not an unknown word.
- if (std.mem.eql(u8, word, "name") and rest.len == 0)
- return .{ .refused = tree.failText(req.tag, E.INVAL, "invalid file name: name takes the name, and there is none") };
- const into: ?Into = if (std.mem.eql(u8, word, "name") and rest.len > 0)
- .{ .file = .name, .data = line[word.len + 1 ..] }
- else if (std.mem.eql(u8, line, "clean"))
- .{ .file = .dirty, .data = "0" }
- else if (std.mem.eql(u8, line, "dirty"))
- .{ .file = .dirty, .data = "1" }
- else if (std.mem.eql(u8, line, "mark"))
- .{ .file = .mark, .data = "1" }
- else if (std.mem.eql(u8, line, "nomark"))
- .{ .file = .mark, .data = "0" }
- else
- null;
- if (into) |w| {
- if (!apply) return .done;
- const r = pane_files.write(p, .{ .tag = req.tag, .op = .write, .node = tree.Node.of(serial, w.file), .data = w.data }, id, pane, w.file);
- return if (r.status == .err) .{ .refused = r } else .done;
+ const Word = enum { name, clean, dirty, mark, nomark, put, del, delete, @"dot=addr", @"addr=dot", @"limit=addr", show, cleartag, dump, dumpdir, font, menu, nomenu };
+ const w = std.meta.stringToEnum(Word, word) orelse return .no;
+ // name, dump, dumpdir and font take what follows them; the rest are a line alone.
+ switch (w) {
+ .name, .dump, .dumpdir, .font => {},
+ else => if (word.len != line.len) return .no,
}
- if (std.mem.eql(u8, line, "put")) return .{ .builtin = "Save" };
- if (std.mem.eql(u8, line, "del")) return .{ .builtin = "Del" };
- if (std.mem.eql(u8, line, "delete")) return .{ .builtin = "Delete" };
const pf = &pane.fs;
- if (std.mem.eql(u8, line, "dot=addr")) {
- if (apply) pane_files.setDot(pane, pf.addr);
- return .done;
- }
- if (std.mem.eql(u8, line, "addr=dot")) {
- if (apply) pf.addr = pane_files.dotOf(pane);
- return .done;
- }
- if (std.mem.eql(u8, line, "limit=addr")) {
- if (apply) pf.limit = pf.addr;
- return .done;
- }
- if (std.mem.eql(u8, line, "show")) {
- if (apply) pane_files.showOffset(pane, pane_files.dotOf(pane).q0);
- return .done;
- }
- if (std.mem.eql(u8, line, "cleartag")) {
- if (apply) _ = pane_files.truncate(p, pane, .tag);
- return .done;
- }
- const none: ?[]const u8 = if (std.mem.eql(u8, word, "dump") or std.mem.eql(u8, word, "dumpdir"))
- "a pane is dumped with the session: Dump and DumpDir on /ctl"
- else if (std.mem.eql(u8, word, "font"))
- "the font is the session's: Font on /ctl"
- else if (std.mem.eql(u8, line, "menu") or std.mem.eql(u8, line, "nomenu"))
- "pardes has no menu"
- else
- null;
- if (none) |why| return .{ .refused = tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s}: {s}", .{ word, why }) catch "invalid: acme's ctl word") };
- return .no;
+ const into: Into = switch (w) {
+ // `name` takes all after its one blank, as the name file takes what
+ // is written; with nothing after it, it names nothing (said so, not
+ // an unknown word), and a second blank is refused, not taken as the
+ // name's first byte: a line's words are split at blanks.
+ .name => if (rest.len == 0)
+ return .{ .refused = tree.failText(req.tag, E.INVAL, "invalid file name: name takes the name, and there is none") }
+ else if (line[word.len + 1] == ' ')
+ return .{ .refused = tree.failText(req.tag, E.INVAL, "bad character in file name: a blank at its start") }
+ else
+ .{ .file = .name, .data = line[word.len + 1 ..] },
+ .clean => .{ .file = .dirty, .data = "0" },
+ .dirty => .{ .file = .dirty, .data = "1" },
+ .mark => .{ .file = .mark, .data = "1" },
+ .nomark => .{ .file = .mark, .data = "0" },
+ .put => return .{ .builtin = "Save" },
+ .del => return .{ .builtin = "Del" },
+ .delete => return .{ .builtin = "Delete" },
+ .@"dot=addr", .@"addr=dot", .@"limit=addr", .show, .cleartag => {
+ if (apply) switch (w) {
+ .@"dot=addr" => pane_files.setDot(pane, pf.addr),
+ .@"addr=dot" => pf.addr = pane_files.dotOf(pane),
+ .@"limit=addr" => pf.limit = pf.addr,
+ .show => pane_files.showOffset(pane, pane_files.dotOf(pane).q0),
+ else => _ = pane_files.truncate(p, pane, .tag),
+ };
+ return .done;
+ },
+ .dump, .dumpdir, .font, .menu, .nomenu => {
+ const why = switch (w) {
+ .font => "the font is the session's: Font on /ctl",
+ .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
+ },
+ };
+ if (!apply) return .done;
+ const r = pane_files.write(p, .{ .tag = req.tag, .op = .write, .node = tree.Node.of(serial, into.file), .data = into.data }, id, pane, into.file);
+ return if (r.status == .err) .{ .refused = r } else .done;
}
const e_not_locked = "pane not locked by this open";
@@ -1264,9 +1259,9 @@ pub fn getRefused(p: *Pardes, pane: *Pane, word: []const u8) ?[]const u8 {
if (listed) |content| panes.Output.openUnsaved(p, id, content);
var notice: [64]u8 = undefined;
p.fs.unlogged = true;
- p.setMessage(id, std.fmt.bufPrint(&notice, "1 unsaved pane \u{2014} {s} again to discard", .{word}) catch "1 unsaved pane");
+ 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.fs.unlogged = false;
- return std.fmt.bufPrint(&p.fs.ename, "{s}: Modified ({s} again to discard)", .{ f.path, word }) catch "Modified (get again to discard)";
+ 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
}
/// acme's `Get file`, and Edit's `e file`: the file at `path` (absolute)
@@ -1331,7 +1326,7 @@ pub fn get(p: *Pardes, pane: *Pane, failed: *anyerror) u16 {
f.disk_gone = false;
if (discarded) {
var rec: [32]u8 = undefined;
- pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d} reloaded", .{pane.serial}) catch "");
+ pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d} reloaded", .{pane.serial}) catch unreachable); // a u32 fits 32
}
return 0;
}
@@ -1423,7 +1418,7 @@ test "Zerox twins: a Save from one, performed, cleans both" {
const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
const p = try withFile(testing.allocator, "one\n");
defer p.deinit();
- var name: [std.fs.max_path_bytes + 8]u8 = undefined;
+ var name: [std.Io.Dir.max_path_bytes + 8]u8 = undefined;
_ = wr(p, Node.of(serialOf(p), .name), try std.fmt.bufPrint(&name, "{s}/z.txt\n", .{dir}));
try testing.expect(p.executeBuiltinLine(0, "Zerox"));
const twin_id = for (p.panes, 0..) |slot, id| {
@@ -1623,7 +1618,7 @@ test "a refusal's +Unsaved goes in the session's directory when the active pane'
const f = pane.file orelse continue;
if (f.output) |o| if (o.from == .unsaved) break f.path;
} else return error.NoUnsavedPane;
- try testing.expectEqualStrings(p.sessionDir(), std.fs.path.dirname(unsaved).?);
+ try testing.expectEqualStrings(p.sessionDir(), std.Io.Dir.path.dirname(unsaved).?);
}