summaryrefslogtreecommitdiff
path: root/src/config.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-01 13:05:10 -0300
committerGabriel Schneider <[email protected]>2026-10-01 13:16:47 -0300
commitf700b2af8e874c586e6996b8311c3983203c6637 (patch)
tree89c7de940f888a0917e5851c8a362c83de50b389 /src/config.zig
parentf6a511c61d7ef2ff680f70077b236559a595be69 (diff)
downloadpardes-f700b2af8e874c586e6996b8311c3983203c6637.tar.gz
pardes-f700b2af8e874c586e6996b8311c3983203c6637.zip
Builtins are chips that link to a glossary generated from the registry, and the virtual filesystem is drawn as a tree
#word draws a builtin as a chip on the tag's ground over a rule (Look and Exec in acme's look green and exec red), a <code class="word"> in HTML, and links it to its entry in a new Builtins chapter wherever that chapter is in the same output (the book, the site). The chapter is drawn from docs/typ/builtins-tty.json and builtins-gui.json, which `zig build builtins-json -Dplatform=tty|gui` writes from the registry and the Help rows (src/builtins_json.zig, tools/gen_builtins_json.zig; summaryOf in ninep/ctl.zig is now pub); style.typ merges them, marking the window-only words. The doc steps refresh their build's file first, and each build's unit-test fails when its file is stale. Everyday words first (`everyday` in style.typ), then groups by leader prefix as Help has them, then settings, the words with no path, debugging and internals, and last an A-Z index of every word. `zig build book` joins the doc steps. #fstree draws a directory tree with its connectors, a description column and links to the sections that document each file; reference.typ draws the served tree with it, each pane, pty and column file on its own line, and a test in config.zig checks it against ninep/tree.zig's files both ways. The cheatsheet has a two-level version. On the site the tree reads as `tree` text in w3m and wraps descriptions under the names on a phone. The site's tutor draws its B1, B2, B3 and 1-2 chords as mouse glyphs; the landing credits Plan 9 and acme, as does the book's title page; install.typ no longer lists the mirrors (the footer does). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/config.zig')
-rw-r--r--src/config.zig71
1 files changed, 70 insertions, 1 deletions
diff --git a/src/config.zig b/src/config.zig
index e9595a2a..f83e7945 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -2101,9 +2101,16 @@ const doc_typ = struct {
}
}
+ /// The other build's builtins (docs/typ/builtins-*.json), so the docs
+ /// may name a window-only word in a terminal build's test, and back.
+ var other_build: []const u8 = "";
+
fn word(w: []const u8) bool {
const name = w[0 .. std.mem.indexOfScalar(u8, w, '+') orelse w.len];
- return std.meta.stringToEnum(Builtin, name) != null;
+ if (std.meta.stringToEnum(Builtin, name) != null) return true;
+ var buf: [96]u8 = undefined;
+ const needle = std.fmt.bufPrint(&buf, "{{\"name\": \"{s}\",", .{name}) catch return false;
+ return std.mem.indexOf(u8, other_build, needle) != null;
}
fn chord(tok: []const u8) ?Chord {
@@ -2195,6 +2202,10 @@ test "docs/typ names only words, keys and default tags that exist" {
var dir = try std.Io.Dir.cwd().openDir(io, @import("doc_typ").dir, .{ .iterate = true });
defer dir.close(io);
var found: [3]std.ArrayList([]const u8) = @splat(.empty);
+ for ([_][]const u8{ "builtins-tty.json", "builtins-gui.json" }) |f| {
+ const text = dir.readFileAlloc(io, f, gpa, .limited(1 << 20)) catch continue;
+ doc_typ.other_build = try std.mem.concat(gpa, u8, &.{ doc_typ.other_build, text });
+ }
var it = dir.iterate();
while (try it.next(io)) |entry| if (entry.kind == .file and std.mem.endsWith(u8, entry.name, ".typ")) {
const source = try dir.readFileAlloc(io, entry.name, gpa, .limited(1 << 20));
@@ -2331,3 +2342,61 @@ test "the tutor names only words, keys, paths and default tags that exist" {
}
}
}
+
+test "reference.typ's #fstree is the tree the session serves, file for file" {
+ const tree = @import("ninep/tree.zig");
+ var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
+ defer arena.deinit();
+ const gpa = arena.allocator();
+ const io = std.testing.io;
+ var dir = try std.Io.Dir.cwd().openDir(io, @import("doc_typ").dir, .{});
+ defer dir.close(io);
+ const source = try dir.readFileAlloc(io, "reference.typ", gpa, .limited(1 << 20));
+ const open = "#fstree(```";
+ const start = (std.mem.indexOf(u8, source, open) orelse return error.NoFsTree) + open.len;
+ const end = std.mem.indexOfPos(u8, source, start, "```)") orelse return error.NoFsTree;
+
+ // what the reference draws: a path per line, from its indent
+ var drawn: std.StringArrayHashMapUnmanaged(void) = .empty;
+ var stack: [8][]const u8 = undefined;
+ var lines = std.mem.tokenizeScalar(u8, source[start..end], '\n');
+ while (lines.next()) |line| {
+ const body = std.mem.trimStart(u8, line, " ");
+ if (body.len == 0) continue;
+ const depth = (line.len - body.len) / 2;
+ const name = body[0 .. std.mem.indexOfScalar(u8, body, ' ') orelse body.len];
+ stack[depth] = name;
+ var path: std.ArrayList(u8) = .empty;
+ for (stack[0 .. depth + 1]) |part| try path.appendSlice(gpa, part);
+ try drawn.put(gpa, path.items, {});
+ }
+
+ // what the session serves: tree.zig's files, and fs.zig's os/ and src/
+ var served: std.StringArrayHashMapUnmanaged(void) = .empty;
+ for (std.enums.values(tree.TopFile)) |f| switch (f) {
+ .root => {},
+ .new => try served.put(gpa, "pane/new", {}),
+ else => try served.put(gpa, if (f.dir()) try std.fmt.allocPrint(gpa, "{s}/", .{f.fileName()}) else f.fileName(), {}),
+ };
+ try served.put(gpa, "os/", {});
+ try served.put(gpa, "src/", {});
+ try served.put(gpa, "pane/<n>/", {});
+ for (std.enums.values(tree.PaneFile)) |f| if (f != .dir) {
+ const under = if (f.inPty() and f != .pty) "pane/<n>/pty/" else "pane/<n>/";
+ try served.put(gpa, try std.fmt.allocPrint(gpa, "{s}{s}{s}", .{ under, f.fileName(), if (f.isDir()) "/" else "" }), {});
+ };
+ try served.put(gpa, "col/<n>/", {});
+ for (std.enums.values(tree.ColFile)) |f| if (f != .dir)
+ try served.put(gpa, try std.fmt.allocPrint(gpa, "col/<n>/{s}", .{f.fileName()}), {});
+
+ var drift = false;
+ for (served.keys()) |k| if (!drawn.contains(k)) {
+ std.debug.print("reference.typ's tree lacks {s}\n", .{k});
+ drift = true;
+ };
+ for (drawn.keys()) |k| if (!served.contains(k)) {
+ std.debug.print("reference.typ's tree has {s}, which the session does not serve\n", .{k});
+ drift = true;
+ };
+ if (drift) return error.FsTreeDrift;
+}