summaryrefslogtreecommitdiff
path: root/src/ninep/pty.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/pty.zig')
-rw-r--r--src/ninep/pty.zig30
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);
}