summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/9p_io.zig4
-rw-r--r--src/Core.zig12
-rw-r--r--src/File.zig8
-rw-r--r--src/Jump.zig4
-rw-r--r--src/Messages.zig4
-rw-r--r--src/Output.zig4
-rw-r--r--src/Pipe.zig2
-rw-r--r--src/Query.zig24
-rw-r--r--src/builtins.zig44
-rw-r--r--src/daemon.zig14
-rw-r--r--src/dump.zig4
-rw-r--r--src/edit.zig4
-rw-r--r--src/edit_cmd.zig24
-rw-r--r--src/exec.zig50
-rw-r--r--src/host_io.zig8
-rw-r--r--src/keys.zig4
-rw-r--r--src/layout.zig3
-rw-r--r--src/look.zig8
-rw-r--r--src/lsp/Ask.zig42
-rw-r--r--src/lsp/lsp_client.zig2
-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
-rw-r--r--src/terminal.zig2
26 files changed, 197 insertions, 195 deletions
diff --git a/src/9p_io.zig b/src/9p_io.zig
index e1472006..75f55296 100644
--- a/src/9p_io.zig
+++ b/src/9p_io.zig
@@ -355,8 +355,8 @@ pub const Listener = struct {
const core = l.core;
const refused = l.refused.swap(0, .acq_rel);
if (refused != 0) {
- var why: [64]u8 = undefined;
- pardes.ctlfs.events.notePath(core, "err -", std.fmt.bufPrint(&why, "9p: too many connections ({d} turned away)", .{refused}) catch unreachable); // a u32 fits 64
+ var why: pardes.Kind.Buf(64) = .{};
+ pardes.ctlfs.events.notePath(core, "err -", why.print("9p: too many connections ({d} turned away)", .{refused}));
}
if (!core.fs.news) return;
core.fs.news = false;
diff --git a/src/Core.zig b/src/Core.zig
index 775d1e9a..5496a979 100644
--- a/src/Core.zig
+++ b/src/Core.zig
@@ -1334,16 +1334,16 @@ pub fn saveFailed(p: *Pardes, id: u8, path: []const u8, err: anyerror) void {
// The `-%` spelling fs.zig already uses for "make this dirty".
f.saved_revision = f.revision -% 1;
};
- var what: [limits.host_path_cap + 32]u8 = undefined;
+ var what: pardes.Kind.Buf(limits.host_path_cap + 32) = .{};
// A write into a directory that is not there: said so, in the words
// a mount reads as ENOENT; EACCES when one above refuses.
const parent = parentTrouble(path, err);
if (parent.denied)
- p.reportFailure(id, std.fmt.bufPrint(&what, "Save {s}: permission denied", .{path[0..@min(path.len, limits.host_path_cap)]}) catch unreachable) // cap + 24 fits cap + 32
+ p.reportFailure(id, what.print("Save {s}: permission denied", .{path[0..@min(path.len, limits.host_path_cap)]}))
else if (parent.missing)
- p.reportFailure(id, std.fmt.bufPrint(&what, "Save {s}: no such directory", .{path[0..@min(path.len, limits.host_path_cap)]}) catch unreachable) // cap + 24 fits cap + 32
+ p.reportFailure(id, what.print("Save {s}: no such directory", .{path[0..@min(path.len, limits.host_path_cap)]}))
else
- p.reportError(id, std.fmt.bufPrint(&what, "Save {s}", .{path[0..@min(path.len, limits.host_path_cap)]}) catch unreachable, err); // cap + 5 fits cap + 32
+ p.reportError(id, what.print("Save {s}", .{path[0..@min(path.len, limits.host_path_cap)]}), err);
p.noteLateFailure(id);
}
@@ -1733,8 +1733,8 @@ pub fn windowOpacityDone(p: *Pardes, applied: u8, failure: ?[]const u8) void {
// Do not claim a value the compositor refused; an explicit retry of
// the same command will arm a new request.
p.settings.window_opacity = applied;
- var buf: [240 + 16]u8 = undefined;
- p.setMessage(p.view().active, std.fmt.bufPrint(&buf, "WindowOpacity: {s}", .{reason[0..@min(reason.len, 240)]}) catch unreachable); // 240 + 15 fits 240 + 16
+ var buf: pardes.Kind.Buf(240 + 16) = .{};
+ p.setMessage(p.view().active, buf.print("WindowOpacity: {s}", .{reason}));
}
/// Recompute geometry, push grid-size changes to each emulator and pty,
diff --git a/src/File.zig b/src/File.zig
index 1c40379d..1e553bc9 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -1511,8 +1511,8 @@ pub fn deleted(p: *Pardes, id: u8) void {
const f = if (pane.file) |*file| file else return;
if (f.disk_gone) return;
f.disk_gone = true;
- var said: [limits.host_path_cap + 64]u8 = undefined;
- p.setMessage(id, std.fmt.bufPrint(&said, "{s} deleted on disk (Save writes it again)", .{f.path[0..@min(f.path.len, limits.host_path_cap)]}) catch unreachable); // cap + 52 fits cap + 64
+ var said: pardes.Kind.Buf(limits.host_path_cap + 64) = .{};
+ p.setMessage(id, said.print("{s} deleted on disk (Save writes it again)", .{f.path[0..@min(f.path.len, limits.host_path_cap)]}));
var rec: [32]u8 = undefined;
pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d} deleted", .{pane.serial}) catch unreachable); // a u32 fits 32
}
@@ -1538,8 +1538,8 @@ pub fn changed(p: *Pardes, id: u8, bytes: []const u8) void {
if (f.disk_newer == disk) return;
f.disk_newer = disk;
f.disk_newer_warned = false;
- var said: [limits.host_path_cap + 64]u8 = undefined;
- p.setMessage(id, std.fmt.bufPrint(&said, "{s} changed on disk (get reloads it, Save overwrites it)", .{f.path[0..@min(f.path.len, limits.host_path_cap)]}) catch unreachable); // cap + 52 fits cap + 64
+ var said: pardes.Kind.Buf(limits.host_path_cap + 64) = .{};
+ p.setMessage(id, said.print("{s} changed on disk (get reloads it, Save overwrites it)", .{f.path[0..@min(f.path.len, limits.host_path_cap)]}));
var rec: [16]u8 = undefined;
pardes.ctlfs.events.notePath(p, "changed", std.fmt.bufPrint(&rec, "{d}", .{pane.serial}) catch unreachable); // a u32 fits 16
return;
diff --git a/src/Jump.zig b/src/Jump.zig
index 2603d672..9f40343a 100644
--- a/src/Jump.zig
+++ b/src/Jump.zig
@@ -301,8 +301,8 @@ pub fn jumpBy(p: *Pardes, delta: i32) void {
// first said), and the step goes on to the next place, never
// stuck on one that cannot open.
if (found == null or !Pardes.recentKeeps(found.?.path)) {
- var said: [recent_path_cap + 32]u8 = undefined;
- if (found) |e| p.setMessage(v.active, std.fmt.bufPrint(&said, "{s}: deleted, skipped", .{e.path[0..@min(e.path.len, recent_path_cap)]}) catch unreachable); // cap and 18 fit
+ var said: Kind.Buf(recent_path_cap + 32) = .{};
+ if (found) |e| p.setMessage(v.active, said.print("{s}: deleted, skipped", .{e.path[0..@min(e.path.len, recent_path_cap)]}));
const hash = j.path_hash;
var w: usize = 0;
var cur = v.jumps.cur;
diff --git a/src/Messages.zig b/src/Messages.zig
index 80e7ab07..e4328a1e 100644
--- a/src/Messages.zig
+++ b/src/Messages.zig
@@ -117,8 +117,8 @@ pub const Message = struct {
pub fn clockText(seconds: i64, gmtoff: i64) [8]u8 {
var text: [8]u8 = "--:--:--".*;
if (noTime()) return text;
- const day: u32 = @intCast(@mod(seconds + gmtoff, 86400));
- _ = std.fmt.bufPrint(&text, "{d:0>2}:{d:0>2}:{d:0>2}", .{ day / 3600, day / 60 % 60, day % 60 }) catch unreachable; // under a day: 8 bytes
+ const day: std.time.epoch.DaySeconds = .{ .secs = @intCast(@mod(seconds + gmtoff, 86400)) };
+ _ = std.fmt.bufPrint(&text, "{d:0>2}:{d:0>2}:{d:0>2}", .{ day.getHoursIntoDay(), day.getMinutesIntoHour(), day.getSecondsIntoMinute() }) catch unreachable; // a u5 and two u6s: two digits each
return text;
}
diff --git a/src/Output.zig b/src/Output.zig
index ceffa7d9..384bb500 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -770,14 +770,14 @@ pub fn dropUnsaved(p: *Pardes, gone: *const Pane) void {
const o = rf.output orelse continue;
if (o.from != .unsaved) continue;
var scratch_name: [limits.host_path_cap + 24]u8 = undefined;
- const as_scratch = std.fmt.bufPrint(&scratch_name, "{s} (pane {d}): Modified", .{ gf.path, gone.serial }) catch "";
+ const as_scratch = std.fmt.bufPrint(&scratch_name, "{s} (pane {d}): Modified", .{ gf.path, gone.serial }) catch null;
var out: std.ArrayList(u8) = .empty;
var lines = std.mem.splitScalar(u8, rf.content, '\n');
var dropped = false;
var first = true;
while (lines.next()) |line| {
const is_it = std.mem.startsWith(u8, line, gf.path) and std.mem.eql(u8, line[gf.path.len..], ": Modified");
- if (is_it or (as_scratch.len > 0 and std.mem.eql(u8, line, as_scratch))) {
+ if (is_it or (as_scratch != null and std.mem.eql(u8, line, as_scratch.?))) {
dropped = true;
continue;
}
diff --git a/src/Pipe.zig b/src/Pipe.zig
index 87768f22..a02b9214 100644
--- a/src/Pipe.zig
+++ b/src/Pipe.zig
@@ -301,7 +301,7 @@ pub fn pipeResponse(
const cut = pipeCut(&wait, content, i) orelse return;
const output = pipeOutput(&wait, outputs, content, i);
if (output.len > selection_pipe.max_stdout_bytes) return;
- total_output = std.math.add(usize, total_output, output.len) catch unreachable; // both are capped far below a usize's room
+ total_output = std.math.add(usize, total_output, output.len) catch return; // past any cap
if (total_output > selection_pipe.max_total_stdout_bytes) return;
if (i > 0 and cut.lo < ops[i - 1].q1) return;
ops[i] = .{ .q0 = @intCast(cut.lo), .q1 = @intCast(cut.hi), .text = output };
diff --git a/src/Query.zig b/src/Query.zig
index abcf147e..1bb5792a 100644
--- a/src/Query.zig
+++ b/src/Query.zig
@@ -936,8 +936,8 @@ fn writePlacesRows(p: *Pardes, q: *Query, out: *std.ArrayList(u8), rows: *std.Ar
const head_le = if (decls[di].start_line + 1 < index.len) index[decls[di].start_line + 1] - 1 else f.content.len;
const head = std.mem.trim(u8, f.content[head_ls..head_le], " \t\r");
// Its address too, `rel:line`, in the column the hits' are.
- var hb: [8192]u8 = undefined;
- const address = std.fmt.bufPrint(&hb, "{s}:{d}", .{ rel[0..@min(rel.len, 4096)], decls[di].start_line + 1 }) catch unreachable; // 4096 and a line fit 8192
+ var hb: [4096 + 4096]u8 = undefined;
+ const address = std.fmt.bufPrint(&hb, "{s}:{d}", .{ rel[0..@min(rel.len, 4096)], decls[di].start_line + 1 }) catch unreachable; // rel cut at the first 4096, a colon and a usize in the second
const gutter = @max(width, address.len) + 2;
const shown = head[0..@min(head.len, hb.len -| gutter)];
@memset(hb[address.len..gutter], ' ');
@@ -974,8 +974,8 @@ fn makeTextRows(p: *Pardes, id: usize, oid: usize, full: bool) !void {
const from = if (full) 0 else at -| 2;
if (set.started and set.from == rp.serial) {
if (from > 0) {
- var hb: [64]u8 = undefined;
- try noteRow(p, q, &out, &rows, std.fmt.bufPrint(&hb, " ... {d} places before these", .{from}) catch unreachable); // a usize fits
+ var hb: pardes.Kind.Buf(64) = .{};
+ try noteRow(p, q, &out, &rows, hb.print(" ... {d} places before these", .{from}));
}
try writePlacesRows(p, q, &out, &rows, owner, std.Io.Dir.path.dirname(rp.file.?.path) orelse "/", from, &budget);
}
@@ -1054,9 +1054,9 @@ fn makeAllRows(p: *Pardes, id: usize) !void {
}
q.total += set.hits.items.len;
q.more = q.more or !set.complete();
- var hb: [600]u8 = undefined;
+ var hb: pardes.Kind.Buf(600) = .{};
const name = if (tp.file) |f| Names.relative(f.path, std.Io.Dir.path.dirname(rp.file.?.path) orelse "") else "";
- const head = std.fmt.bufPrint(&hb, config.pane_addr ++ "{d} {s} ({d})", .{ tp.serial, name[0..@min(name.len, 500)], set.hits.items.len }) catch unreachable; // 500 and 44 fit 600
+ const head = hb.print(config.pane_addr ++ "{d} {s} ({d})", .{ tp.serial, name[0..@min(name.len, 500)], set.hits.items.len });
try q.items.append(p.gpa, .{ .kind = .header, .serial = tp.serial });
try writeRow(p, &out, &rows, head, .{ .kind = .context, .declaration = true, .path = @constCast(addressOf(p.scratch.allocator(), tp)), .at = .{}, .location_end = 0, .code_start = 0 });
try writePlacesRows(p, q, &out, &rows, tp, std.Io.Dir.path.dirname(rp.file.?.path) orelse "/", 0, &budget);
@@ -1174,8 +1174,8 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void {
const lo = if (full) 0 else at -| 2;
const hi = if (full) q.found.items.len else @min(q.found.items.len, lo + live_rows);
if (lo > 0) {
- var hb: [64]u8 = undefined;
- try noteRow(p, q, &out, &rows, std.fmt.bufPrint(&hb, " ... {d} lines before these", .{lo}) catch unreachable); // a usize fits
+ var hb: pardes.Kind.Buf(64) = .{};
+ try noteRow(p, q, &out, &rows, hb.print(" ... {d} lines before these", .{lo}));
}
var current: ?usize = null;
var sh: Shades = .{};
@@ -1203,8 +1203,8 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void {
try writeHitRow(p, &out, &rows, &sh, width, rel, path, fd.line, code, fd.col, fd.end, &.{});
}
if (hi < q.found.items.len) {
- var hb: [64]u8 = undefined;
- try noteRow(p, q, &out, &rows, std.fmt.bufPrint(&hb, " ... {d} lines after these", .{q.found.items.len - hi}) catch unreachable); // a usize fits
+ var hb: pardes.Kind.Buf(64) = .{};
+ try noteRow(p, q, &out, &rows, hb.print(" ... {d} lines after these", .{q.found.items.len - hi}));
}
if (p.stream.target == rp.serial and p.stream.state == .capped) try noteRow(p, q, &out, &rows, " ... stopped at 2000 lines: More in the tag goes on");
try skippedRow(p, q, rp, &out, &rows);
@@ -1222,8 +1222,8 @@ fn makeGrepRows(p: *Pardes, id: usize, full: bool) !void {
fn skippedRow(p: *Pardes, q: *Query, rp: *Pane, out: *std.ArrayList(u8), rows: *std.ArrayList(locations.Row)) !void {
const n = p.stream.skipped;
if (p.stream.target != rp.serial or n == 0) return;
- var hb: [96]u8 = undefined;
- try noteRow(p, q, out, rows, std.fmt.bufPrint(&hb, " {d} director{s} skipped: permission denied", .{ n, if (n == 1) "y" else "ies" }) catch unreachable); // a usize and 40 fit 96
+ var hb: pardes.Kind.Buf(96) = .{};
+ try noteRow(p, q, out, rows, hb.print(" {d} director{s} skipped: permission denied", .{ n, if (n == 1) "y" else "ies" }));
}
/// `k` for a Grep: the current row's line among all the lines sent.
diff --git a/src/builtins.zig b/src/builtins.zig
index c500ee56..4712a67a 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -593,8 +593,8 @@ pub fn warnModifiedIn(c: Ctx, asking: Pane.Discarding, which: Asked) bool {
// A refused Delcol changes nothing, the layout included: its records
// and its notice say it, and no +Unsaved opens.
if (asking != .Delcol) if (c.p.gpa.dupe(u8, listed.items)) |content| panes.Output.openUnsaved(c.p, c.id, content) else |_| {};
- var short: [96]u8 = undefined;
- c.p.reportFailure(c.id, std.fmt.bufPrint(&short, "{d} unsaved pane{s} \u{2014} {s} again to discard", .{ count, if (count == 1) "" else "s", @tagName(asking) }) catch unreachable); // a u32 and 48 fit 96
+ var short: pardes.Kind.Buf(96) = .{};
+ c.p.reportFailure(c.id, short.print("{d} unsaved pane{s} \u{2014} {s} again to discard", .{ count, if (count == 1) "" else "s", @tagName(asking) }));
}
if (count > 0 and (c.p.fs.no_prompt or c.p.fs.capturing)) {
var said_buf: pardes.Kind.Buf(limits.host_path_cap + 96) = .{};
@@ -706,8 +706,8 @@ pub const Restore = struct {
var label_buf: [256]u8 = undefined;
const file = if (typed) |t| dump.restoreFile(t, c.p.settings.dump_dir.get(), &full_buf) else null;
const name = if (file) |path| path else pardes.tape.authority(pardes.Db.labelled, .{ &c.p.db, c.p, typed, @as([]u8, &label_buf) }) orelse {
- var buf: [320]u8 = undefined;
- return c.p.reportFailure(c.id, if (typed) |t| std.fmt.bufPrint(&buf, "Restore: no dump labelled {s}", .{t[0..@min(t.len, 256)]}) catch unreachable else "Restore: no dump yet; name one"); // 256 fit 320
+ var buf: pardes.Kind.Buf(320) = .{};
+ return c.p.reportFailure(c.id, if (typed) |t| buf.print("Restore: no dump labelled {s}", .{t}) else "Restore: no dump yet; name one");
};
if (name.len > c.p.restore_buf.len) return c.p.reportFailure(c.id, "Restore: that name is too long");
// A file that cannot be read is said now, and fails a ctl write:
@@ -787,8 +787,8 @@ pub const Mount = struct {
const dial = std.mem.trim(u8, args.rest(), " \t");
if (dial.len == 0) return c.p.reportFailure(c.id, e_args);
c.p.fs.mount(c.p.gpa, name, dial) catch |err| {
- var said: [200]u8 = undefined;
- if (err == error.BadDial) return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Mount: bad dial address: {s} (unix!/path, /path, tcp!<numeric-ip>!<port>, or a session name)", .{dial[0..@min(dial.len, 100)]}) catch unreachable); // 100 and 92 fit 200
+ var said: pardes.Kind.Buf(200) = .{};
+ if (err == error.BadDial) return c.p.reportFailure(c.id, said.print("Mount: bad dial address: {s} (unix!/path, /path, tcp!<numeric-ip>!<port>, or a session name)", .{dial[0..@min(dial.len, 100)]}));
return c.p.reportError(c.id, "Mount", err);
};
// A socket path that is not there: said so (ENOENT), not a dial
@@ -799,8 +799,8 @@ pub const Mount = struct {
c.p.gpa.free(gone.name);
c.p.gpa.free(gone.dial);
}
- var said: [200]u8 = undefined;
- return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Mount {s}: {s}: no such socket", .{ name[0..@min(name.len, 32)], path[0..@min(path.len, 100)] }) catch unreachable); // 132 and 25 fit 200
+ var said: pardes.Kind.Buf(200) = .{};
+ return c.p.reportFailure(c.id, said.print("Mount {s}: {s}: no such socket", .{ name[0..@min(name.len, 32)], path[0..@min(path.len, 100)] }));
};
// A mount that cannot be reached is said now, and taken back, not
// found out by the first look through it.
@@ -810,8 +810,8 @@ pub const Mount = struct {
c.p.gpa.free(gone.name);
c.p.gpa.free(gone.dial);
}
- var what: [160]u8 = undefined;
- return c.p.reportError(c.id, std.fmt.bufPrint(&what, "Mount {s} {s}", .{ name[0..@min(name.len, 32)], dial[0..@min(dial.len, 100)] }) catch unreachable, err); // 132 and 7 fit 160
+ var what: pardes.Kind.Buf(160) = .{};
+ return c.p.reportError(c.id, what.print("Mount {s} {s}", .{ name[0..@min(name.len, 32)], dial }), err);
};
}
};
@@ -828,8 +828,8 @@ pub const Unmount = struct {
pardes.filesystem.unmount(c.p, name) catch |err| {
// "no such": the words 9ns reads as ENOENT.
if (err == error.NotMounted) {
- var said: [96]u8 = undefined;
- return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Unmount: no such mount {s}", .{name[0..@min(name.len, 32)]}) catch unreachable); // 32 and 23 fit 96
+ var said: pardes.Kind.Buf(96) = .{};
+ return c.p.reportFailure(c.id, said.print("Unmount: no such mount {s}", .{name}));
}
return c.p.reportError(c.id, "Unmount", err);
};
@@ -878,8 +878,8 @@ pub const ThemeFile = struct {
const arg = pardes.filesystem.expandHome(std.mem.trim(u8, c.arg orelse return, " \t\r\n"), &home_buf);
// Said with why, not "invalid theme path".
if (!std.mem.endsWith(u8, arg, ".zon")) {
- var said: [320]u8 = undefined;
- return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "ThemeFile: {s}: invalid theme path: a theme file is a .zon (DumpThemes writes some to start from)", .{arg[0..@min(arg.len, 200)]}) catch unreachable); // 200 and 85 fit 320
+ var said: pardes.Kind.Buf(320) = .{};
+ return c.p.reportFailure(c.id, said.print("ThemeFile: {s}: invalid theme path: a theme file is a .zon (DumpThemes writes some to start from)", .{arg[0..@min(arg.len, 200)]}));
}
colors.requestThemeFile(c.p, c.id, arg);
}
@@ -935,8 +935,8 @@ pub const TreeContext = struct {
fn stateArg(c: Ctx, comptime T: type, comptime builtin_word: []const u8, comptime takes: []const u8) ?T {
const a = std.mem.trim(u8, c.arg orelse return null, " \t");
return std.meta.stringToEnum(T, a) orelse {
- var said: [128]u8 = undefined;
- c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "invalid argument: " ++ builtin_word ++ " takes " ++ takes ++ ", not \"{s}\"", .{a[0..@min(a.len, 32)]}) catch unreachable); // its callers' words and 32 fit 128
+ var said: pardes.Kind.Buf(128) = .{};
+ c.p.reportFailure(c.id, said.print("invalid argument: " ++ builtin_word ++ " takes " ++ takes ++ ", not \"{s}\"", .{a[0..@min(a.len, 32)]}));
return null;
};
}
@@ -1061,10 +1061,10 @@ pub const Get = struct {
// A file that is not there, or a directory, is said before unsaved
// edits are asked about: there would be nothing to load over them.
if (typed.len > 0) if (@import("fs.zig").localPath(path)) |local| {
- var said: [320]u8 = undefined;
+ var said: pardes.Kind.Buf(320) = .{};
const kind = exec.kindOf(local);
if (kind == null or kind.? == .directory)
- return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Get: {s}: {s}", .{ path[0..@min(path.len, 256)], if (kind == null) "no such file" else "is a directory" }) catch unreachable); // 256 fit 320
+ return c.p.reportFailure(c.id, said.print("Get: {s}: {s}", .{ path[0..@min(path.len, 256)], if (kind == null) "no such file" else "is a directory" }));
};
if (ctl.getRefused(c.p, c.pane, "Get")) |said| return c.p.reportFailure(c.id, said);
const errno = if (typed.len == 0) ctl.get(c.p, c.pane, &failed) else ctl.getFile(c.p, c.pane, path, &failed);
@@ -1209,14 +1209,14 @@ pub const Save = struct {
// Said, never a silent success.
if (c.pane.file == null and !c.pane.isTerminal()) {
const kind = if (c.pane.addon) |k| k.nameOf() else "";
- var said: [64]u8 = undefined;
- return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Save: a{s} {s} pane has no text to save", .{ if (kind.len > 0 and std.mem.indexOfScalar(u8, "aeiou", kind[0]) != null) "n" else "", kind[0..@min(kind.len, 16)] }) catch unreachable); // 16 and 36 fit 64
+ var said: pardes.Kind.Buf(64) = .{};
+ return c.p.reportFailure(c.id, said.print("Save: a{s} {s} pane has no text to save", .{ if (kind.len > 0 and std.mem.indexOfScalar(u8, "aeiou", kind[0]) != null) "n" else "", kind[0..@min(kind.len, 16)] }));
}
// A directory's listing is no file to write, bare or to a path, as
// acme's Put does nothing in a directory window.
if (c.pane.file) |file| if (file.listing != null) {
- var said: [limits.host_path_cap + 48]u8 = undefined;
- return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Save: {s} is a directory", .{file.path[0..@min(file.path.len, limits.host_path_cap)]}) catch unreachable); // cap and 21 fit
+ var said: pardes.Kind.Buf(limits.host_path_cap + 48) = .{};
+ return c.p.reportFailure(c.id, said.print("Save: {s} is a directory", .{file.path[0..@min(file.path.len, limits.host_path_cap)]}));
};
const path = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
if (path.len > 0) return exec.saveTo(c.p, c.id, path);
diff --git a/src/daemon.zig b/src/daemon.zig
index dc86963d..f02c339e 100644
--- a/src/daemon.zig
+++ b/src/daemon.zig
@@ -359,10 +359,10 @@ pub fn setState(detached: bool) void {
/// This session's replica clients now, each its process's pid (0 when its
/// socket's peer is not known), for `--ps`.
pub fn clients(pids: []const libc.pid_t) void {
- var buf: [64]u8 = undefined;
+ var buf: ["clients".len + max_clients * " -2147483648".len]u8 = undefined;
var w: std.Io.Writer = .fixed(&buf);
- w.writeAll("clients") catch unreachable; // a literal fits 64
- for (pids[0..@min(pids.len, max_clients)]) |pid| w.print(" {d}", .{pid}) catch unreachable; // with max_clients pids, fits 64
+ w.writeAll("clients") catch unreachable; // a literal, its .len in buf's
+ for (pids[0..@min(pids.len, max_clients)]) |pid| w.print(" {d}", .{pid}) catch unreachable; // max_clients i32s, in buf's type
tell(w.buffered(), &.{});
}
@@ -761,15 +761,15 @@ const Daemon = struct {
/// TERM and marked, its pids answered; the shells of none kept, for
/// all of them.
fn kill(d: *Daemon, i: u8, named: ?[]const u8) void {
- var line: [msg_max]u8 = undefined;
+ var line: ["ok".len + max_conns * " -2147483648".len]u8 = undefined;
var w: std.Io.Writer = .fixed(&line);
- w.writeAll("ok") catch unreachable; // a literal fits msg_max
+ w.writeAll("ok") catch unreachable; // a literal, its .len in line's
var n: usize = 0;
for (&d.conns) |*s| if (s.fd >= 0 and s.kind != null) {
if (named) |want| if (!std.mem.eql(u8, s.named(), want)) continue;
s.killed = true;
_ = libc.kill(s.pid, .TERM);
- w.print(" {d}", .{s.pid}) catch unreachable; // max_conns pids after "ok" fit msg_max
+ w.print(" {d}", .{s.pid}) catch unreachable; // one i32 a conn, max_conns in line's type
n += 1;
};
if (named == null) {
@@ -954,7 +954,7 @@ const Daemon = struct {
return null;
}
if (count == 0) {
- w.print("no the detached session{s} running {s} {s}=<name>`", .{ if (others == 1) " is" else "s are", if (others == 1) "is" else "are each", other }) catch unreachable; // literals fit 511
+ w.print("no the detached session{s} running {s} {s}=<name>`", .{ if (others == 1) " is" else "s are", if (others == 1) "is" else "are each", other }) catch {}; // cut short, still 0-terminated
return null;
}
w.print("no {d} detached sessions are running; say which with --attach=<name>:", .{count}) catch unreachable; // a usize fits 511
diff --git a/src/dump.zig b/src/dump.zig
index 06721be1..08736c84 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -254,7 +254,7 @@ pub fn check(gpa: std.mem.Allocator, bytes: []const u8, why: *[256]u8) !void {
error.NoDump => "it holds no dump",
error.OutOfMemory => "out of memory",
else => "it is no dump of pardes's",
- }}) catch unreachable; // a literal or an error's name fits 255
+ }}) catch why[0 .. why.len - 1]; // cut at 255
why[said.len] = 0;
return err;
};
@@ -266,7 +266,7 @@ pub fn check(gpa: std.mem.Allocator, bytes: []const u8, why: *[256]u8) !void {
error.BadDump => "it does not begin as one",
error.EndOfDump => "it is cut short",
else => @errorName(err),
- }}) catch unreachable; // a literal or an error's name fits 255
+ }}) catch why[0 .. why.len - 1]; // cut at 255
why[said.len] = 0;
return err;
};
diff --git a/src/edit.zig b/src/edit.zig
index 4253d293..064f0f44 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -118,8 +118,8 @@ pub fn applyPaste(p: *Pardes, whole: []const u8) Error!void {
const limit = @import("memory.zig").limits.max_paste_bytes;
const bytes = if (whole.len > limit) whole[0..modal.graphemeStart(whole, limit)] else whole;
if (whole.len > limit) {
- var said: [96]u8 = undefined;
- p.setMessage(v.active, std.fmt.bufPrint(&said, "paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024}) catch unreachable); // a usize and 47 bytes fit 96
+ var said: pardes.Kind.Buf(96) = .{};
+ p.setMessage(v.active, said.print("paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024}));
}
// A prompt answering for a header takes the paste, as it takes keys.
const asking = if (p.panes[v.active]) |active| active.prompt != .none else false;
diff --git a/src/edit_cmd.zig b/src/edit_cmd.zig
index 0f10e136..b1239a84 100644
--- a/src/edit_cmd.zig
+++ b/src/edit_cmd.zig
@@ -176,9 +176,9 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void {
var world: World = .{ .p = p, .from = id, .arena = arena };
var why: sam.Why = .{};
- var text: [260]u8 = undefined;
+ var text: pardes.Kind.Buf(260) = .{};
const res = sam.run(arena, files.items, cur, command, .{ .ctx = &world, .check = World.check, .open = World.open, .read = World.read, .refuseGet = World.refuseGet }, &why) catch |err| switch (err) {
- error.Edit => return p.reportFailure(id, std.fmt.bufPrint(&text, "Edit: {s}", .{why.text()}) catch unreachable), // why.text() is a slice of Why's [200]u8 buf; 6 more fit 260
+ error.Edit => return p.reportFailure(id, text.print("Edit: {s}", .{why.text()})),
error.OutOfMemory => return p.reportError(id, "Edit", err),
};
// acme's Edit blocks the editor while its commands run; here the editor
@@ -194,7 +194,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void {
if (!touches) continue;
const q = p.panes[f.id] orelse continue;
for (running.res.files, 0..) |g, j| if (g.id == f.id and running.serials[j] == q.serial and changes(g))
- return p.reportFailure(id, std.fmt.bufPrint(&text, "Edit: busy: {s}: an Edit's commands are running on it", .{f.name[0..@min(f.name.len, 200)]}) catch unreachable); // 200 and 50 fit 260
+ return p.reportFailure(id, text.print("Edit: busy: {s}: an Edit's commands are running on it", .{f.name[0..@min(f.name.len, 200)]}));
}
}
if (res.undo != 0) {
@@ -323,14 +323,14 @@ pub fn finish(p: *Pardes, success: bool, outputs: []const []const u8, failure: ?
var out: std.Io.Writer.Allocating = .init(p.gpa);
defer out.deinit();
const w = &out.writer;
- var line: [256]u8 = undefined;
+ var line: pardes.Kind.Buf(256) = .{};
report: {
w.print("Edit: {c} {s}\n\n", .{ job.c, job.command }) catch break :report;
if (pd.res.jobs.len > 1) if (failure) |f| w.print("command {d} of {d}: ", .{ f.index + 1, pd.res.jobs.len }) catch break :report;
const why_at = out.written().len;
Pipe.writeFailure(w, failure) catch break :report;
const why = std.mem.sliceTo(out.written()[why_at..], '\n');
- const said = std.fmt.bufPrint(&line, "Edit: {c} {s}: {s}", .{ job.c, job.command[0..@min(job.command.len, 120)], why[0..@min(why.len, 120)] }) catch unreachable; // 240 and 10 fit 256
+ const said = line.print("Edit: {c} {s}: {s}", .{ job.c, job.command[0..@min(job.command.len, 120)], why });
const was = p.view().active;
_ = ninep_pane.appendErrors(p, at, out.written());
if (p.panes[was] != null) p.view().active = was;
@@ -344,13 +344,13 @@ pub fn finish(p: *Pardes, success: bool, outputs: []const []const u8, failure: ?
fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
const res = pd.res;
const at = if (p.panes[pd.origin]) |pane| (if (pane.serial == pd.origin_serial) pd.origin else p.view().active) else p.view().active;
- var text: [320]u8 = undefined;
+ var text: pardes.Kind.Buf(320) = .{};
for (res.files, 0..) |f, i| {
if (f.ops.items.len == 0 and !f.close and !f.renamed and !f.moved and f.get == null) continue;
- const pane = p.panes[f.id] orelse return p.reportFailure(at, std.fmt.bufPrint(&text, "Edit: {s} closed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}) catch unreachable); // 256 and 56 fit 320
- if (pane.serial != pd.serials[i]) return p.reportFailure(at, std.fmt.bufPrint(&text, "Edit: {s} closed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}) catch unreachable); // 256 and 56 fit 320
+ const pane = p.panes[f.id] orelse return p.reportFailure(at, text.print("Edit: {s} closed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}));
+ if (pane.serial != pd.serials[i]) return p.reportFailure(at, text.print("Edit: {s} closed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}));
if ((f.ops.items.len > 0 or f.get != null) and pane.file.?.revision != pd.revisions[i])
- return p.reportFailure(at, std.fmt.bufPrint(&text, "Edit: {s} changed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}) catch unreachable); // 256 and 57 fit 320
+ return p.reportFailure(at, text.print("Edit: {s} changed while its commands ran; nothing changed", .{f.name[0..@min(f.name.len, 256)]}));
}
// e first, Get's way: read before anything is changed, so one that
// cannot be read changes nothing; its own undo step puts the old name
@@ -359,7 +359,7 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
const path = f.get orelse continue;
var failed: anyerror = error.Unexpected;
const errno = @import("ninep/ctl.zig").getFile(p, p.panes[f.id].?, path, &failed);
- if (errno != 0) return p.reportFailure(at, std.fmt.bufPrint(&text, "Edit: e {s}: {s}", .{ path[0..@min(path.len, 256)], if (errno == @import("ninep/tree.zig").E.NOENT) "no such file" else "cannot be read" }) catch unreachable); // 256 and 24 fit 320
+ if (errno != 0) return p.reportFailure(at, text.print("Edit: e {s}: {s}", .{ path[0..@min(path.len, 256)], if (errno == @import("ninep/tree.zig").E.NOENT) "no such file" else "cannot be read" }));
}
// `w`'s bytes, written after this step, before anything else is. To
// its own file changed on disk since it was read, as Save is: refused
@@ -436,8 +436,8 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
if (p.panes[was] != null) p.view().active = was;
}
if (refused.written().len > 0) {
- var said: [320]u8 = undefined;
- p.reportFailure(at, std.fmt.bufPrint(&said, "Edit: w: {s} modified on disk since read (w again to overwrite)", .{refused.written()[0..@min(refused.written().len, 200)]}) catch unreachable); // 200 and 66 fit 320
+ var said: pardes.Kind.Buf(320) = .{};
+ p.reportFailure(at, said.print("Edit: w: {s} modified on disk since read (w again to overwrite)", .{refused.written()[0..@min(refused.written().len, 200)]}));
}
// D's panes last, each as Del closes one: an edited one is warned about
// once, and closes on the next.
diff --git a/src/exec.zig b/src/exec.zig
index 46bf54c3..ee6370bf 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -331,8 +331,8 @@ pub fn saveFile(p: *Pardes, id: usize) void {
if (f.disk_newer != null) {
if (!f.disk_newer_warned) {
f.disk_newer_warned = true;
- var said: [Pardes.SavePath.cap + 64]u8 = undefined;
- return p.reportFailure(id, std.fmt.bufPrint(&said, "{s} modified on disk since read (Save again to overwrite)", .{f.path[0..@min(f.path.len, Pardes.SavePath.cap)]}) catch unreachable); // cap and 55 fit
+ var said: pardes.Kind.Buf(Pardes.SavePath.cap + 64) = .{};
+ return p.reportFailure(id, said.print("{s} modified on disk since read (Save again to overwrite)", .{f.path[0..@min(f.path.len, Pardes.SavePath.cap)]}));
}
f.disk_newer = null;
}
@@ -391,8 +391,8 @@ pub fn spawnTty(p: *Pardes, from: usize) ?*Pane {
// that starts shells (none, as in the core's tests, starts none).
const dir = p.execDir(from);
if (missingDir(p, dir)) {
- var said: [pardes.memory.limits.host_path_cap + 48]u8 = undefined;
- p.reportFailure(from, std.fmt.bufPrint(&said, "Term: {s}: no such directory", .{dir[0..@min(dir.len, pardes.memory.limits.host_path_cap)]}) catch unreachable); // cap and 27 fit
+ var said: pardes.Kind.Buf(pardes.memory.limits.host_path_cap + 48) = .{};
+ p.reportFailure(from, said.print("Term: {s}: no such directory", .{dir[0..@min(dir.len, pardes.memory.limits.host_path_cap)]}));
return null;
}
const free = p.freeSlot() orelse {
@@ -475,7 +475,7 @@ pub fn replLive(p: *const Pardes, id: usize) bool {
/// `python-a`.
pub fn replId(buf: *[48]u8, pane: *const Pane) []const u8 {
const r = pane.repl orelse return "";
- return std.fmt.bufPrint(buf, "{s}-{c}", .{ grammars[r.lang].name, r.letter }) catch unreachable; // a comptime grammar name and a letter fit 48
+ return std.fmt.bufPrint(buf, "{s}-{c}", .{ grammars[r.lang].name, r.letter }) catch buf; // cut at 48
}
const Routed = union(enum) { none, sent: usize, asked };
@@ -598,8 +598,8 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
// Sent whole or not at all: a send cut short would leave the REPL in a
// paste, or with half a block.
if (n + 16 > p.writeRoom(to)) {
- var said: [128]u8 = undefined;
- return p.setMessage(from, std.fmt.bufPrint(&said, "Repl: {d} bytes is more than can be sent at once; send less", .{n}) catch unreachable); // a usize and 56 fit 128
+ var said: pardes.Kind.Buf(128) = .{};
+ return p.setMessage(from, said.print("Repl: {d} bytes is more than can be sent at once; send less", .{n}));
}
const pasted = panes.terminal.bracketedPaste(dst);
edit.typeToTty(p, to, dst, clean[0..n]);
@@ -725,8 +725,8 @@ fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize {
// A directory that is not there runs nothing, as Term makes nothing
// there: no pane, and the write fails ENOENT.
if (missingDir(p, dir)) {
- var said: [pardes.memory.limits.host_path_cap + 48]u8 = undefined;
- p.reportFailure(from, std.fmt.bufPrint(&said, "exec: {s}: no such directory", .{dir[0..@min(dir.len, pardes.memory.limits.host_path_cap)]}) catch unreachable); // cap and 27 fit
+ var said: pardes.Kind.Buf(pardes.memory.limits.host_path_cap + 48) = .{};
+ p.reportFailure(from, said.print("exec: {s}: no such directory", .{dir[0..@min(dir.len, pardes.memory.limits.host_path_cap)]}));
return null;
}
// Not one whose pty a job it left behind still prints to: reusing it
@@ -844,9 +844,9 @@ pub fn commandDone(p: *Pardes, id: usize, status: ?u8) void {
}
var buf: [16]u8 = undefined;
const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit status fits 16
- var said: [32]u8 = undefined;
+ var said: pardes.Kind.Buf(32) = .{};
const lead = if (panes.terminal.gridCursor(pane).x != 0) "\r\n" else "";
- panes.terminal.feedOutput(p, pane, std.fmt.bufPrint(&said, "{s}exit {s}\r\n", .{ lead, code }) catch unreachable); // a literal, the [16]u8 code and 7 fit 32
+ panes.terminal.feedOutput(p, pane, said.print("{s}exit {s}\r\n", .{ lead, code }));
noteRun(p, pane, "exit", code);
p.needs_frame = true;
}
@@ -898,8 +898,8 @@ pub fn executeBuiltinLine(p: *Pardes, id: usize, txt: []const u8) bool {
const cmd = for (acme_words) |w| {
if (!std.mem.eql(u8, raw[0..word_end], w.acme)) continue;
const now = w.pardes orelse {
- var said: [128]u8 = undefined;
- p.reportFailure(id, std.fmt.bufPrint(&said, "invalid: acme's {s} is not a pardes builtin{s}", .{ w.acme, w.hint }) catch unreachable); // acme_words holds short literals
+ var said: pardes.Kind.Buf(128) = .{};
+ p.reportFailure(id, said.print("invalid: acme's {s} is not a pardes builtin{s}", .{ w.acme, w.hint }));
return true;
};
// Delete: Del, the text thrown away unasked.
@@ -964,9 +964,9 @@ fn applyInitText(p: *Pardes, text: []const u8, settings_only: bool) void {
if (known and p.fs.failures == failures) continue;
// Never silent: a word it has not, or one that failed, is a notice
// on the message row and an err in the log, with its line.
- var why_buf: [320]u8 = undefined;
+ var why_buf: pardes.Kind.Buf(320) = .{};
const why: []const u8 = if (!known)
- std.fmt.bufPrint(&why_buf, "unknown word \"{s}\"", .{word[0..@min(word.len, 64)]}) catch unreachable // 64 fit 320
+ why_buf.print("unknown word \"{s}\"", .{word[0..@min(word.len, 64)]})
else if (p.fs.said_len > 0) p.fs.said[0..p.fs.said_len] else "failed";
var said: pardes.Kind.Buf(400) = .{};
const line_said = said.print("init file line {d}: {s}", .{ number, why });
@@ -985,8 +985,8 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?
// A window's own word in a terminal's view (Fonts, Lift): said, as a
// word a build lacks is, and never run.
if (!builtins.registry.here(p, b)) {
- var said: [96]u8 = undefined;
- return p.reportFailure(id, std.fmt.bufPrint(&said, "{s} is GUI-only, invalid here", .{@tagName(b)}) catch unreachable); // a builtin's name is 15 at most
+ var said: pardes.Kind.Buf(96) = .{};
+ return p.reportFailure(id, said.print("{s} is GUI-only, invalid here", .{@tagName(b)}));
}
// No pane at all (the window Delcol emptied): a word runs all the same,
// with a stand-in that is no pane (New, Newcol, Exit are what make sense).
@@ -1004,8 +1004,8 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?
// A word for one kind of pane, on another: refused with why, not a
// silent nothing (Palette on a file, Filter on a PDF).
if (builtins.registry.needs(b)) |kind| if (p.panes[id] == null or !kind.has(pane)) {
- var said: [96]u8 = undefined;
- return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: only {s} pane takes it", .{ @tagName(b), kind.noun() }) catch unreachable); // an enum's name and a literal noun fit 96
+ var said: pardes.Kind.Buf(96) = .{};
+ return p.reportFailure(id, said.print("{s}: only {s} pane takes it", .{ @tagName(b), kind.noun() }));
};
const c: builtins.Ctx = .{ .p = p, .pane = pane, .id = id, .txt = txt, .arg = arg, .from_body = from_body };
builtins.registry.dispatch(b, c);
@@ -1044,8 +1044,8 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]
p.settings.shell.requested.clear();
p.settings.shell.pending = true;
if (!p.announce) return;
- var said: [320]u8 = undefined;
- return p.setMessage(v.active, std.fmt.bufPrint(&said, "Shell: the default again, {s} ($SHELL, else /bin/sh)", .{config.defaultShell()[0..@min(config.defaultShell().len, 256)]}) catch unreachable); // 256 and 53 fit 320
+ var said: pardes.Kind.Buf(320) = .{};
+ return p.setMessage(v.active, said.print("Shell: the default again, {s} ($SHELL, else /bin/sh)", .{config.defaultShell()[0..@min(config.defaultShell().len, 256)]}));
}
var why: [320]u8 = undefined;
if (pardes.tape.value(.shell, @import("host_io.zig").Shell.refusal, .{ want[0..@min(want.len, 200)], &why })) |refused| {
@@ -1056,11 +1056,11 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]
},
// Bare, each says its value, as acme's Tab says the width.
inline .tab, .callstack_depth => |_, tag| if (arg == null) {
- var said: [40]u8 = undefined;
- return p.setMessage(v.active, std.fmt.bufPrint(&said, "{s} {d}", .{ setting.word, @field(p.settings, @tagName(tag)) }) catch unreachable); // a setting's word is 14 at most
+ var said: pardes.Kind.Buf(40) = .{};
+ return p.setMessage(v.active, said.print("{s} {d}", .{ setting.word, @field(p.settings, @tagName(tag)) }));
} else if (!p.settings.apply(setting, arg)) {
- var said: [96]u8 = undefined;
- p.reportFailure(v.active, std.fmt.bufPrint(&said, "{s}{s}: takes {s}", .{ setting.word, if (tag == .tab) ": invalid tab width" else "", comptime config.Runtime.takes(tag).? }) catch unreachable); // a comptime word and two literals fit 96
+ var said: pardes.Kind.Buf(96) = .{};
+ p.reportFailure(v.active, said.print("{s}{s}: takes {s}", .{ setting.word, if (tag == .tab) ": invalid tab width" else "", comptime config.Runtime.takes(tag).? }));
} else if (tag == .tab) {
config.tab_now = p.settings.tab;
},
diff --git a/src/host_io.zig b/src/host_io.zig
index 6ce26e41..9e0292b3 100644
--- a/src/host_io.zig
+++ b/src/host_io.zig
@@ -231,8 +231,8 @@ pub const Adoptions = struct {
/// takes this pty instead of forking a shell (`take`).
pub fn adoptShell(a: *Adoptions, core: *pardes.Pardes, pid: libc.pid_t, fd: c_int) void {
if (pid == 0) {
- var buf: [96]u8 = undefined;
- return core.setMessage(core.view().active, if (a.taken == 0) "Adopt: no shell of a session that died is waiting" else std.fmt.bufPrint(&buf, "Adopt: {d} shell{s} taken in; what they showed is gone", .{ a.taken, if (a.taken == 1) "" else "s" }) catch unreachable); // a count fits 96
+ var buf: pardes.Kind.Buf(96) = .{};
+ return core.setMessage(core.view().active, if (a.taken == 0) "Adopt: no shell of a session that died is waiting" else buf.print("Adopt: {d} shell{s} taken in; what they showed is gone", .{ a.taken, if (a.taken == 1) "" else "s" }));
}
if (a.len < a.list.len) {
a.list[a.len] = .{ .pid = pid, .fd = fd, .pane = null };
@@ -246,8 +246,8 @@ pub const Adoptions = struct {
}
// No room for it: its master goes, and the shell with this session.
_ = libc.close(fd);
- var buf: [96]u8 = undefined;
- core.setMessage(core.view().active, std.fmt.bufPrint(&buf, "Adopt: no room for shell {d}; it ends with this session", .{pid}) catch unreachable); // a pid fits 96
+ var buf: pardes.Kind.Buf(96) = .{};
+ core.setMessage(core.view().active, buf.print("Adopt: no room for shell {d}; it ends with this session", .{pid}));
}
/// The adopted shell pane `pane`'s spawn takes, off the list.
diff --git a/src/keys.zig b/src/keys.zig
index 5ebdc046..33760b8b 100644
--- a/src/keys.zig
+++ b/src/keys.zig
@@ -90,8 +90,8 @@ pub fn questionChoices(p: *const Pardes, id: usize, buf: []u8) ?[]const u8 {
const ask = p.repl_ask orelse return null;
var w = std.Io.Writer.fixed(buf);
for (ask.offered, 0..) |serial, i| if (serial != 0) {
- if (w.buffered().len > 0) w.writeByte(' ') catch unreachable; // 26 letters and spaces fit 64
- w.writeByte(@intCast('a' + i)) catch unreachable; // [26]u32 offered: 51 bytes fit 64
+ if (w.buffered().len > 0) w.writeByte(' ') catch break; // the letters that fit
+ w.writeByte(@intCast('a' + i)) catch break; // the letters that fit
};
return w.buffered();
},
diff --git a/src/layout.zig b/src/layout.zig
index 3475dbbf..188ac2b8 100644
--- a/src/layout.zig
+++ b/src/layout.zig
@@ -1739,9 +1739,8 @@ pub fn newColumn(p: *Pardes, from_id: usize) void {
const before = p.view().rects;
// Said, not silently nothing: "no space" is 9ns's word for ENOSPC.
const c = insertColumnUnannounced(p, col, false) orelse {
- var said: [96]u8 = undefined;
return p.reportFailure(from_id, if (p.view().ncol >= MAX_COLS)
- std.fmt.bufPrint(&said, "Newcol: no space for a column: {d} max", .{MAX_COLS}) catch unreachable // an integer and 34 bytes fit 96
+ std.fmt.comptimePrint("Newcol: no space for a column: {d} max", .{MAX_COLS})
else
"Newcol: no space for a column: this one is too narrow to split");
};
diff --git a/src/look.zig b/src/look.zig
index aee96513..0414f6d1 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -1295,9 +1295,9 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text:
// that is gone, else the file named.
if (filesystem.dotRelative(trimmed)) {
const dir = Pardes.paneDir(pane);
- var said: [4096 + 104]u8 = undefined;
+ var said: Kind.Buf(4096 + 104) = .{};
const gone = if (filesystem.localPath(dir)) |local| exec.kindOf(local) != .directory else false;
- if (gone) return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch unreachable); // 4096 + 27 fits 4096 + 104
+ if (gone) return p.reportFailure(id, said.print("look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}));
// A file not there is a miss, as `x` and `/abs/x` are: said and
// logged, the write answered with nothing.
var cut: [miss_path_cap + "…".len]u8 = undefined;
@@ -1755,8 +1755,8 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
// A directory that is not there (the pane's own, gone): said,
// ENOENT, no terminal made in it.
if (filesystem.localPath(dir)) |local| if (exec.kindOf(local) != .directory) {
- var said: [4096 + 104]u8 = undefined;
- return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}) catch unreachable); // 4096 + 27 fits 4096 + 104
+ var said: Kind.Buf(4096 + 104) = .{};
+ return p.reportFailure(id, said.print("look: {s}: no such directory", .{dir[0..@min(dir.len, 4096)]}));
};
// acme's: a pane listing it (Dir.zig).
panes.Dir.look(p, id, dir);
diff --git a/src/lsp/Ask.zig b/src/lsp/Ask.zig
index 6b5dd8c8..b00a3384 100644
--- a/src/lsp/Ask.zig
+++ b/src/lsp/Ask.zig
@@ -45,22 +45,22 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
// file, place and argument -- from wherever it is run.
const last_pane: ?usize = if (kind == .explain) (if (p.lsp_ask.last) |last| p.paneBySerial(last.serial) else null) else null;
const id = last_pane orelse asked;
- var said: [160]u8 = undefined;
+ var said: pardes.Kind.Buf(160) = .{};
if (!lsp.supports.contains(kind))
- return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: no language server here answers it", .{lspWord(kind)}) catch unreachable); // a word and 45 fit 160
+ return p.reportFailure(id, said.print("{s}: no language server here answers it", .{lspWord(kind)}));
const pane = p.panes[id] orelse return;
if (kind != .status) {
const f = pane.file orelse
- return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: only a file's pane asks a language server", .{lspWord(kind)}) catch unreachable); // a word and 45 fit 160
+ return p.reportFailure(id, said.print("{s}: only a file's pane asks a language server", .{lspWord(kind)}));
if (f.output != null)
- return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: only a file's pane asks a language server", .{lspWord(kind)}) catch unreachable); // a word and 45 fit 160
+ return p.reportFailure(id, said.print("{s}: only a file's pane asks a language server", .{lspWord(kind)}));
}
- if (arg.len > 128) return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: its argument is at most 128 bytes", .{lspWord(kind)}) catch unreachable); // a word and 45 fit 160
+ if (arg.len > 128) return p.reportFailure(id, said.print("{s}: its argument is at most 128 bytes", .{lspWord(kind)}));
if (kind == .rename) {
const zig_buf = if (pane.file) |f| std.mem.endsWith(u8, f.path, ".zig") else true;
if ((zig_buf and (!std.zig.isValidId(arg) or std.zig.isUnderscore(arg))) or
(!zig_buf and std.mem.indexOfAny(u8, arg, " \t\r\n\"\\") != null))
- return p.reportFailure(id, std.fmt.bufPrint(&said, "Rename: {s} is no name", .{arg[0..@min(arg.len, 128)]}) catch unreachable); // 128 and 19 fit 160
+ return p.reportFailure(id, said.print("Rename: {s} is no name", .{arg}));
}
var off = if (pane.file) |f| modal.offsetAt(f.content, .{
.row = @intCast(@max(0, pane.body.cur_row)),
@@ -83,17 +83,17 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8)
}
}
off = nearest orelse
- return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: no {s} in this file", .{ lspWord(kind), arg[0..@min(arg.len, 128)] }) catch unreachable); // a literal word, 128 and 18 fit 160
+ return p.reportFailure(id, said.print("{s}: no {s} in this file", .{ lspWord(kind), arg }));
arg = "";
}
// Lspwhy asks the last query again, narrated: its kind and argument,
// at its place when asked from its pane. None yet: a definition.
- var explained: [160]u8 = undefined;
+ var explained: pardes.Kind.Buf(160) = .{};
var sent = arg;
var at = off;
if (kind == .explain) {
if (p.lsp_ask.last) |last| {
- sent = std.fmt.bufPrint(&explained, "{s} {s}", .{ @tagName(last.kind), last.arg.slice() }) catch unreachable; // an enum's name and a Buf(128) fit 160
+ sent = explained.print("{s} {s}", .{ @tagName(last.kind), last.arg.slice() });
if (last_pane != null) at = last.offset;
}
} else if (kind != .status) p.lsp_ask.last = .{ .kind = kind, .arg = .from(arg), .serial = pane.serial, .offset = @intCast(off) };
@@ -273,13 +273,13 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
// its pane -- fails a 9P write that asked it too.
const failures = p.fs.failures;
defer if (p.fs.failures != failures) p.noteLateFailure(w.pane);
- var said: [256]u8 = undefined;
+ var said: pardes.Kind.Buf(256) = .{};
const rows = response orelse
- return p.reportFailure(w.pane, std.fmt.bufPrint(&said, "{s}: the language server did not answer", .{lspWord(w.kind)}) catch unreachable); // a literal word and 40 fit 256
+ return p.reportFailure(w.pane, said.print("{s}: the language server did not answer", .{lspWord(w.kind)}));
// A backend that cannot answer it says why (`@none <why>`).
if (std.mem.startsWith(u8, rows, "@none ")) {
const why = std.mem.trimEnd(u8, rows["@none ".len..], "\n");
- return p.reportFailure(w.pane, std.fmt.bufPrint(&said, "{s}: {s}", .{ lspWord(w.kind), why[0..@min(why.len, 200)] }) catch unreachable); // 200 fit 256
+ return p.reportFailure(w.pane, said.print("{s}: {s}", .{ lspWord(w.kind), why }));
}
// Index's answer is its indexer's command line, run in a command
// pane (lsp_client.indexCommand).
@@ -291,9 +291,9 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
const fallback: ?[]const u8 = if (w.kind == .rename) w.arg.slice() else null;
if (parseLspEdits(p, rows, fallback)) |edits| {
if (applyLspEdits(p, pane, w.revision, edits)) {
- var buf: [64]u8 = undefined;
+ var buf: pardes.Kind.Buf(64) = .{};
const verb: []const u8 = if (w.kind == .rename) "renamed" else "formatted";
- p.setMessage(w.pane, std.fmt.bufPrint(&buf, "{s} {d} range(s)", .{ verb, edits.len }) catch unreachable); // a literal and a usize fit 64
+ p.setMessage(w.pane, buf.print("{s} {d} range(s)", .{ verb, edits.len }));
}
return;
}
@@ -311,13 +311,13 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
const none: ?[]const u8 = switch (w.kind) {
.completion, .format => null,
.rename => "nothing here to rename",
- .diagnostics, .workspace_diagnostics => return p.setMessage(w.pane, std.fmt.bufPrint(&said, "{s}: none", .{lspWord(w.kind)}) catch unreachable), // a literal word fits 256
+ .diagnostics, .workspace_diagnostics => return p.setMessage(w.pane, said.print("{s}: none", .{lspWord(w.kind)})),
.incoming_calls => "callers not found",
.outgoing_calls => "callees not found",
.hover => "nothing to show: not found",
else => "not found",
};
- if (none) |text| p.reportFailure(w.pane, std.fmt.bufPrint(&said, "{s}: {s}", .{ lspWord(w.kind), text }) catch unreachable); // two literals fit 256
+ if (none) |text| p.reportFailure(w.pane, said.print("{s}: {s}", .{ lspWord(w.kind), text }));
return;
}
@@ -347,8 +347,8 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
else => false,
};
if (listing and !p.look_missed) {
- var where: [300]u8 = undefined;
- p.setMessage(v.active, std.fmt.bufPrint(&where, "{s}: the one, {s}", .{ lspWord(w.kind), place[0..@min(place.len, 240)] }) catch unreachable); // 240 fit 300
+ var where: pardes.Kind.Buf(300) = .{};
+ p.setMessage(v.active, where.print("{s}: the one, {s}", .{ lspWord(w.kind), place }));
}
return;
}
@@ -394,14 +394,14 @@ pub fn lspResponse(p: *Pardes, id: u32, response: ?[]const u8) void {
};
}
if (w.kind == .rename) {
- var said_buf: [128]u8 = undefined;
+ var said_buf: pardes.Kind.Buf(128) = .{};
// Rows that only name a file the server left alone (lsp_client
// renameEdits) are no edits.
const unrenamed = std.mem.count(u8, rows, ", which the server did not rename\n");
p.setMessage(w.pane, if (unrenamed > 0)
- std.fmt.bufPrint(&said_buf, "Rename: previewed, not applied: the server renamed in this file only, and {d} other open file(s) say the name", .{unrenamed}) catch unreachable // a usize and 106 fit 128
+ said_buf.print("Rename: previewed, not applied: the server renamed in this file only, and {d} other open file(s) say the name", .{unrenamed})
else
- std.fmt.bufPrint(&said_buf, "Rename: {d} edit(s) across files, previewed, not applied", .{nrows}) catch unreachable); // a usize and 50 fit 128
+ said_buf.print("Rename: {d} edit(s) across files, previewed, not applied", .{nrows}));
}
if (panes.Output.traits(from).jumps) {
const result = p.panes[pane.search_pane orelse return] orelse return;
diff --git a/src/lsp/lsp_client.zig b/src/lsp/lsp_client.zig
index ef531f30..76be6f45 100644
--- a/src/lsp/lsp_client.zig
+++ b/src/lsp/lsp_client.zig
@@ -2501,7 +2501,7 @@ fn frame(c: *Conn, io: std.Io, sock: c_int, body: []const u8, deadline: i64) Err
/// dropped, and the server's request goes unanswered).
fn answerServer(c: *Conn, io: std.Io, sock: c_int, body: []const u8) void {
var hdr: [64]u8 = undefined;
- const h = std.fmt.bufPrint(&hdr, "Content-Length: {d}\r\n\r\n", .{body.len}) catch unreachable; // a usize and 20 fit 64
+ const h = std.fmt.bufPrint(&hdr, "Content-Length: {d}\r\n\r\n", .{body.len}) catch unreachable; // a usize's 20 digits and a short header fit 64
c.replies_mu.lockUncancelable(io);
const half = &c.replies[c.filling];
const len = &c.replies_len[c.filling];
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.
diff --git a/src/terminal.zig b/src/terminal.zig
index 8249ee09..5338afa7 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -777,7 +777,7 @@ pub fn mouseBytes(pane: *Pane, buf: *[64]u8, action: MouseAction, button: ?Mouse
} else null,
.mods = .{ .shift = mods.shift, .alt = mods.alt, .ctrl = mods.ctrl },
.pos = .{ .x = @as(f32, @floatFromInt(col)) + 0.5, .y = @as(f32, @floatFromInt(row)) + 0.5 },
- }, opts) catch unreachable; // a mouse report is at most 31 bytes
+ }, opts) catch return &.{}; // no report rather than half of one
return writer.buffered();
}