summaryrefslogtreecommitdiff
path: root/src/config.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 06:24:42 -0300
committerGabriel Schneider <[email protected]>2026-11-06 11:19:44 -0300
commitc1917b949b9580de8bf0977874a210f0266812da (patch)
tree447dd2235ea00634f662cd3becf4bceb8a895f41 /src/config.zig
parent76c55b5bce0f181b0b15b16596c900397dfef544 (diff)
downloadpardes-c1917b949b9580de8bf0977874a210f0266812da.tar.gz
pardes-c1917b949b9580de8bf0977874a210f0266812da.zip
kinds #14, the core's PDF code gone: pdf.zig and pdf_view.zig leave and every pdf_enabled branch with them; look, Jump, Recent, dumps (one from before the addon opens as its pane), the watch, mouse, keys, the rail and the tag go through Kind for any kind's pane; test/pdf.zig's behaviours are T1 cases over 9P (addons_pdf.zig) and pane cases (a Shadow over a replica, a file changed under it), the harnesses load pdf.so by path
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/config.zig')
-rw-r--r--src/config.zig49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/config.zig b/src/config.zig
index f9fd336f..17a7305a 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -17,7 +17,7 @@ pub const Chord = struct {
};
// Leader paths apply wherever normal mode reads keys: a body's, a tag's
-// (column and workspace tags too) and a PDF's, never a raw terminal's
+// (column and workspace tags too) and a kind's pane's, never a raw terminal's
// (normal.zig takes `.leader` for every target).
pub const leader: []const Chord = &.{.{ .cp = ' ' }};
@@ -164,11 +164,6 @@ pub const leader_path = paths: {
table.set(.Adopt, null);
table.set(.Upgrade, "sU");
}
- if (pardes.pdf_enabled) {
- table.set(.PdfTint, "ti");
- table.set(.PdfSections, "ts");
- table.set(.PdfFit, "tz");
- }
for (std.enums.values(Builtin)) |b| if (table.get(b)) |p| {
if (std.mem.eql(u8, p, undecided)) @compileError("builtin has no leader path decided: " ++ @tagName(b));
};
@@ -280,7 +275,6 @@ pub const child_term_program = "pardes";
pub const topbar_str = "Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config Debug Exit";
pub const pane_builtins_str = "Term Collapse Del";
-pub const pdf_pane_builtins_str = "Term PdfSections PdfTint PdfFit Collapse Del";
pub const file_pane_builtins_str = "Save Term Collapse Del";
/// After a file's, on one a language server speaks for.
pub const lsp_pane_builtins_str = "Def Refs";
@@ -497,9 +491,7 @@ pub const preview_buffer = "+Preview";
pub const unsaved_buffer = "+Unsaved";
pub const themes_buffer = "+Themes";
pub const fonts_buffer = "+Fonts";
-pub const pdf_sections_buffer = "+PdfSections";
pub const diff_buffer = "+Diff";
-pub const pdf_links_buffer = "+Links";
pub const hover_buffer = "+Hover";
pub const lsp_buffer = "+Lsp";
pub const changelog_buffer = "+Changelog";
@@ -1496,13 +1488,33 @@ 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 = "";
+ /// The shipped addons' sources (addons/*/*.c): their words are named
+ /// in the docs too, `PA_WORD("PdfFit", ...`.
+ var addon_sources: []const u8 = "";
+
+ fn loadAddons(gpa: std.mem.Allocator) !void {
+ const io = std.testing.io;
+ var root = try std.Io.Dir.cwd().openDir(io, @import("doc_typ").addons, .{ .iterate = true });
+ defer root.close(io);
+ var kinds = root.iterate();
+ while (try kinds.next(io)) |k| if (k.kind == .directory) {
+ var sub = try root.openDir(io, k.name, .{ .iterate = true });
+ defer sub.close(io);
+ var files = sub.iterate();
+ while (try files.next(io)) |f| if (std.mem.endsWith(u8, f.name, ".c")) {
+ addon_sources = try std.mem.concat(gpa, u8, &.{ addon_sources, try sub.readFileAlloc(io, f.name, gpa, .limited(1 << 20)) });
+ };
+ };
+ }
fn word(w: []const u8) bool {
const name = w[0 .. std.mem.indexOfScalar(u8, w, '+') orelse w.len];
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;
+ if (std.mem.indexOf(u8, other_build, needle) != null) return true;
+ const addon = std.fmt.bufPrint(&buf, "PA_WORD(\"{s}\",", .{name}) catch return false;
+ return std.mem.indexOf(u8, addon_sources, addon) != null;
}
fn chord(tok: []const u8) ?Chord {
@@ -1585,9 +1597,18 @@ const doc_typ = struct {
if (w.end > 0) w.writeByte(' ') catch return false;
w.writeAll(x[0 .. std.mem.indexOfScalar(u8, x, '+') orelse x.len]) catch return false;
}
- const tags = [_][]const u8{ topbar_str, @import("tagline.zig").column_tag_default, pane_builtins_str, pdf_pane_builtins_str, file_pane_builtins_str, diff_pane_builtins_str, pager_pane_builtins_str, pager_diff_pane_builtins_str, diff_view_builtins_str, terminal_pane_builtins_str, command_pane_builtins_str, dir_pane_builtins_str };
+ const tags = [_][]const u8{ topbar_str, @import("tagline.zig").column_tag_default, pane_builtins_str, file_pane_builtins_str, diff_pane_builtins_str, pager_pane_builtins_str, pager_diff_pane_builtins_str, diff_view_builtins_str, terminal_pane_builtins_str, command_pane_builtins_str, dir_pane_builtins_str };
for (tags) |d| if (std.mem.eql(u8, d, w.buffered())) return true;
- return false;
+ // A kind's pane's: Term, its addon's words, Collapse Del (Kind.zig).
+ const shown = w.buffered();
+ if (!std.mem.startsWith(u8, shown, "Term ") or !std.mem.endsWith(u8, shown, " Collapse Del")) return false;
+ var mid = std.mem.tokenizeScalar(u8, shown["Term ".len .. shown.len - " Collapse Del".len], ' ');
+ while (mid.next()) |x| {
+ var buf: [96]u8 = undefined;
+ const addon = std.fmt.bufPrint(&buf, "PA_WORD(\"{s}\",", .{x}) catch return false;
+ if (std.mem.indexOf(u8, addon_sources, addon) == null) return false;
+ }
+ return true;
}
};
@@ -1601,6 +1622,8 @@ test "docs/typ names only words, keys and default tags that exist" {
var found: [3]std.ArrayList([]const u8) = @splat(.empty);
// The arena's: gone with this test, so no later test reads it.
defer doc_typ.other_build = "";
+ defer doc_typ.addon_sources = "";
+ try doc_typ.loadAddons(gpa);
for ([_][]const u8{ "builtins-tui.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 });
@@ -1701,6 +1724,8 @@ test "the tutor names only words, keys, paths and default tags that exist" {
defer arena.deinit();
const gpa = arena.allocator();
const tutor = @embedFile("tutor.txt");
+ defer doc_typ.addon_sources = "";
+ try doc_typ.loadAddons(gpa);
var found: std.ArrayList([]const u8) = .empty;
try doc_tutor.words(gpa, tutor, &found);