summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Dir.zig8
-rw-r--r--src/Jump.zig2
-rw-r--r--src/Messages.zig6
-rw-r--r--src/Output.zig14
-rw-r--r--src/Pipe.zig18
-rw-r--r--src/builtins.zig76
-rw-r--r--src/edit_cmd.zig28
-rw-r--r--src/exec.zig71
8 files changed, 116 insertions, 107 deletions
diff --git a/src/Dir.zig b/src/Dir.zig
index d8d4d9b0..65e18c1a 100644
--- a/src/Dir.zig
+++ b/src/Dir.zig
@@ -39,7 +39,7 @@ pub fn ofName(name: []const u8) []const u8 {
const dir = std.mem.trimEnd(u8, name, "/");
return if (dir.len == 0) "/" else dir;
}
- return std.fs.path.dirname(name) orelse "/";
+ return std.Io.Dir.path.dirname(name) orelse "/";
}
/// The entries of directory `dir` on this host as acme lists them
@@ -105,7 +105,7 @@ fn readHost(gpa: std.mem.Allocator, local: []const u8) ![]u8 {
/// first, every column as wide as the widest entry and a cell more,
/// rounded up to a tab, and each row ending in a newline. Blanks pad where
/// acme's tabs do: a pardes tab is a fixed width, not a stop.
-pub fn columnate(gpa: std.mem.Allocator, entries: []const []const u8, width: usize) ![]u8 {
+pub fn columnate(gpa: std.mem.Allocator, entries: []const []const u8, width: usize) error{OutOfMemory}![]u8 {
var colw: usize = 0;
for (entries) |entry| {
const w = File.displayWidth(entry) + 1;
@@ -194,7 +194,7 @@ pub fn look(p: *Pardes, from: usize, dir: []const u8) void {
return show(p, from, i);
}
var said: [limits.host_path_cap + 16]u8 = undefined;
- const what = std.fmt.bufPrint(&said, "look: {s}", .{name[0..@min(name.len, limits.host_path_cap)]}) catch "look";
+ const what = std.fmt.bufPrint(&said, "look: {s}", .{name[0..@min(name.len, limits.host_path_cap)]}) catch unreachable; // cap and 6 fit
const names = read(p.gpa, dir) catch |err| {
p.gpa.free(name);
return p.reportError(from, what, err);
@@ -240,7 +240,7 @@ pub fn show(p: *Pardes, from: usize, id: usize) void {
const serial = pane.serial;
var said: [limits.host_path_cap + 16]u8 = undefined;
const name = pane.file.?.path;
- const what = std.fmt.bufPrint(&said, "look: {s}", .{name[0..@min(name.len, limits.host_path_cap)]}) catch "look";
+ const what = std.fmt.bufPrint(&said, "look: {s}", .{name[0..@min(name.len, limits.host_path_cap)]}) catch unreachable; // cap and 6 fit
refresh(p, id) catch |err| return p.reportError(from, what, err);
// Closed while the turn was out: nothing to give the keyboard to.
const now = p.panes[id] orelse return;
diff --git a/src/Jump.zig b/src/Jump.zig
index 10014e9e..2603d672 100644
--- a/src/Jump.zig
+++ b/src/Jump.zig
@@ -302,7 +302,7 @@ pub fn jumpBy(p: *Pardes, delta: i32) void {
// 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}) catch "deleted, skipped");
+ 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
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 ad91cf8d..80e7ab07 100644
--- a/src/Messages.zig
+++ b/src/Messages.zig
@@ -118,7 +118,7 @@ pub const Message = struct {
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 {};
+ _ = 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
return text;
}
@@ -435,7 +435,9 @@ pub fn errorWords(err: anyerror, buf: []u8) []const u8 {
pub fn zonWhy(diag: *const std.zon.parse.Diagnostics, buf: []u8) []const u8 {
if (diag.errors.len == 0) return "not valid ZON";
const first = diag.errors[0];
- return std.fmt.bufPrint(buf, "line {d}: {s}", .{ first.loc.line + 1, first.msg }) catch "not valid ZON";
+ var w: std.Io.Writer = .fixed(buf);
+ w.print("line {d}: {s}", .{ first.loc.line + 1, first.msg }) catch {}; // a long message is cut at the room's end
+ return w.buffered();
}
test "errors are said in words, and a ZON failure names its line" {
diff --git a/src/Output.zig b/src/Output.zig
index 20d672d2..ceffa7d9 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -485,7 +485,7 @@ pub fn fillResults(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []
const output = if (rf.output) |*o| o else continue;
if (!std.meta.eql(output.from, from)) continue;
if (by_arg and !std.mem.eql(u8, output.arg(), arg)) continue;
- if (!std.mem.eql(u8, std.fs.path.dirname(rf.path) orelse "", dir)) continue;
+ if (!std.mem.eql(u8, std.Io.Dir.path.dirname(rf.path) orelse "", dir)) continue;
if (!locations.sameInput(content, rf.content, rf.location_rows, p.locations_config.layout)) continue;
try setArg(output, arg);
p.gpa.free(content);
@@ -534,7 +534,7 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con
if (i == id and !shared) continue;
if (!shared and !std.meta.eql(o.from, from)) continue;
if (!shared and by_arg and !std.mem.eql(u8, o.arg(), arg)) continue;
- if (!std.mem.eql(u8, std.fs.path.dirname(rf.path) orelse "", dir)) continue;
+ if (!std.mem.eql(u8, std.Io.Dir.path.dirname(rf.path) orelse "", dir)) continue;
o.from = from;
p.fs.refilled = rp.serial;
try setArg(o, arg);
@@ -582,7 +582,7 @@ pub fn fillRows(p: *Pardes, id: usize, dir: []const u8, from: Origin, arg: []con
/// stands elsewhere), for Diff to go back to it. The +Diff's id;
/// NoHunks when there is none in it.
pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !usize {
- const dir = std.fs.path.dirname(path) orelse p.sessionDir();
+ const dir = std.Io.Dir.path.dirname(path) orelse p.sessionDir();
const root = hunks.sourceRoot(p, dir, content);
const result = try hunks.format(p, root, content);
errdefer {
@@ -592,7 +592,7 @@ pub fn openDiff(p: *Pardes, id: usize, path: []const u8, content: []const u8) !u
var has_hunk = false;
for (result.rows) |row| has_hunk = has_hunk or row.kind == .match;
if (!has_hunk) return error.NoHunks;
- const arg = if (std.mem.eql(u8, root, dir) or path.len > max_arg) std.fs.path.basename(path) else path;
+ const arg = if (std.mem.eql(u8, root, dir) or path.len > max_arg) std.Io.Dir.path.basename(path) else path;
return fillRows(p, id, root, .{ .cmd = .Diff }, arg, result.content, result.rows, null);
}
@@ -622,7 +622,7 @@ pub fn diffSource(p: *Pardes, f: *const File.State) ?[]const u8 {
if (!std.meta.eql(o.from, Origin{ .cmd = .Diff })) return null;
const arg = o.arg();
if (arg.len > 0 and arg[0] == '/') return arg;
- return std.fs.path.join(p.scratch.allocator(), &.{ std.fs.path.dirname(f.path) orelse "", arg }) catch null;
+ return std.Io.Dir.path.join(p.scratch.allocator(), &.{ std.Io.Dir.path.dirname(f.path) orelse "", arg }) catch null;
}
pub fn openJumps(p: *Pardes, id: usize) !void {
@@ -718,7 +718,7 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void {
// goes in the session's, where a look from it can still resolve.
const dir = if (pardes.filesystem.localPath(own)) |local| (if (exec.kindOf(local) == .directory) own else p.sessionDir()) else own;
const free = p.freeSlot() orelse return p.gpa.free(content);
- _ = open(p, free, dir, .unsaved, "", content) catch return;
+ _ = open(p, free, dir, .unsaved, "", content) catch |err| return p.reportError(id, "+Unsaved", err);
exec.placeNew(p, id, id, free, .doc);
p.view().active = id;
}
@@ -731,7 +731,7 @@ pub fn openUnsaved(p: *Pardes, id: usize, content: []u8) void {
/// when it has no room at all.
pub fn openPager(p: *Pardes, from: usize, dir_arg: []const u8) !usize {
const dir = if (dir_arg.len > 0 and dir_arg[0] == '/') dir_arg else p.sessionDir();
- const path = try std.fs.path.join(p.gpa, &.{ dir, "+Pager" });
+ const path = try std.Io.Dir.path.join(p.gpa, &.{ dir, "+Pager" });
const free = p.freeSlot() orelse {
p.gpa.free(path);
return error.NoPaneSlots;
diff --git a/src/Pipe.zig b/src/Pipe.zig
index e7895c0d..87768f22 100644
--- a/src/Pipe.zig
+++ b/src/Pipe.zig
@@ -103,7 +103,7 @@ pub fn submitPipe(p: *Pardes, id: usize) void {
const f = pane.file orelse return;
if (!panes.Output.fileTraits(f.output).saves) return;
}
- const content = edit.flatSurface(p, t) catch return;
+ const content = edit.flatSurface(p, t) catch |err| return p.reportError(id, "pipe", err);
const how = switch (pane.prompt) {
.pipe => |pipe| pipe,
else => return,
@@ -174,11 +174,11 @@ fn pipeFailed(p: *Pardes, wait: *const PendingPipe, failure: ?selection_pipe.Fai
var out: std.Io.Writer.Allocating = .init(p.gpa);
defer out.deinit();
const w = &out.writer;
- w.print("| {s}\n\n", .{wait.command}) catch return;
+ w.print("| {s}\n\n", .{wait.command}) catch |err| return p.reportError(wait.pane, "pipe", err);
if (wait.inputs.len > 1) if (failure) |fail|
- w.print("selection {d} of {d}: ", .{ fail.index + 1, wait.inputs.len }) catch return;
- writeFailure(w, failure) catch return;
- const content = out.toOwnedSlice() catch return;
+ w.print("selection {d} of {d}: ", .{ fail.index + 1, wait.inputs.len }) catch |err| return p.reportError(wait.pane, "pipe", err);
+ writeFailure(w, failure) catch |err| return p.reportError(wait.pane, "pipe", err);
+ const content = out.toOwnedSlice() catch |err| return p.reportError(wait.pane, "pipe", err);
const was = p.view().active;
panes.Output.openErrors(p, wait.pane, content) catch |err| {
p.gpa.free(content);
@@ -191,7 +191,7 @@ fn pipeFailed(p: *Pardes, wait: *const PendingPipe, failure: ?selection_pipe.Fai
/// How a filter failed, a line, and the command's stderr after it: what
/// +Errors says of a `|` and of an Edit's `< | >`.
-pub fn writeFailure(w: *std.Io.Writer, failure: ?selection_pipe.Failure) !void {
+pub fn writeFailure(w: *std.Io.Writer, failure: ?selection_pipe.Failure) std.Io.Writer.Error!void {
const fail = failure orelse {
// No diagnosis at all: nobody ran it. The detached daemon leaves
// `pipe` null on purpose.
@@ -267,7 +267,7 @@ pub fn pipeResponse(
.workspace => &p.global_tag,
.input => return,
};
- const content = edit.flatSurface(p, t) catch return;
+ const content = edit.flatSurface(p, t) catch |err| return p.reportError(wait.pane, "pipe", err);
const changed = if (t.what == .body) changed: {
const f = pane.file orelse return;
if (!panes.Output.fileTraits(f.output).saves) return;
@@ -301,12 +301,12 @@ 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 return;
+ total_output = std.math.add(usize, total_output, output.len) catch unreachable; // both are capped far below a usize's room
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 };
}
- const replacement = sam.apply(p.gpa, content, ops[0..n]) catch return;
+ const replacement = sam.apply(p.gpa, content, ops[0..n]) catch |err| return p.reportError(wait.pane, "pipe", err);
var new_ranges: [panes.Text.max_selections]modal.Selection = undefined;
var delta: isize = 0;
for (ops[0..n], wait.ranges[0..n], new_ranges[0..n]) |op, range, *moved| {
diff --git a/src/builtins.zig b/src/builtins.zig
index ada02e0c..76fb959d 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -594,14 +594,14 @@ pub fn warnModifiedIn(c: Ctx, asking: Pane.Discarding, which: Asked) bool {
// 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 "unsaved panes");
+ 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
}
if (count > 0 and (c.p.fs.no_prompt or c.p.fs.capturing)) {
var said_buf: [limits.host_path_cap + 96]u8 = undefined;
const said = (if (count == 1)
std.fmt.bufPrint(&said_buf, "{s}: Modified ({s} again to discard)", .{ one, @tagName(asking) })
else
- std.fmt.bufPrint(&said_buf, "{d} unsaved panes: Modified ({s} again to discard)", .{ count, @tagName(asking) })) catch "unsaved panes: Modified";
+ std.fmt.bufPrint(&said_buf, "{d} unsaved panes: Modified ({s} again to discard)", .{ count, @tagName(asking) })) catch unreachable; // one is one_buf's at most
var room: @TypeOf(c.p.fs.failure) = undefined;
const kept = pardes.ctlfs.fitErr(said, &room);
@memcpy(c.p.fs.failure[0..kept.len], kept);
@@ -707,7 +707,7 @@ pub const Restore = struct {
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 "Restore: no dump of that label" else "Restore: no dump yet; name one");
+ 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
};
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:
@@ -715,7 +715,7 @@ pub const Restore = struct {
// First, so a Restore that could never happen spends no warning.
if (file) |path| {
const bytes = @import("fs.zig").readFile(c.p.gpa, path) catch |err| {
- var buf: [limits.host_path_cap + 64]u8 = undefined;
+ var buf: [limits.host_path_cap + 160]u8 = undefined;
var words: [128]u8 = undefined;
const why = switch (err) {
error.FileNotFound => "no such file",
@@ -723,7 +723,7 @@ pub const Restore = struct {
error.IsDirectory => "a directory, not a dump",
else => pardes.Messages.errorWords(err, &words),
};
- return c.p.reportFailure(c.id, std.fmt.bufPrint(&buf, "Restore: {s}: {s}", .{ path, why }) catch "Restore: cannot read the dump");
+ return c.p.reportFailure(c.id, std.fmt.bufPrint(&buf, "Restore: {s}: {s}", .{ path[0..@min(path.len, limits.host_path_cap)], why }) catch unreachable); // cap and 128 fit
};
defer c.p.gpa.free(bytes);
// Nor does a file that is not a dump, before any warning.
@@ -731,7 +731,7 @@ pub const Restore = struct {
pardes.dump.check(c.p.gpa, bytes, &why_buf) catch |err| {
var buf: [limits.host_path_cap + 320]u8 = undefined;
const why = if (err == error.OutOfMemory) pardes.Messages.errorWords(err, &why_buf) else why_buf[0..std.mem.indexOfScalar(u8, &why_buf, 0).?];
- return c.p.reportFailure(c.id, std.fmt.bufPrint(&buf, "Restore: {s}: not a pardes dump: {s}", .{ path, why }) catch "Restore: not a pardes dump");
+ return c.p.reportFailure(c.id, std.fmt.bufPrint(&buf, "Restore: {s}: not a pardes dump: {s}", .{ path[0..@min(path.len, limits.host_path_cap)], why }) catch unreachable); // cap and 256 fit
};
}
// acme's Load adds a dump's windows to the ones there; a Restore
@@ -788,7 +788,7 @@ pub const Mount = struct {
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 "Mount: bad dial address");
+ 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
return c.p.reportError(c.id, "Mount", err);
};
// A socket path that is not there: said so (ENOENT), not a dial
@@ -800,7 +800,7 @@ pub const Mount = struct {
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, path[0..@min(path.len, 100)] }) catch "Mount: no such socket");
+ 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
};
// A mount that cannot be reached is said now, and taken back, not
// found out by the first look through it.
@@ -811,7 +811,7 @@ pub const Mount = struct {
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, dial[0..@min(dial.len, 100)] }) catch "Mount", err);
+ 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
};
}
};
@@ -829,7 +829,7 @@ pub const Unmount = struct {
// "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 "Unmount: no such mount");
+ 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
}
return c.p.reportError(c.id, "Unmount", err);
};
@@ -879,7 +879,7 @@ pub const ThemeFile = struct {
// 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 "ThemeFile: invalid theme path: a theme file is a .zon");
+ 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
}
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: [96]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 "invalid argument");
+ 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
return null;
};
}
@@ -1057,22 +1057,22 @@ pub const Get = struct {
if (!panes.Output.fileTraits(f.output).saves) return c.p.reportFailure(c.id, "Get: only a file pane takes it");
var failed: anyerror = error.Unexpected;
var home_buf: [4096]u8 = undefined;
- const path = if (typed.len == 0) c.pane.file.?.path else std.fs.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(typed, &home_buf) }) catch return;
+ const path = if (typed.len == 0) c.pane.file.?.path else std.Io.Dir.path.resolvePosix(c.p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(typed, &home_buf) }) catch |err| return c.p.reportError(c.id, "Get", err);
// 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;
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 "Get: no such file");
+ 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
};
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);
if (errno != 0) {
- var said: [320]u8 = undefined;
+ var said: [400]u8 = undefined;
var words: [128]u8 = undefined;
const why = if (failed == error.FileNotFound) "no such file" else pardes.Messages.errorWords(failed, &words);
- c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Get: {s}: {s}", .{ path[0..@min(path.len, 256)], why }) catch "Get: cannot be read");
+ c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Get: {s}: {s}", .{ path[0..@min(path.len, 256)], why }) catch unreachable); // 256 and 128 fit 400
}
}
};
@@ -1118,20 +1118,20 @@ pub const Incl = struct {
const shown = dir_word[0..@min(dir_word.len, 200)];
if (std.mem.eql(u8, dir_word, "-")) return p.reportFailure(c.id, "Incl: invalid: - clears the list, alone");
if (dir_word[0] != '/' and dir_word[0] != '~')
- return p.reportFailure(c.id, std.fmt.bufPrint(&said, "Incl: invalid directory: {s} is relative", .{shown}) catch "Incl: invalid directory");
+ return p.reportFailure(c.id, std.fmt.bufPrint(&said, "Incl: invalid directory: {s} is relative", .{shown}) catch unreachable); // 200 fit 320
var home_buf: [4096]u8 = undefined;
const expanded = @import("fs.zig").expandHome(dir_word, &home_buf);
if (@import("fs.zig").localPath(expanded)) |local| if (exec.kindOf(local) != .directory)
return p.reportFailure(c.id, if (exec.kindOf(local) != null)
- std.fmt.bufPrint(&said, "Incl: not a directory: {s}", .{shown}) catch "Incl: not a directory"
+ std.fmt.bufPrint(&said, "Incl: not a directory: {s}", .{shown}) catch unreachable // 200 fit 320
else
- std.fmt.bufPrint(&said, "Incl: no such directory: {s}", .{shown}) catch "Incl: no such directory");
+ std.fmt.bufPrint(&said, "Incl: no such directory: {s}", .{shown}) catch unreachable); // 200 fit 320
}
var words = std.mem.tokenizeAny(u8, typed, " \t");
while (words.next()) |dir_word| {
var home_buf: [4096]u8 = undefined;
- const full = std.fs.path.resolvePosix(p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(dir_word, &home_buf) }) catch return;
- if (!std.fs.path.isAbsolute(full)) return p.reportFailure(c.id, "Incl: invalid directory");
+ const full = std.Io.Dir.path.resolvePosix(p.scratch.allocator(), &.{ Pardes.paneDir(c.pane), @import("fs.zig").expandHome(dir_word, &home_buf) }) catch |err| return p.reportError(c.id, "Incl", err);
+ if (!std.Io.Dir.path.isAbsolute(full)) return p.reportFailure(c.id, "Incl: invalid directory");
for (p.incl.items) |dir| {
if (std.mem.eql(u8, dir, full)) break;
} else {
@@ -1141,9 +1141,9 @@ pub const Incl = struct {
}
if (typed.len > 0) return;
var list: std.Io.Writer.Allocating = .init(p.scratch.allocator());
- list.writer.writeAll("Incl:") catch return;
- for (p.incl.items) |dir| list.writer.print(" {s}", .{dir}) catch return;
- if (p.incl.items.len == 0) list.writer.writeAll(" none") catch return;
+ list.writer.writeAll("Incl:") catch |err| return p.reportError(c.id, "Incl", err);
+ for (p.incl.items) |dir| list.writer.print(" {s}", .{dir}) catch |err| return p.reportError(c.id, "Incl", err);
+ if (p.incl.items.len == 0) list.writer.writeAll(" none") catch |err| return p.reportError(c.id, "Incl", err);
p.setMessage(c.id, list.written());
}
};
@@ -1210,19 +1210,19 @@ pub const Save = struct {
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 }) catch "Save: no text to save");
+ 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 }) catch unreachable); // a kind's 16-byte name and 35 fit 64
}
// 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 "Save: a directory pane has no file to save");
+ 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
};
const path = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
if (path.len > 0) return exec.saveTo(c.p, c.id, path);
// A `+` name is a generated pane's (+Tutor), no file of its own:
// a bare Save asks for a path, as a +New scratch's does.
- if (c.pane.file) |file| if (file.output == null and !std.mem.startsWith(u8, std.fs.path.basename(file.path), "+")) return exec.saveFile(c.p, c.id);
+ if (c.pane.file) |file| if (file.output == null and !std.mem.startsWith(u8, std.Io.Dir.path.basename(file.path), "+")) return exec.saveFile(c.p, c.id);
if (c.pane.file != null or c.pane.isTerminal()) panes.startPrompt(c.p, c.pane, &c.pane.body, .save);
}
};
@@ -1280,7 +1280,7 @@ pub const Del = struct {
c.pane.question_due_ns = exec.clockNow(c.p) + config.del_question_delay_ns;
c.p.view().active = c.id;
var rec: [32]u8 = undefined;
- pardes.ctlfs.events.notePath(c.p, "ask", std.fmt.bufPrint(&rec, "{d} del k j", .{c.pane.serial}) catch "");
+ pardes.ctlfs.events.notePath(c.p, "ask", std.fmt.bufPrint(&rec, "{d} del k j", .{c.pane.serial}) catch unreachable); // a u32 fits 32
// The question says Del already.
if (c.pane.msg_announcement) c.pane.msg_len = 0;
return;
@@ -1422,7 +1422,7 @@ pub const Term = struct {
// The authority's lookup, taped, as Shell's (exec.zig).
if (pardes.tape.value(.shell, @import("host_io.zig").Shell.refusal, .{ arg[0..@min(arg.len, 200)], &why })) |refused| {
var said: [340]u8 = undefined;
- return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Term: {s}", .{refused}) catch "Term: no such shell");
+ return c.p.reportFailure(c.id, std.fmt.bufPrint(&said, "Term: {s}", .{refused}) catch unreachable); // refused is at most why's 320
}
}
const pane = exec.spawnTty(c.p, c.id) orelse return;
@@ -1455,7 +1455,7 @@ pub const Repl = struct {
var idbuf: [48]u8 = undefined;
if (arg.len == 0) {
if (pane.repl == null) return c.p.setMessage(c.id, "Repl: not bound");
- return c.p.setMessage(c.id, std.fmt.bufPrint(&buf, "Repl: {s}", .{exec.replId(&idbuf, pane)}) catch "Repl");
+ return c.p.setMessage(c.id, std.fmt.bufPrint(&buf, "Repl: {s}", .{exec.replId(&idbuf, pane)}) catch unreachable); // 48 fit 320
}
if (std.mem.eql(u8, arg, "-")) {
pane.repl = null;
@@ -1467,9 +1467,9 @@ pub const Repl = struct {
const named: ?u8 = if (manifest.byName(arg)) |i| if (grammars[i].exts.len > 0) @intCast(i) else null else null;
const lang: u8 = named orelse {
// A few, whole, and where the rest are: a list cut to fit the
- // row would end mid-word.
+ // row would end mid-word. unreachable: 24, six names and 60 fit 320.
var w = std.Io.Writer.fixed(&buf);
- w.print("Repl: invalid language \"{s}\"; - or one like", .{@import("Messages.zig").clip(arg, 24)}) catch {};
+ w.print("Repl: invalid language \"{s}\"; - or one like", .{@import("Messages.zig").clip(arg, 24)}) catch unreachable;
// Those that start as the word does first, a misspelling's
// likeliest meaning (pithon: python).
var shown: usize = 0;
@@ -1479,15 +1479,15 @@ pub const Repl = struct {
if (starts != alike) continue;
known += 1;
if (shown < 6) {
- w.print(" {s}", .{g.name}) catch {};
+ w.print(" {s}", .{g.name}) catch unreachable;
shown += 1;
}
};
- w.print(" ({d} more)", .{known - shown}) catch {};
+ w.print(" ({d} more)", .{known - shown}) catch unreachable;
return c.p.reportFailure(c.id, w.buffered());
};
if (pane.repl) |r| if (r.lang == lang)
- return c.p.setMessage(c.id, std.fmt.bufPrint(&buf, "Repl: {s}", .{exec.replId(&idbuf, pane)}) catch "Repl");
+ return c.p.setMessage(c.id, std.fmt.bufPrint(&buf, "Repl: {s}", .{exec.replId(&idbuf, pane)}) catch unreachable); // 48 fit 320
// The lowest letter no other REPL of the language has: freed ones
// come back.
var letter: u8 = 'a';
@@ -1501,7 +1501,7 @@ pub const Repl = struct {
if (letter > 'z') return c.p.reportFailure(c.id, "Repl: every letter of the language is taken");
pane.repl = .{ .lang = lang, .letter = letter };
pane.repl_warned = false;
- c.p.setMessage(c.id, std.fmt.bufPrint(&buf, "Repl: {s}", .{exec.replId(&idbuf, pane)}) catch "Repl");
+ c.p.setMessage(c.id, std.fmt.bufPrint(&buf, "Repl: {s}", .{exec.replId(&idbuf, pane)}) catch unreachable); // 48 fit 320
}
};
@@ -1525,7 +1525,7 @@ pub const Tutor = struct {
pub const scope: Scope = .session;
pub fn run(c: Ctx) void {
const free = c.p.freeSlot() orelse return c.p.reportError(c.id, "Tutor", error.NoPaneSlots);
- _ = panes.openTutorView(c.p, free) catch return;
+ _ = panes.openTutorView(c.p, free) catch |err| return c.p.reportError(c.id, "Tutor", err);
exec.placeNew(c.p, c.id, c.id, free, .doc); // a doc like any other
}
};
diff --git a/src/edit_cmd.zig b/src/edit_cmd.zig
index 207dd7cc..1a99e76c 100644
--- a/src/edit_cmd.zig
+++ b/src/edit_cmd.zig
@@ -125,7 +125,9 @@ const World = struct {
}
fn said(comptime T: type, why: *sam.Why, comptime fmt: []const u8, args: anytype) ?T {
- why.len = if (std.fmt.bufPrint(&why.buf, fmt, args)) |s| s.len else |_| 0;
+ var w: std.Io.Writer = .fixed(&why.buf);
+ w.print(fmt, args) catch {}; // a long path is cut at the room's end
+ why.len = w.end;
return null;
}
};
@@ -176,7 +178,7 @@ pub fn run(p: *Pardes, id: usize, command: []const u8) void {
var why: sam.Why = .{};
var text: [260]u8 = undefined;
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 "Edit: failed"),
+ error.Edit => return p.reportFailure(id, std.fmt.bufPrint(&text, "Edit: {s}", .{why.text()}) catch unreachable), // why's 200 fit 260
error.OutOfMemory => return p.reportError(id, "Edit", err),
};
// acme's Edit blocks the editor while its commands run; here the editor
@@ -192,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}) catch "Edit: busy");
+ 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
}
}
if (res.undo != 0) {
@@ -328,7 +330,7 @@ pub fn finish(p: *Pardes, success: bool, outputs: []const []const u8, failure: ?
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 }) catch "Edit: a command failed";
+ 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 was = p.view().active;
_ = ninep_pane.appendErrors(p, at, out.written());
if (p.panes[was] != null) p.view().active = was;
@@ -345,10 +347,12 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
var text: [320]u8 = undefined;
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}) catch "Edit: a pane closed");
- 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}) catch "Edit: a pane closed");
+ // unreachable: 256 of the name and 56 fit 320.
+ const name = f.name[0..@min(f.name.len, 256)];
+ const pane = p.panes[f.id] orelse return p.reportFailure(at, std.fmt.bufPrint(&text, "Edit: {s} closed while its commands ran; nothing changed", .{name}) catch unreachable);
+ if (pane.serial != pd.serials[i]) return p.reportFailure(at, std.fmt.bufPrint(&text, "Edit: {s} closed while its commands ran; nothing changed", .{name}) catch unreachable);
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}) catch "Edit: a file changed");
+ return p.reportFailure(at, std.fmt.bufPrint(&text, "Edit: {s} changed while its commands ran; nothing changed", .{name}) catch unreachable);
}
// 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
@@ -357,7 +361,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, if (errno == @import("ninep/tree.zig").E.NOENT) "no such file" else "cannot be read" }) catch "Edit: e 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
}
// `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
@@ -422,11 +426,11 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
var from: usize = 0;
for (res.jobs, 0..) |job, j| {
if (job.c != '>') continue;
- out.appendSlice(p.gpa, res.printed[from..job.at]) catch return;
- out.appendSlice(p.gpa, outputs[j]) catch return;
+ out.appendSlice(p.gpa, res.printed[from..job.at]) catch |err| return p.reportError(at, "Edit", err);
+ out.appendSlice(p.gpa, outputs[j]) catch |err| return p.reportError(at, "Edit", err);
from = job.at;
}
- out.appendSlice(p.gpa, res.printed[from..]) catch return;
+ out.appendSlice(p.gpa, res.printed[from..]) catch |err| return p.reportError(at, "Edit", err);
// Printed, the keyboard stays where it was: a +Errors made for it
// does not take it, so the next Edit lands where this one did.
const was = p.view().active;
@@ -435,7 +439,7 @@ fn commit(p: *Pardes, pd: *Pending, outputs: []const []const u8) void {
}
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 "Edit: w: modified on disk since read (w again to overwrite)");
+ 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
}
// 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 eb42424f..f90a2315 100644
--- a/src/exec.zig
+++ b/src/exec.zig
@@ -332,7 +332,7 @@ pub fn saveFile(p: *Pardes, id: usize) void {
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}) catch "modified on disk since read (Save again to overwrite)");
+ 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
}
f.disk_newer = null;
}
@@ -345,11 +345,11 @@ pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void {
std.mem.indexOfScalar(u8, path, '\n') != null)
return p.reportError(id, "save", error.NoFilename);
var home_buf: [4096]u8 = undefined;
- const full = std.fs.path.resolvePosix(
+ const full = std.Io.Dir.path.resolvePosix(
p.scratch.allocator(),
&.{ Pardes.paneDir(pane), @import("fs.zig").expandHome(path, &home_buf) },
- ) catch return;
- if (!std.fs.path.isAbsolute(full)) return p.reportError(id, "save", error.NoDirectory);
+ ) catch |err| return p.reportError(id, "save", err);
+ if (!std.Io.Dir.path.isAbsolute(full)) return p.reportError(id, "save", error.NoDirectory);
if (full.len > Pardes.SavePath.cap) return p.reportError(id, "save", error.PathTooLong);
const f = if (pane.file) |*file| file else {
// a terminal writes its scrollback; an image and a PDF have nothing
@@ -392,7 +392,7 @@ pub fn spawnTty(p: *Pardes, from: usize) ?*Pane {
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}) catch "Term: no such directory");
+ 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
return null;
}
const free = p.freeSlot() orelse {
@@ -473,9 +473,9 @@ pub fn replLive(p: *const Pardes, id: usize) bool {
}
/// `python-a`.
-pub fn replId(buf: []u8, pane: *const Pane) []const u8 {
+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 "";
+ return std.fmt.bufPrint(buf, "{s}-{c}", .{ grammars[r.lang].name, r.letter }) catch unreachable; // a grammar's name is short
}
const Routed = union(enum) { none, sent: usize, asked };
@@ -485,7 +485,7 @@ const Routed = union(enum) { none, sent: usize, asked };
pub fn replGone(p: *Pardes, from: usize, repl: *const Pane) Routed {
var idbuf: [48]u8 = undefined;
var said: [128]u8 = undefined;
- p.setMessage(from, std.fmt.bufPrint(&said, "Repl: {s} has no program running; nothing sent", .{replId(&idbuf, repl)}) catch "Repl: no program running");
+ p.setMessage(from, std.fmt.bufPrint(&said, "Repl: {s} has no program running; nothing sent", .{replId(&idbuf, repl)}) catch unreachable); // 48 and 44 fit 128
return .asked;
}
@@ -586,7 +586,7 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
// Lines end in \n alone (a \r\n would give Python a blank line that
// ends its block), and no ESC or other control byte but a tab goes: an
// ESC[201~ in the text would end a bracketed paste early.
- const clean = p.scratch.allocator().alloc(u8, text.len) catch return;
+ const clean = p.scratch.allocator().alloc(u8, text.len) catch |err| return p.reportError(from, "Repl", err);
var n: usize = 0;
for (text, 0..) |c, i| {
if (c == '\r') {
@@ -599,7 +599,7 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
// 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 "Repl: too long to send");
+ 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
}
const pasted = panes.terminal.bracketedPaste(dst);
edit.typeToTty(p, to, dst, clean[0..n]);
@@ -629,10 +629,10 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void {
{
dst.repl_warned = true;
var warn: [128]u8 = undefined;
- p.setMessage(from, std.fmt.bufPrint(&warn, "Repl: {s} takes no bracketed paste; a blank line in a block ends it", .{id}) catch "Repl: no bracketed paste");
+ p.setMessage(from, std.fmt.bufPrint(&warn, "Repl: {s} takes no bracketed paste; a blank line in a block ends it", .{id}) catch unreachable); // a 48-byte id and 66 fit 128
}
var said: [64]u8 = undefined;
- p.setMessage(from, std.fmt.bufPrint(&said, "\u{2192} {s}", .{id}) catch "sent");
+ p.setMessage(from, std.fmt.bufPrint(&said, "\u{2192} {s}", .{id}) catch unreachable); // a 48-byte id and 4 fit 64
src.msg_sent = true;
var rec: [96]u8 = undefined;
pardes.ctlfs.events.notePath(p, "send", std.fmt.bufPrint(&rec, "{d} {d} {s}", .{ src.serial, dst.serial, id }) catch return);
@@ -690,7 +690,7 @@ pub fn executeFrom(p: *Pardes, id: usize, txt: []const u8, from_body: bool) ?usi
const word = cmd[0 .. std.mem.indexOfAny(u8, cmd, " \t") orelse cmd.len];
if (builtins.absentWhy(word) orelse if (config.Runtime.find(word) != null) @as([]const u8, "GUI-only") else null) |why| {
var said: [96]u8 = undefined;
- p.reportFailure(id, std.fmt.bufPrint(&said, "{s} is {s}, invalid here", .{ word, why }) catch "GUI-only, invalid here");
+ p.reportFailure(id, std.fmt.bufPrint(&said, "{s} is {s}, invalid here", .{ word, why }) catch unreachable); // a known word (15 at most) and 17 fit 96
return null;
}
// A command from a column's or the workspace's tag is that tag's: a
@@ -726,7 +726,7 @@ fn runCommand(p: *Pardes, from: usize, line: []const u8) ?usize {
// 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}) catch "exec: no such directory");
+ 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
return null;
}
// Not one whose pty a job it left behind still prints to: reusing it
@@ -806,11 +806,12 @@ fn winid(p: *const Pardes, src: ?*Pane) u32 {
/// what it was given; its newlines the terminal's, so a multi-line command
/// does not staircase.
fn echoCommand(p: *Pardes, pane: *Pane, line: []const u8) void {
+ // unreachable: runCommand takes no line over command_max, each byte two at most.
var buf: [2 * command_max + 8]u8 = undefined;
var w = std.Io.Writer.fixed(&buf);
- w.writeAll(if (panes.terminal.gridCursor(pane).x != 0) "\r\n% " else "% ") catch {};
- for (line) |c| (if (c == '\n') w.writeAll("\r\n") else w.writeByte(c)) catch {};
- w.writeAll("\r\n") catch {};
+ w.writeAll(if (panes.terminal.gridCursor(pane).x != 0) "\r\n% " else "% ") catch unreachable;
+ for (line) |c| (if (c == '\n') w.writeAll("\r\n") else w.writeByte(c)) catch unreachable;
+ w.writeAll("\r\n") catch unreachable;
panes.terminal.feedOutput(p, pane, w.buffered());
}
@@ -821,7 +822,7 @@ fn echoCommand(p: *Pardes, pane: *Pane, line: []const u8) void {
pub fn noteRun(p: *Pardes, pane: *Pane, what: []const u8, said: []const u8) void {
pardes.ctlfs.events.announce(p);
var buf: [command_max + 16]u8 = undefined;
- pardes.ctlfs.events.notePath(p, what, std.fmt.bufPrint(&buf, "{d} {s}", .{ pane.serial, std.mem.trim(u8, said, " \t\r\n") }) catch return);
+ pardes.ctlfs.events.notePath(p, what, std.fmt.bufPrint(&buf, "{d} {s}", .{ pane.serial, std.mem.trim(u8, said, " \t\r\n") }) catch unreachable); // a run's line is at most command_max
}
/// A command pane's child is gone: the pane stays, showing what it said
@@ -840,10 +841,10 @@ pub fn commandDone(p: *Pardes, id: usize, status: ?u8) void {
if (status == 0) return p.removePane(id, null) catch {};
}
var buf: [16]u8 = undefined;
- const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch "?" else "?";
+ const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // a status fits 16
var said: [32]u8 = undefined;
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 "exit ?\r\n");
+ panes.terminal.feedOutput(p, pane, std.fmt.bufPrint(&said, "{s}exit {s}\r\n", .{ lead, code }) catch unreachable); // 16 and 9 fit 32
noteRun(p, pane, "exit", code);
p.needs_frame = true;
}
@@ -896,7 +897,7 @@ pub fn executeBuiltinLine(p: *Pardes, id: usize, txt: []const u8) bool {
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 "invalid: an acme word pardes has not");
+ 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
return true;
};
// Delete: Del, the text thrown away unasked.
@@ -963,10 +964,10 @@ fn applyInitText(p: *Pardes, text: []const u8, settings_only: bool) void {
// on the message row and an err in the log, with its line.
var why_buf: [320]u8 = undefined;
const why: []const u8 = if (!known)
- std.fmt.bufPrint(&why_buf, "unknown word \"{s}\"", .{word[0..@min(word.len, 64)]}) catch "unknown word"
+ std.fmt.bufPrint(&why_buf, "unknown word \"{s}\"", .{word[0..@min(word.len, 64)]}) catch unreachable // 64 fit 320
else if (p.fs.said_len > 0) p.fs.said[0..p.fs.said_len] else "failed";
var said: [400]u8 = undefined;
- const line_said = std.fmt.bufPrint(&said, "init file line {d}: {s}", .{ number, why }) catch "init file: a line failed";
+ const line_said = std.fmt.bufPrint(&said, "init file line {d}: {s}", .{ number, why }) catch unreachable; // why is 320 at most
if (!known) p.reportFailure(p.view().active, line_said);
pardes.ctlfs.events.notePath(p, "err -", line_said);
}
@@ -983,7 +984,7 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?
// 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 "GUI-only, invalid here");
+ 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
}
// 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).
@@ -1002,7 +1003,7 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ?
// 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 "only another kind of pane takes it");
+ return p.reportFailure(id, std.fmt.bufPrint(&said, "{s}: only {s} pane takes it", .{ @tagName(b), kind.noun() }) catch unreachable); // short names
};
const c: builtins.Ctx = .{ .p = p, .pane = pane, .id = id, .txt = txt, .arg = arg, .from_body = from_body };
builtins.registry.dispatch(b, c);
@@ -1023,7 +1024,7 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]
const room = 128 -| ("Theme: no theme \"\"; like it: ; Themes lists all".len + shown.len);
var near: [128]u8 = undefined;
var text: [256]u8 = undefined;
- return p.reportFailure(v.active, std.fmt.bufPrint(&text, "Theme: no theme \"{s}\"; like it: {s}; Themes lists all", .{ shown, colors.themesNear(near[0..@min(room, near.len)], want) }) catch "Theme: no such theme");
+ return p.reportFailure(v.active, std.fmt.bufPrint(&text, "Theme: no theme \"{s}\"; like it: {s}; Themes lists all", .{ shown, colors.themesNear(near[0..@min(room, near.len)], want) }) catch unreachable); // 40 and 128 of names fit 256
},
.font => {
if (comptime !font_picker) return;
@@ -1042,30 +1043,32 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]
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()}) catch "Shell: the default again");
+ 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 why: [320]u8 = undefined;
if (pardes.tape.value(.shell, @import("host_io.zig").Shell.refusal, .{ want[0..@min(want.len, 200)], &why })) |refused| {
var text: [340]u8 = undefined;
- return p.reportFailure(v.active, std.fmt.bufPrint(&text, "Shell: {s}", .{refused}) catch "Shell: no such shell");
+ return p.reportFailure(v.active, std.fmt.bufPrint(&text, "Shell: {s}", .{refused}) catch unreachable); // refused is at most why's 320
}
if (!p.settings.apply(setting, want)) p.reportFailure(v.active, "Shell: takes " ++ comptime config.Runtime.takes(.shell).?);
},
// 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 setting.word);
+ 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
} 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 setting.word);
+ 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); // short literals
} else if (tag == .tab) {
config.tab_now = p.settings.tab;
},
// Said with what it takes: its words, its range.
else => if (!p.settings.apply(setting, arg)) {
- var text: [160]u8 = undefined;
- const why = if (config.Runtime.takes(setting.action)) |values| std.fmt.bufPrint(&text, "{s}: takes {s}", .{ setting.word, values }) else std.fmt.bufPrint(&text, "{s}: does not take that value", .{setting.word});
- p.reportFailure(v.active, why catch "does not take that value");
+ var buf: [160]u8 = undefined;
+ var text: std.Io.Writer = .fixed(&buf);
+ // A list of values too long for the row is cut.
+ (if (config.Runtime.takes(setting.action)) |values| text.print("{s}: takes {s}", .{ setting.word, values }) else text.print("{s}: does not take that value", .{setting.word})) catch {};
+ p.reportFailure(v.active, text.buffered());
},
}
if (setting.action == .tab) {
@@ -1257,7 +1260,7 @@ pub fn runWord(p: *Pardes, id: usize, w: *const pardes.Kind.Word, line: []const
if (w.opens != 0) {
const free = p.freeSlot() orelse return p.reportError(id, name, error.NoPaneSlots);
var path_buf: [4096]u8 = undefined;
- const path = if (arg.len == 0 or std.fs.path.isAbsolute(arg)) arg else std.fmt.bufPrint(&path_buf, "{s}/{s}", .{ std.mem.trimEnd(u8, if (p.panes[id]) |pane| Pardes.paneDir(pane) else p.sessionDir(), "/"), arg }) catch arg;
+ const path = if (arg.len == 0 or std.Io.Dir.path.isAbsolute(arg)) arg else std.fmt.bufPrint(&path_buf, "{s}/{s}", .{ std.mem.trimEnd(u8, if (p.panes[id]) |pane| Pardes.paneDir(pane) else p.sessionDir(), "/"), arg }) catch arg;
const made = (if (path.len > 0) pardes.Kind.openFile(p, free, w.kind, path) else pardes.Kind.open(p, free, w.kind, null, null)) catch |err| return p.reportError(id, name, err);
if (made.addon.?.refused.len > 0) {
made.vweight = 0;