summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CHANGELOG.md7
-rw-r--r--src/builtins_json.zig50
2 files changed, 52 insertions, 5 deletions
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index 07c72846..8107f920 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -2,6 +2,13 @@
## Unreleased
+- MuPDF and FreeType are lazy: a fresh checkout's `zig build
+ -Dplatform=tui` fetches neither; `-Dpdf` fetches MuPDF the first time
+ (and is on by itself after), and without it the PDF steps say so.
+ The Zig kinds export `pardes_addon` from a library alone
+ (`addon.exportLib`), and a pardes off Linux has its addons compiled in,
+ as the static one does (`Addon load` there: `not on this platform`).
+ The glossary lists the PDF addon's words again.
- The PDF addon is Zig (`addons/pdf/pdf.zig`, over MuPDF through
`pdf_bridge.c`): each view of a PDF has its own layout of the one place
(a terminal's text layer and a window's pages at once), its search, its
diff --git a/src/builtins_json.zig b/src/builtins_json.zig
index e8ec5768..c5bc6bb3 100644
--- a/src/builtins_json.zig
+++ b/src/builtins_json.zig
@@ -2,7 +2,9 @@
//! and builtins-gui.json, a build's list each; style.typ merges them):
//! the rows the `Help` builtin draws (pardes.builtin_rows: the leader path
//! and the other shortcuts) with what /commands says of each word (its doc
-//! comment's first sentence, or a setting's doc). One source, so the
+//! comment's first sentence, or a setting's doc), then the shipped addons'
+//! words, read off their kinds' `Word` lines (`"addon"` first, so a search
+//! for a builtin's `{"name": ` never meets one). One source, so the
//! glossary and Help cannot drift; the test below fails when the committed
//! copy is stale, and `zig build builtins-json` rewrites it.
const std = @import("std");
@@ -19,7 +21,11 @@ fn lessName(_: void, a: Entry, b: Entry) bool {
return std.mem.lessThan(u8, a.name, b.name);
}
-pub fn write(w: *std.Io.Writer) std.Io.Writer.Error!void {
+/// The kinds whose words are listed (under addons/), their sources in
+/// this order.
+pub const addons = [_][]const u8{ "image/image.zig", "pdf/pdf.zig" };
+
+pub fn write(w: *std.Io.Writer, addon_sources: []const []const u8) std.Io.Writer.Error!void {
var all: [pardes.builtin_rows.len]Entry = undefined;
var len: usize = 0;
// This build's own frontend's words (a desktop build has the other's
@@ -35,6 +41,7 @@ pub fn write(w: *std.Io.Writer) std.Io.Writer.Error!void {
const row = pardes.builtin_rows[e.row];
const b = row.cmd;
const name = @tagName(b);
+ if (n > 0) try w.writeAll(",\n");
try w.writeAll(" {\"name\": ");
try str(name, .{}, w);
try w.writeAll(", \"leader\": ");
@@ -67,9 +74,35 @@ pub fn write(w: *std.Io.Writer) std.Io.Writer.Error!void {
const doc = if (setting) |s| s.doc else ctl.summaryOf(name, &buf);
try w.writeAll(", \"doc\": ");
try str(doc, .{}, w);
- try w.writeAll(if (n + 1 < order.len) "},\n" else "}\n");
+ try w.writeByte('}');
+ }
+ // A kind's word is a line of its own: `.{ .name = "PdfFit", .leader =
+ // "tz", .arg = .optional, .doc = "..." },` (a doc's Zig escapes are
+ // copied as written: none has one).
+ for (addon_sources) |source| {
+ var kind: []const u8 = "";
+ var lines = std.mem.splitScalar(u8, source, '\n');
+ while (lines.next()) |line| {
+ if (std.mem.indexOf(u8, line, "pub const head: addon.Head = ") != null) kind = quoted(line, ".name = ").?;
+ if (!std.mem.startsWith(u8, std.mem.trimStart(u8, line, " "), ".{ .name = \"")) continue;
+ try w.print(",\n {{\"addon\": \"{s}\", \"name\": \"{s}\", \"leader\": ", .{ kind, quoted(line, ".name = ").? });
+ if (quoted(line, ".leader = ")) |l| {
+ try w.writeAll("\"SPC");
+ for (l) |c| try w.print(" {c}", .{c});
+ try w.writeByte('"');
+ } else try w.writeAll("null");
+ try w.print(", \"also\": [], \"arg\": {}, \"scope\": \"pane\", \"setting\": false, \"choices\": null, \"doc\": ", .{std.mem.indexOf(u8, line, ".arg = .") != null});
+ try str(quoted(line, ".doc = ") orelse "", .{}, w);
+ try w.writeByte('}');
+ }
}
- try w.writeAll("]\n");
+ try w.writeAll("\n]\n");
+}
+
+/// The string after `field` on a line: `.name = "PdfFit"` is PdfFit.
+fn quoted(line: []const u8, comptime field: []const u8) ?[]const u8 {
+ const at = (std.mem.indexOf(u8, line, field ++ "\"") orelse return null) + field.len + 1;
+ return line[at .. std.mem.indexOfScalarPos(u8, line, at, '"') orelse return null];
}
test "docs/typ/builtins-<platform>.json is what the registry says now" {
@@ -84,7 +117,14 @@ test "docs/typ/builtins-<platform>.json is what the registry says now" {
const gpa = std.testing.allocator;
var out: std.Io.Writer.Allocating = .init(gpa);
defer out.deinit();
- try write(&out.writer);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var sources: [addons.len][]const u8 = undefined;
+ for (addons, &sources) |path, *source| {
+ var buf: [4096]u8 = undefined;
+ source.* = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, try std.fmt.bufPrint(&buf, "{s}/{s}", .{ @import("doc_typ").addons, path }), arena.allocator(), .limited(1 << 20));
+ }
+ try write(&out.writer, &sources);
var dir = try std.Io.Dir.cwd().openDir(std.testing.io, @import("doc_typ").dir, .{});
defer dir.close(std.testing.io);
const committed = try dir.readFileAlloc(std.testing.io, file, gpa, .limited(1 << 20));