summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep')
-rw-r--r--src/ninep/ctl.zig93
-rw-r--r--src/ninep/events.zig20
-rw-r--r--src/ninep/pane.zig2
-rw-r--r--src/ninep/pty.zig4
-rw-r--r--src/ninep/tree.zig2
5 files changed, 62 insertions, 59 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index d21e58a3..2e362f77 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -420,39 +420,42 @@ pub const pane_text_cap = 9 * 12 + 2 * 256 + 4 + "notcurrent ".len + 48 + "colla
/// a REPL's id.
pub fn paneText(p: *Pardes, pane: *Pane, buf: *[pane_text_cap]u8) []const u8 {
var w = std.Io.Writer.fixed(buf);
- w.print("{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} ", .{
- pane.serial,
- pane_files.tagOf(p, pane).len,
- // A terminal's body is its history, read whole on an open's first read.
- if (pane.isTerminal()) panes.terminal.screenTextLen(pane) else pane_files.bodyOf(pane).len,
- // A directory pane is one, as acme's isdir says.
- @intFromBool(if (pane.file) |f| f.listing != null else false),
- @intFromBool(pane_files.dirtyOf(pane)),
- pane.cols,
- }) 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; // 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; // 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[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; // 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[0..@min(kind_fields.len, fields.len)]}) catch unreachable; // 128 and a blank, counted
+ // A buffer that fills cuts the line there.
+ fill: {
+ w.print("{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} ", .{
+ pane.serial,
+ pane_files.tagOf(p, pane).len,
+ // A terminal's body is its history, read whole on an open's first read.
+ if (pane.isTerminal()) panes.terminal.screenTextLen(pane) else pane_files.bodyOf(pane).len,
+ // A directory pane is one, as acme's isdir says.
+ @intFromBool(if (pane.file) |f| f.listing != null else false),
+ @intFromBool(pane_files.dirtyOf(pane)),
+ pane.cols,
+ }) catch break :fill;
+ const font = p.settings.font.effective_name.get();
+ writeQuoted(&w, if (font.len == 0) "default" else font) catch break :fill;
+ // 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 break :fill;
+ // 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 break :fill;
+ // 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 break :fill;
+ 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 break :fill;
+ }
+ // 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 break :fill;
}
- // 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; // an enum's name, counted
return w.buffered();
}
@@ -521,7 +524,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 unreachable); // acme_words holds short literals
+ 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 &p.fs.ename); // cut to ename's 320
break now;
} else typed;
const arg = if (sp) |s| std.mem.trim(u8, line[s + 1 ..], " \t") else "";
@@ -672,18 +675,18 @@ pub fn writePager(p: *Pardes, req: Req) Reply {
// 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 unreachable); // 256 fit 320
+ 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 &p.fs.ename); // cut to ename's 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 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
+ 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 &p.fs.ename); // cut to ename's 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 &p.fs.ename); // cut to ename's 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 unreachable); // 256 fit 320
+ return tree.failText(req.tag, E.PERM, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: permission denied", .{dir[0..@min(dir.len, 256)]}) catch &p.fs.ename); // cut to ename's 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) {
@@ -1104,11 +1107,11 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply {
// 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;
+ var why_buf: pardes.Kind.Buf(48) = .{};
const why = if (pardes.Messages.dialReason(failed)) |r|
- std.fmt.bufPrint(&why_buf, "dial failed: {s}", .{r}) catch unreachable // dialReason's literals and 13 fit 48
+ why_buf.print("dial failed: {s}", .{r})
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[0..@min(why.len, 48)] }) catch unreachable); // 256, 48 and 7 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 &p.fs.ename); // cut to ename's 320
}
},
.lock => {
@@ -1126,7 +1129,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[0..@min(choices.len, 64)]}) catch unreachable); // 64 and 18 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 &p.fs.ename); // cut to ename's 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) {
@@ -1135,8 +1138,8 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply {
const id = p.paneBySerial(serial).?;
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 unreachable); // a u32 and 256 fit 300
+ var rec: pardes.Kind.Buf(300) = .{};
+ pardes.ctlfs.events.notePath(p, "answer", rec.print("{d} {s}", .{ serial, path }));
if (!std.mem.eql(u8, path, "-")) exec_line.saveTo(p, id, path);
asked.closePrompt();
} else if (std.mem.startsWith(u8, line, "answer ")) {
@@ -1222,7 +1225,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}", .{ @tagName(w), why }) catch unreachable) }; // an enum's name and a literal fit 320
+ return .{ .refused = tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s}: {s}", .{ @tagName(w), why }) catch &p.fs.ename) }; // cut to ename's 320
},
};
if (!apply) return .done;
@@ -1260,7 +1263,7 @@ pub fn getRefused(p: *Pardes, pane: *Pane, word: []const u8) ?[]const u8 {
p.fs.unlogged = true;
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[0..@min(word.len, 16)] }) catch unreachable; // 256, 16 and 33 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 &p.fs.ename; // cut to ename's 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 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.* = ' ';
};
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 52ae9494..58b14c92 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -893,7 +893,7 @@ fn writeName(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
// Save could only fail. Said now, EISDIR.
const is_dir = name[name.len - 1] == '/' or std.mem.eql(u8, full, "/") or
(if (fs.localPath(full)) |local| exec.kindOf(local) == .directory else false);
- if (is_dir) return tree.failText(req.tag, E.ISDIR, std.fmt.bufPrint(&p.fs.ename, "name: {s} is a directory, not a file", .{full[0..@min(full.len, 256)]}) catch unreachable); // 256 fit 320
+ if (is_dir) return tree.failText(req.tag, E.ISDIR, std.fmt.bufPrint(&p.fs.ename, "name: {s} is a directory, not a file", .{full[0..@min(full.len, 256)]}) catch &p.fs.ename); // cut to ename's 320
nameBuffer(p, id, full, false) catch |err| return Reply.fail(req.tag, switch (err) {
error.OutOfMemory => E.NOMEM,
else => E.INVAL,
diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig
index 2a4fc1ed..8514c669 100644
--- a/src/ninep/pty.zig
+++ b/src/ninep/pty.zig
@@ -61,13 +61,13 @@ pub fn writeCtl(p: *Pardes, req: Req, id: usize) Reply {
// refused before anything runs, as Term there is.
const dir = pane.cwdSlice();
if (pardes.exec.missingDir(p, dir))
- return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}: no such 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, "exec: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch &p.fs.ename); // cut to ename's 320
// Nor is a shell that is not there, or a script whose
// interpreter is not: refused, and the running shell kept.
const bin = pane.shell orelse p.shellBin();
var why: [320]u8 = undefined;
if (pardes.tape.value(.shell, @import("../host_io.zig").Shell.refusal, .{ bin[0..@min(bin.len, 200)], &why })) |refused|
- return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}", .{refused[0..@min(refused.len, 300)]}) catch unreachable); // 300 fit 320
+ return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}", .{refused[0..@min(refused.len, 300)]}) catch &p.fs.ename); // cut to ename's 320
};
if (verb(p, id, line, apply)) |why| return tree.failText(req.tag, E.INVAL, why);
}
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index fde0054f..dfcf7097 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); // a literal and an integer fit 320
+ const slot = p.freeSlot() orelse return failText(req.tag, E.NOSPC, std.fmt.comptimePrint("pane/new: " ++ pardes.Messages.no_pane_slots, .{pardes.MAX_PANES}));
p.fs.no_pane_slot = false;
// Refused, the open's err is the one record of it (the
// one rule): no msg besides.