diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 12:40:11 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 14:56:36 -0300 |
| commit | 36a51ddc67d0beb7d9851fb2425cf780a47fed36 (patch) | |
| tree | d534d3151d836ea7a275e9f118a89f2bbc0d0448 /src/ninep/pty.zig | |
| parent | 4917ae452a15ff4f32d97d215a99fdcfaab29d61 (diff) | |
| download | pardes-36a51ddc67d0beb7d9851fb2425cf780a47fed36.tar.gz pardes-36a51ddc67d0beb7d9851fb2425cf780a47fed36.zip | |
idioms #10, the 9P tree: every bufPrint that fell back to "" or a placeholder is proven to fit (catch unreachable, its why) or cut its argument to fit, /status, /listeners and the 9P reads that staged on gpa answer ENOMEM rather than read short, acme's pane ctl words and pty's files and signals are stringToEnum switches, a dirent's head and name are staged together or not at all, a repeated log record too long to count is pushed as its own line rather than dropped, and daemonList's set is named
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/ninep/pty.zig')
| -rw-r--r-- | src/ninep/pty.zig | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig index 65e8589f..2a4fc1ed 100644 --- a/src/ninep/pty.zig +++ b/src/ninep/pty.zig @@ -12,11 +12,12 @@ const E = tree.E; const PaneFile = tree.PaneFile; pub fn fileNamed(name: []const u8) ?PaneFile { - if (std.mem.eql(u8, name, "ctl")) return .pty_ctl; - if (std.mem.eql(u8, name, "status")) return .pty_status; - if (std.mem.eql(u8, name, "data")) return .pty_data; - if (std.mem.eql(u8, name, "run")) return .pty_run; - return null; + return switch (std.meta.stringToEnum(enum { ctl, status, data, run }, name) orelse return null) { + .ctl => .pty_ctl, + .status => .pty_status, + .data => .pty_data, + .run => .pty_run, + }; } const Verb = enum { winsize, sig, exec }; @@ -37,12 +38,13 @@ const e_winsize_range = std.fmt.comptimePrint("invalid winsize: out of range, 1x const e_winsize_rows = std.fmt.comptimePrint("invalid winsize: at least {d} rows", .{pty_rows_min}); fn signalNamed(word: []const u8) ?pardes.PtySignal { - if (std.mem.eql(u8, word, "INT")) return .int; - if (std.mem.eql(u8, word, "TERM")) return .term; - if (std.mem.eql(u8, word, "HUP")) return .hup; - if (std.mem.eql(u8, word, "QUIT")) return .quit; - if (std.mem.eql(u8, word, "KILL")) return .kill; - return null; + return switch (std.meta.stringToEnum(enum { INT, TERM, HUP, QUIT, KILL }, word) orelse return null) { + .INT => .int, + .TERM => .term, + .HUP => .hup, + .QUIT => .quit, + .KILL => .kill, + }; } pub fn writeCtl(p: *Pardes, req: Req, id: usize) Reply { @@ -59,13 +61,13 @@ pub fn writeCtl(p: *Pardes, req: Req, id: usize) Reply { // refused before anything runs, as Term there is. const dir = pane.cwdSlice(); if (pardes.exec.missingDir(p, dir)) - return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch "exec: no such directory"); + return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch unreachable); // 256 fit 320 // Nor is a shell that is not there, or a script whose // interpreter is not: refused, and the running shell kept. const bin = pane.shell orelse p.shellBin(); var why: [320]u8 = undefined; if (pardes.tape.value(.shell, @import("../host_io.zig").Shell.refusal, .{ bin[0..@min(bin.len, 200)], &why })) |refused| - return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}", .{refused}) catch "exec: no such shell"); + return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}", .{refused[0..@min(refused.len, 300)]}) catch unreachable); // 300 fit 320 }; if (verb(p, id, line, apply)) |why| return tree.failText(req.tag, E.INVAL, why); } @@ -140,7 +142,7 @@ pub fn readStatus(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { (if (marks) |m| m.prompts > 0 and (m.phase != .input or !pardes.panes.terminal.promptInputEmpty(pane)) else false))); const out = p.fs.stage(p.gpa); const size = winsize(pane); - out.print(p.gpa, "{d:>11} {d:>11} {d:>11}\n", .{ size[0], size[1], @intFromBool(busy) }) catch {}; + out.print(p.gpa, "{d:>11} {d:>11} {d:>11}\n", .{ size[0], size[1], @intFromBool(busy) }) catch return Reply.fail(req.tag, E.NOMEM); return tree.stagedReply(p, req); } |
