diff options
Diffstat (limited to 'src/ninep/ctl.zig')
| -rw-r--r-- | src/ninep/ctl.zig | 93 |
1 files changed, 48 insertions, 45 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index d21e58a3..2e362f77 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -420,39 +420,42 @@ pub const pane_text_cap = 9 * 12 + 2 * 256 + 4 + "notcurrent ".len + 48 + "colla /// a REPL's id. pub fn paneText(p: *Pardes, pane: *Pane, buf: *[pane_text_cap]u8) []const u8 { var w = std.Io.Writer.fixed(buf); - w.print("{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} ", .{ - pane.serial, - pane_files.tagOf(p, pane).len, - // A terminal's body is its history, read whole on an open's first read. - if (pane.isTerminal()) panes.terminal.screenTextLen(pane) else pane_files.bodyOf(pane).len, - // A directory pane is one, as acme's isdir says. - @intFromBool(if (pane.file) |f| f.listing != null else false), - @intFromBool(pane_files.dirtyOf(pane)), - pane.cols, - }) catch unreachable; // integers: pane_text_cap counts them at 11 each - const font = p.settings.font.effective_name.get(); - writeQuoted(&w, if (font.len == 0) "default" else font) catch unreachable; // a Text(255) quoted is 2 * 256 at most, counted - // While a column's or the workspace's tag has the keyboard, no pane does. - const current = p.panes[p.view().active] == pane and p.view().header == null; - const f = pane_files.fileOf(pane); - const undo = if (f) |file| file.history.journal.done > 0 else false; - const redo = if (f) |file| file.history.journal.done < file.history.journal.steps.items.len else false; - w.print(" {d:>11} {d:>11} {d:>11} {s} ", .{ config.tab_now, @intFromBool(undo), @intFromBool(redo), if (current) "current" else "notcurrent" }) catch unreachable; // integers and a literal, counted - // A terminal bound as a REPL ends with its id, `python-a`. - var idbuf: [48]u8 = undefined; - const id = exec_line.replId(&idbuf, pane); - if (id.len > 0) w.print("{s} ", .{id[0..@min(id.len, idbuf.len)]}) catch unreachable; // 48, counted - // Then what its tag does not say: Collapse, and a kind's own fields (a - // PDF's PdfFit and PdfTint, in the words they take). - if (pane.collapsed) w.writeAll("collapsed ") catch unreachable; // a literal, counted - if (pane.addon != null) { - var fields: [128]u8 = undefined; - const kind_fields = pardes.Kind.ctlRead(pane, &fields); - if (kind_fields.len > 0) w.print("{s} ", .{kind_fields[0..@min(kind_fields.len, fields.len)]}) catch unreachable; // 128 and a blank, counted + // A buffer that fills cuts the line there. + fill: { + w.print("{d:>11} {d:>11} {d:>11} {d:>11} {d:>11} {d:>11} ", .{ + pane.serial, + pane_files.tagOf(p, pane).len, + // A terminal's body is its history, read whole on an open's first read. + if (pane.isTerminal()) panes.terminal.screenTextLen(pane) else pane_files.bodyOf(pane).len, + // A directory pane is one, as acme's isdir says. + @intFromBool(if (pane.file) |f| f.listing != null else false), + @intFromBool(pane_files.dirtyOf(pane)), + pane.cols, + }) catch break :fill; + const font = p.settings.font.effective_name.get(); + writeQuoted(&w, if (font.len == 0) "default" else font) catch break :fill; + // While a column's or the workspace's tag has the keyboard, no pane does. + const current = p.panes[p.view().active] == pane and p.view().header == null; + const f = pane_files.fileOf(pane); + const undo = if (f) |file| file.history.journal.done > 0 else false; + const redo = if (f) |file| file.history.journal.done < file.history.journal.steps.items.len else false; + w.print(" {d:>11} {d:>11} {d:>11} {s} ", .{ config.tab_now, @intFromBool(undo), @intFromBool(redo), if (current) "current" else "notcurrent" }) catch break :fill; + // A terminal bound as a REPL ends with its id, `python-a`. + var idbuf: [48]u8 = undefined; + const id = exec_line.replId(&idbuf, pane); + if (id.len > 0) w.print("{s} ", .{id}) catch break :fill; + // Then what its tag does not say: Collapse, and a kind's own fields (a + // PDF's PdfFit and PdfTint, in the words they take). + if (pane.collapsed) w.writeAll("collapsed ") catch break :fill; + if (pane.addon != null) { + var fields: [128]u8 = undefined; + const kind_fields = pardes.Kind.ctlRead(pane, &fields); + if (kind_fields.len > 0) w.print("{s} ", .{kind_fields}) catch break :fill; + } + // Last, the body's mode, which the tag shows as a box: helix's select + // is normal mode extending. + w.print("mode:{s} ", .{if (pane.body.mode == .normal and pane.body.select) "select" else @tagName(pane.body.mode)}) catch break :fill; } - // Last, the body's mode, which the tag shows as a box: helix's select - // is normal mode extending. - w.print("mode:{s} ", .{if (pane.body.mode == .normal and pane.body.select) "select" else @tagName(pane.body.mode)}) catch unreachable; // an enum's name, counted return w.buffered(); } @@ -521,7 +524,7 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ? // acme's words: checked as the pardes word they run as, or refused. const word = for (pardes.exec.acme_words) |w| { if (!std.mem.eql(u8, typed, w.acme)) continue; - const now = w.pardes orelse return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s} is not a pardes builtin{s}", .{ w.acme, w.hint }) catch unreachable); // acme_words holds short literals + const now = w.pardes orelse return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s} is not a pardes builtin{s}", .{ w.acme, w.hint }) catch &p.fs.ename); // cut to ename's 320 break now; } else typed; const arg = if (sp) |s| std.mem.trim(u8, line[s + 1 ..], " \t") else ""; @@ -672,18 +675,18 @@ pub fn writePager(p: *Pardes, req: Req) Reply { // named into one missing, nor a relative one quietly taken for none. if (dir.len > 0 and dir[0] != '/') { var shown: [256]u8 = undefined; - return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "pager: invalid directory \"{s}\": must be absolute", .{blanked(dir[0..@min(dir.len, shown.len)], &shown)}) catch unreachable); // 256 fit 320 + return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "pager: invalid directory \"{s}\": must be absolute", .{blanked(dir[0..@min(dir.len, shown.len)], &shown)}) catch &p.fs.ename); // cut to ename's 320 } if (dir.len > 0) if (pardes.filesystem.localPath(dir)) |local| { // A file there is no directory, ENOTDIR; nothing there, ENOENT. if (exec_line.kindOf(local) != .directory) { if (exec_line.kindOf(local) != null) - return tree.failText(req.tag, E.NOTDIR, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: not a directory", .{dir[0..@min(dir.len, 256)]}) catch unreachable); // 256 fit 320 - return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch unreachable); // 256 fit 320 + return tree.failText(req.tag, E.NOTDIR, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: not a directory", .{dir[0..@min(dir.len, 256)]}) catch &p.fs.ename); // cut to ename's 320 + return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: no such directory", .{dir[0..@min(dir.len, 256)]}) catch &p.fs.ename); // cut to ename's 320 } // Nor one that may not be written, as a file's name there is refused. if (pardes.filesystem.deniedAbove(local)) - return tree.failText(req.tag, E.PERM, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: permission denied", .{dir[0..@min(dir.len, 256)]}) catch unreachable); // 256 fit 320 + return tree.failText(req.tag, E.PERM, std.fmt.bufPrint(&p.fs.ename, "pager: {s}: permission denied", .{dir[0..@min(dir.len, 256)]}) catch &p.fs.ename); // cut to ename's 320 }; const id = pardes.panes.Output.openPager(p, p.view().active, dir) catch |err| return tree.failText(req.tag, if (err == error.NoPaneRoom or err == error.NoPaneSlots) E.NOSPC else E.IO, switch (err) { @@ -1104,11 +1107,11 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply { // out of reach as a look or a Save says it. if (errno != 0) { const path = if (pane_files.fileOf(pane)) |f| f.path else ""; - var why_buf: [48]u8 = undefined; + var why_buf: pardes.Kind.Buf(48) = .{}; const why = if (pardes.Messages.dialReason(failed)) |r| - std.fmt.bufPrint(&why_buf, "dial failed: {s}", .{r}) catch unreachable // dialReason's literals and 13 fit 48 + why_buf.print("dial failed: {s}", .{r}) else if (errno == E.NOENT) "no such file" else "cannot be read"; - return tree.failText(req.tag, errno, std.fmt.bufPrint(&p.fs.ename, "get: {s}: {s}", .{ path[0..@min(path.len, 256)], why[0..@min(why.len, 48)] }) catch unreachable); // 256, 48 and 7 fit 320 + return tree.failText(req.tag, errno, std.fmt.bufPrint(&p.fs.ename, "get: {s}: {s}", .{ path[0..@min(path.len, 256)], why[0..@min(why.len, 48)] }) catch &p.fs.ename); // cut to ename's 320 } }, .lock => { @@ -1126,7 +1129,7 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply { // With a question up, what it offers. var offered: [64]u8 = undefined; if (keys.questionChoices(p, p.paneBySerial(serial).?, &offered)) |choices| - return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "answer takes {s} or -", .{choices[0..@min(choices.len, 64)]}) catch unreachable); // 64 and 18 fit 320 + return tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "answer takes {s} or -", .{choices[0..@min(choices.len, 64)]}) catch &p.fs.ename); // cut to ename's 320 return tree.failText(req.tag, E.INVAL, "answer takes a choice or -"); }, } else if (std.mem.startsWith(u8, line, "answer ") and p.panes[p.paneBySerial(serial).?].?.prompt == .save) { @@ -1135,8 +1138,8 @@ pub fn writePane(p: *Pardes, req: Req, pane: *Pane) Reply { const id = p.paneBySerial(serial).?; const asked = p.panes[id].?; const path = std.mem.trim(u8, line["answer ".len..], " "); - var rec: [300]u8 = undefined; - pardes.ctlfs.events.notePath(p, "answer", std.fmt.bufPrint(&rec, "{d} {s}", .{ serial, path[0..@min(path.len, 256)] }) catch unreachable); // a u32 and 256 fit 300 + var rec: pardes.Kind.Buf(300) = .{}; + pardes.ctlfs.events.notePath(p, "answer", rec.print("{d} {s}", .{ serial, path })); if (!std.mem.eql(u8, path, "-")) exec_line.saveTo(p, id, path); asked.closePrompt(); } else if (std.mem.startsWith(u8, line, "answer ")) { @@ -1222,7 +1225,7 @@ fn acmeCtl(p: *Pardes, req: Req, serial: u32, line: []const u8, apply: bool) Acm .menu, .nomenu => "pardes has no menu", else => "a pane is dumped with the session: Dump and DumpDir on /ctl", }; - return .{ .refused = tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s}: {s}", .{ @tagName(w), why }) catch unreachable) }; // an enum's name and a literal fit 320 + return .{ .refused = tree.failText(req.tag, E.INVAL, std.fmt.bufPrint(&p.fs.ename, "invalid: acme's {s}: {s}", .{ @tagName(w), why }) catch &p.fs.ename) }; // cut to ename's 320 }, }; if (!apply) return .done; @@ -1260,7 +1263,7 @@ pub fn getRefused(p: *Pardes, pane: *Pane, word: []const u8) ?[]const u8 { p.fs.unlogged = true; p.setMessage(id, notice.print("1 unsaved pane \u{2014} {s} again to discard", .{word})); p.fs.unlogged = false; - return std.fmt.bufPrint(&p.fs.ename, "{s}: Modified ({s} again to discard)", .{ f.path[0..@min(f.path.len, 256)], word[0..@min(word.len, 16)] }) catch unreachable; // 256, 16 and 33 fit 320 + return std.fmt.bufPrint(&p.fs.ename, "{s}: Modified ({s} again to discard)", .{ f.path[0..@min(f.path.len, 256)], word[0..@min(word.len, 16)] }) catch &p.fs.ename; // cut to ename's 320 } /// acme's `Get file`, and Edit's `e file`: the file at `path` (absolute) |
