summaryrefslogtreecommitdiff
path: root/src/builtins.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/builtins.zig')
-rw-r--r--src/builtins.zig79
1 files changed, 41 insertions, 38 deletions
diff --git a/src/builtins.zig b/src/builtins.zig
index 76fb959d..c500ee56 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -597,11 +597,11 @@ pub fn warnModifiedIn(c: Ctx, asking: Pane.Discarding, which: Asked) bool {
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) })
+ var said_buf: pardes.Kind.Buf(limits.host_path_cap + 96) = .{};
+ const said = if (count == 1)
+ said_buf.print("{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 unreachable; // one is one_buf's at most
+ said_buf.print("{d} unsaved panes: Modified ({s} again to discard)", .{ count, @tagName(asking) });
var room: @TypeOf(c.p.fs.failure) = undefined;
const kept = pardes.ctlfs.fitErr(said, &room);
@memcpy(c.p.fs.failure[0..kept.len], kept);
@@ -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 + 160]u8 = undefined;
+ var buf: pardes.Kind.Buf(limits.host_path_cap + 160) = .{};
var words: [128]u8 = undefined;
const why = switch (err) {
error.FileNotFound => "no such file",
@@ -723,15 +723,15 @@ 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[0..@min(path.len, limits.host_path_cap)], why }) catch unreachable); // cap and 128 fit
+ return c.p.reportFailure(c.id, buf.print("Restore: {s}: {s}", .{ path[0..@min(path.len, limits.host_path_cap)], why }));
};
defer c.p.gpa.free(bytes);
// Nor does a file that is not a dump, before any warning.
var why_buf: [256]u8 = undefined;
pardes.dump.check(c.p.gpa, bytes, &why_buf) catch |err| {
- var buf: [limits.host_path_cap + 320]u8 = undefined;
+ var buf: pardes.Kind.Buf(limits.host_path_cap + 320) = .{};
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[0..@min(path.len, limits.host_path_cap)], why }) catch unreachable); // cap and 256 fit
+ return c.p.reportFailure(c.id, buf.print("Restore: {s}: not a pardes dump: {s}", .{ path[0..@min(path.len, limits.host_path_cap)], why }));
};
}
// acme's Load adds a dump's windows to the ones there; a Restore
@@ -1069,10 +1069,10 @@ pub const Get = struct {
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: [400]u8 = undefined;
+ var said: pardes.Kind.Buf(400) = .{};
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 unreachable); // 256 and 128 fit 400
+ c.p.reportFailure(c.id, said.print("Get: {s}: {s}", .{ path[0..@min(path.len, 256)], why }));
}
}
};
@@ -1114,18 +1114,18 @@ pub const Incl = struct {
// is absolute (or ~) and there.
var check = std.mem.tokenizeAny(u8, typed, " \t");
while (check.next()) |dir_word| {
- var said: [320]u8 = undefined;
+ var said: pardes.Kind.Buf(320) = .{};
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 unreachable); // 200 fit 320
+ return p.reportFailure(c.id, said.print("Incl: invalid directory: {s} is relative", .{shown}));
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 unreachable // 200 fit 320
+ said.print("Incl: not a directory: {s}", .{shown})
else
- std.fmt.bufPrint(&said, "Incl: no such directory: {s}", .{shown}) catch unreachable); // 200 fit 320
+ said.print("Incl: no such directory: {s}", .{shown}));
}
var words = std.mem.tokenizeAny(u8, typed, " \t");
while (words.next()) |dir_word| {
@@ -1210,7 +1210,7 @@ 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 unreachable); // a kind's 16-byte name and 35 fit 64
+ 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
}
// A directory's listing is no file to write, bare or to a path, as
// acme's Put does nothing in a directory window.
@@ -1421,8 +1421,8 @@ pub const Term = struct {
var why: [320]u8 = undefined;
// 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 unreachable); // refused is at most why's 320
+ var said: pardes.Kind.Buf(340) = .{};
+ return c.p.reportFailure(c.id, said.print("Term: {s}", .{refused}));
}
}
const pane = exec.spawnTty(c.p, c.id) orelse return;
@@ -1451,11 +1451,11 @@ pub const Repl = struct {
if (!pane.isTerminal() or pane.terminal == null) return c.p.reportFailure(c.id, "Repl: only a terminal is a REPL");
if (pane.command != null and pane.command_done) return c.p.reportFailure(c.id, "Repl: its command is done; a REPL is a running program");
const arg = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
- var buf: [320]u8 = undefined;
+ var buf: pardes.Kind.Buf(320) = .{};
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 unreachable); // 48 fit 320
+ return c.p.setMessage(c.id, buf.print("Repl: {s}", .{exec.replId(&idbuf, pane)}));
}
if (std.mem.eql(u8, arg, "-")) {
pane.repl = null;
@@ -1467,27 +1467,30 @@ 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. 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 unreachable;
- // Those that start as the word does first, a misspelling's
- // likeliest meaning (pithon: python).
- var shown: usize = 0;
- var known: usize = 0;
- for ([2]bool{ true, false }) |alike| for (grammars) |g| if (g.exts.len > 0) {
- const starts = arg.len > 0 and g.name[0] == std.ascii.toLower(arg[0]);
- if (starts != alike) continue;
- known += 1;
- if (shown < 6) {
- w.print(" {s}", .{g.name}) catch unreachable;
- shown += 1;
- }
- };
- w.print(" ({d} more)", .{known - shown}) catch unreachable;
+ // row would end mid-word.
+ var w = std.Io.Writer.fixed(&buf.bytes);
+ list: {
+ // A list past the room is cut at its end.
+ w.print("Repl: invalid language \"{s}\"; - or one like", .{@import("Messages.zig").clip(arg, 24)}) catch break :list;
+ // Those that start as the word does first, a misspelling's
+ // likeliest meaning (pithon: python).
+ var shown: usize = 0;
+ var known: usize = 0;
+ for ([2]bool{ true, false }) |alike| for (grammars) |g| if (g.exts.len > 0) {
+ const starts = arg.len > 0 and g.name[0] == std.ascii.toLower(arg[0]);
+ if (starts != alike) continue;
+ known += 1;
+ if (shown < 6) {
+ w.print(" {s}", .{g.name}) catch break :list;
+ shown += 1;
+ }
+ };
+ w.print(" ({d} more)", .{known - shown}) catch break :list;
+ }
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 unreachable); // 48 fit 320
+ return c.p.setMessage(c.id, buf.print("Repl: {s}", .{exec.replId(&idbuf, pane)}));
// The lowest letter no other REPL of the language has: freed ones
// come back.
var letter: u8 = 'a';
@@ -1501,7 +1504,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 unreachable); // 48 fit 320
+ c.p.setMessage(c.id, buf.print("Repl: {s}", .{exec.replId(&idbuf, pane)}));
}
};