diff options
Diffstat (limited to 'src/exec.zig')
| -rw-r--r-- | src/exec.zig | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/src/exec.zig b/src/exec.zig index f90a2315..46bf54c3 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -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 grammar's name is short + return std.fmt.bufPrint(buf, "{s}-{c}", .{ grammars[r.lang].name, r.letter }) catch unreachable; // a comptime grammar name and a letter fit 48 } const Routed = union(enum) { none, sent: usize, asked }; @@ -484,8 +484,8 @@ const Routed = union(enum) { none, sent: usize, asked }; /// and nothing sent or run. 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 unreachable); // 48 and 44 fit 128 + var said: pardes.Kind.Buf(128) = .{}; + p.setMessage(from, said.print("Repl: {s} has no program running; nothing sent", .{replId(&idbuf, repl)})); return .asked; } @@ -628,11 +628,11 @@ pub fn sendToRepl(p: *Pardes, from: usize, to: usize, text: []const u8) void { std.mem.indexOfScalar(u8, text, '\n') != null) { 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 unreachable); // a 48-byte id and 66 fit 128 + var warn: pardes.Kind.Buf(128) = .{}; + p.setMessage(from, warn.print("Repl: {s} takes no bracketed paste; a blank line in a block ends it", .{id})); } - var said: [64]u8 = undefined; - p.setMessage(from, std.fmt.bufPrint(&said, "\u{2192} {s}", .{id}) catch unreachable); // a 48-byte id and 4 fit 64 + var said: pardes.Kind.Buf(64) = .{}; + p.setMessage(from, said.print("\u{2192} {s}", .{id})); 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); @@ -689,8 +689,8 @@ pub fn executeFrom(p: *Pardes, id: usize, txt: []const u8, from_body: bool) ?usi // never run as a shell command. 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 unreachable); // a known word (15 at most) and 17 fit 96 + var said: pardes.Kind.Buf(96) = .{}; + p.reportFailure(id, said.print("{s} is {s}, invalid here", .{ word, why })); return null; } // A command from a column's or the workspace's tag is that tag's: a @@ -806,12 +806,14 @@ 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 unreachable; - for (line) |c| (if (c == '\n') w.writeAll("\r\n") else w.writeByte(c)) catch unreachable; - w.writeAll("\r\n") catch unreachable; + // A line past the room is cut at its end. + echo: { + w.writeAll(if (panes.terminal.gridCursor(pane).x != 0) "\r\n% " else "% ") catch break :echo; + for (line) |c| (if (c == '\n') w.writeAll("\r\n") else w.writeByte(c)) catch break :echo; + w.writeAll("\r\n") catch break :echo; + } panes.terminal.feedOutput(p, pane, w.buffered()); } @@ -821,8 +823,8 @@ fn echoCommand(p: *Pardes, pane: *Pane, line: []const u8) void { /// announced first, so `new` comes before the `run` in it. 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 unreachable); // a run's line is at most command_max + var buf: pardes.Kind.Buf(command_max + 16) = .{}; + pardes.ctlfs.events.notePath(p, what, buf.print("{d} {s}", .{ pane.serial, std.mem.trim(u8, said, " \t\r\n") })); } /// A command pane's child is gone: the pane stays, showing what it said @@ -841,10 +843,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 unreachable else "?"; // a status fits 16 + const code = if (status) |n| std.fmt.bufPrint(&buf, "{d}", .{n}) catch unreachable else "?"; // an exit 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 unreachable); // 16 and 9 fit 32 + 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 noteRun(p, pane, "exit", code); p.needs_frame = true; } @@ -966,8 +968,8 @@ fn applyInitText(p: *Pardes, text: []const u8, settings_only: bool) void { 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 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 unreachable; // why is 320 at most + var said: pardes.Kind.Buf(400) = .{}; + const line_said = said.print("init file line {d}: {s}", .{ number, why }); if (!known) p.reportFailure(p.view().active, line_said); pardes.ctlfs.events.notePath(p, "err -", line_said); } @@ -1003,7 +1005,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 unreachable); // short names + 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 }; const c: builtins.Ctx = .{ .p = p, .pane = pane, .id = id, .txt = txt, .arg = arg, .from_body = from_body }; builtins.registry.dispatch(b, c); @@ -1023,8 +1025,8 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] const shown = want[0..@min(want.len, 40)]; 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 unreachable); // 40 and 128 of names fit 256 + var text: pardes.Kind.Buf(256) = .{}; + return p.reportFailure(v.active, text.print("Theme: no theme \"{s}\"; like it: {s}; Themes lists all", .{ shown, colors.themesNear(near[0..@min(room, near.len)], want) })); }, .font => { if (comptime !font_picker) return; @@ -1047,8 +1049,8 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] } 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 unreachable); // refused is at most why's 320 + var text: pardes.Kind.Buf(340) = .{}; + return p.reportFailure(v.active, text.print("Shell: {s}", .{refused})); } if (!p.settings.apply(setting, want)) p.reportFailure(v.active, "Shell: takes " ++ comptime config.Runtime.takes(.shell).?); }, @@ -1058,7 +1060,7 @@ pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[] 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 unreachable); // short literals + 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 } else if (tag == .tab) { config.tab_now = p.settings.tab; }, |
