diff options
Diffstat (limited to 'src/ninep')
| -rw-r--r-- | src/ninep/ctl.zig | 17 | ||||
| -rw-r--r-- | src/ninep/pane.zig | 2 | ||||
| -rw-r--r-- | src/ninep/tree.zig | 27 |
3 files changed, 36 insertions, 10 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index 68fefbc5..a65b3562 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -408,7 +408,7 @@ fn writeQuoted(w: *std.Io.Writer, s: []const u8) !void { try w.writeByte('\''); } -pub const pane_text_cap = 9 * 12 + 2 * 256 + 4 + "notcurrent ".len + 48 + "collapsed fit:height tint:filtered mode:insert ".len; +pub const pane_text_cap = 9 * 12 + 2 * 256 + 4 + "notcurrent ".len + 48 + "collapsed fit:height tint:filtered mode:insert ".len + 129; /// acme's winctlprint (plan9port wind.c), field for field: serial, tag /// length, body length, isdir (1 for a directory pane), the dirty flag, @@ -444,6 +444,11 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: []u8) []const u8 { // PdfTint, in the words they take. if (pane.collapsed) w.writeAll("collapsed ") catch {}; if (comptime pardes.pdf_enabled) if (pane.pdf) |pv| w.print("fit:{s} tint:{s} ", .{ @tagName(pv.fit), @tagName(pv.tint) }) catch {}; + 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 {}; + } // 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 {}; @@ -521,6 +526,8 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ? const arg = if (sp) |s| std.mem.trim(u8, line[s + 1 ..], " \t") else ""; const here = if (std.meta.stringToEnum(Builtin, word)) |b| builtins.registry.here(p, b) else false; const b = (if (here) std.meta.stringToEnum(Builtin, word) else null) orelse { + // An addon's word: its kind's to take or refuse as it runs. + if (pardes.Kind.word(word) != null) return null; // A setting this build's frontend cannot show (Lift, GripWidth on a // terminal, the window's own words in a terminal's view) is known, // and says so rather than sound misspelt. @@ -890,6 +897,14 @@ fn writeCommands(p: *const Pardes, w: *std.Io.Writer) !void { } try w.writeByte('\n'); } + // The addons' words, after the core's: `(addon <name>)` says whose. + for (pardes.Kind.wordsOf()) |kw| try w.print("{s}{s} {s} -- {s} (addon {s})\n", .{ + std.mem.span(kw.w.name), + if (kw.w.arg != pardes.Kind.c.PA_ARG_NONE) " arg" else "", + if (kw.w.opens != 0) "both" else "pane", + if (kw.w.doc == null) "" else std.mem.span(kw.w.doc), + pardes.Kind.headName(kw.ops), + }); } /// /commands' text (`writeCommands`), in the step's scratch. diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig index 49fa46c6..3b982803 100644 --- a/src/ninep/pane.zig +++ b/src/ninep/pane.zig @@ -454,7 +454,9 @@ fn readFlag(p: *Pardes, req: Req, on: bool) Reply { /// The text layer of the page a PDF pane shows (MuPDF's extraction, kept /// with the page), null for any other pane. +/// A document's text, read-only: a PDF's text layer, a kind's `body`. fn pdfText(p: *Pardes, pane: *Pane) ?[]const u8 { + if (pane.addon != null) return pardes.Kind.body(pane, p.scratch.allocator()) catch null; if (comptime !pardes.pdf_enabled) return null; const pv = pane.pdf orelse return null; return pv.ensureText(p.pdf_gpa); diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index 1b6c242e..9c3de708 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -265,6 +265,10 @@ pub const TopFile = enum(u5) { /// first: `<label> <date> <size> <panes>`; `Restore <label>` brings one /// back. dumps, + /// The kinds of pane this session has, compiled in or an addon's, and + /// the addons refused, a line each: `<kind> <version> <abi> + /// static|loaded|refused: why [path]`. + addons, pub fn fileName(f: TopFile) []const u8 { return if (f == .root) "/" else @tagName(f); @@ -274,7 +278,7 @@ pub const TopFile = enum(u5) { return switch (f) { .root, .pane, .col => 0o755, .look, .exec, .log, .focus, .ctl, .tag, .tagexec, .pager => 0o666, - .README, .index, .status, .screen, .listeners, .new, .commands, .layout, .recent, .dumps, .sessions => 0o444, + .README, .index, .status, .screen, .listeners, .new, .commands, .layout, .recent, .dumps, .sessions, .addons => 0o444, .kbdin, .mousein => 0o222, }; } @@ -675,7 +679,7 @@ fn topSize(p: *Pardes, f: TopFile) u64 { // frame, /pane/new until an open has a pane to name, and the index, // layout, recent list and listeners, which a stat would otherwise // have to build to count. - .root, .pane, .col, .screen, .new, .layout, .index, .recent, .dumps, .listeners, .sessions, .kbdin, .mousein => 0, + .root, .pane, .col, .screen, .new, .layout, .index, .recent, .dumps, .addons, .listeners, .sessions, .kbdin, .mousein => 0, .tag => cols.headerText(p, null).?.len, .README => fs.help.len, .status => ctl.statusText(p).len, @@ -759,7 +763,7 @@ fn readdir(p: *Pardes, req: Req, target: Target) Reply { .root => { // The guide, then what describes the session, then the // files that act, then the directories. - inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.dumps, TopFile.look, TopFile.exec, TopFile.pager, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.sessions, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.kbdin, TopFile.mousein, TopFile.pane, TopFile.col }) |t| { + inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.dumps, TopFile.addons, TopFile.look, TopFile.exec, TopFile.pager, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.sessions, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.kbdin, TopFile.mousein, TopFile.pane, TopFile.col }) |t| { if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @backingInt(t), t.dir(), t.fileName()); } if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, fs.os_root, true, "os"); @@ -847,7 +851,7 @@ fn open(p: *Pardes, req: Req, target: Target) Reply { }, .screen => .{ .snapshot = null }, .log => .{ .log = .{} }, - .index, .layout, .recent, .dumps, .commands, .status, .listeners, .sessions => .{ .frozen = &.{} }, + .index, .layout, .recent, .dumps, .addons, .commands, .status, .listeners, .sessions => .{ .frozen = &.{} }, // The root's ctl opened only to read: its settings, frozen. .ctl => if (linesOpen(target, req)) .lines else .{ .frozen = &.{} }, else => if (linesOpen(target, req)) .lines else return .{ .tag = req.tag }, @@ -1107,6 +1111,11 @@ fn readFile(p: *Pardes, req: Req, target: Target) Reply { pardes.panes.Output.recentText(p, &text.writer, false) catch break :recent Reply.fail(req.tag, E.NOMEM); break :recent window(p, req, text.written()); }, + .addons => addons: { + var text: std.ArrayList(u8) = .empty; + pardes.Kind.list(p, &text, p.scratch.allocator()) catch break :addons Reply.fail(req.tag, E.NOMEM); + break :addons window(p, req, text.items); + }, .dumps => dumps: { // The state file read now, unless a step is out mid-syscall // (its database is the step's): then none. @@ -1546,13 +1555,13 @@ test "readdir lists the root and a pane directory without creating anything" { @memcpy(top_bytes[0..top_reply.bytes.len], top_reply.bytes); const top = th.dirents(top_bytes[0..top_reply.bytes.len], &buf); try testing.expect(top.len >= 10); - for ([_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "recent", "dumps", "look", "exec", "pager", "log", "screen", "listeners", "sessions", "layout", "tag", "tagexec", "kbdin", "mousein", "pane", "col", "os" }, 0..) |name, i| { + for ([_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "recent", "dumps", "addons", "look", "exec", "pager", "log", "screen", "listeners", "sessions", "layout", "tag", "tagexec", "kbdin", "mousein", "pane", "col", "os" }, 0..) |name, i| { try testing.expectEqualStrings(name, top[i].name); - try testing.expectEqual(i >= 20, top[i].dir); + try testing.expectEqual(i >= 21, top[i].dir); } - try testing.expectEqual(@backingInt(TopFile.pane), top[20].node); - try testing.expectEqual(@backingInt(TopFile.col), top[21].node); - try testing.expectEqual(fs.os_root, top[22].node); + try testing.expectEqual(@backingInt(TopFile.pane), top[21].node); + try testing.expectEqual(@backingInt(TopFile.col), top[22].node); + try testing.expectEqual(fs.os_root, top[23].node); var idbuf: [16]u8 = undefined; try testing.expect(th.nameAt(top, try std.fmt.bufPrint(&idbuf, "{d}", .{serial})) == null); try testing.expect(th.nameAt(top, "self") == null); |
