summaryrefslogtreecommitdiff
path: root/src/exec.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/exec.zig')
-rw-r--r--src/exec.zig50
1 files changed, 25 insertions, 25 deletions
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;
},