diff options
Diffstat (limited to 'src/builtins.zig')
| -rw-r--r-- | src/builtins.zig | 44 |
1 files changed, 22 insertions, 22 deletions
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); |
