summaryrefslogtreecommitdiff
path: root/src/Core.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core.zig')
-rw-r--r--src/Core.zig27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/Core.zig b/src/Core.zig
index 5c68a5af..bbacc536 100644
--- a/src/Core.zig
+++ b/src/Core.zig
@@ -91,6 +91,9 @@ const Pardes = @This();
gpa: std.mem.Allocator,
image_gpa: std.mem.Allocator,
+/// Its kinds of pane (Kind.zig): the compiled-in ones, then what addons
+/// brought; the data both cores hold, the code only the authority.
+kinds: pardes.Kind.Registry = .{},
pdf_gpa: std.mem.Allocator,
tree_sitter_gpa: std.mem.Allocator,
opts: Options,
@@ -460,6 +463,7 @@ pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes {
p.* = .{
.gpa = gpa,
.image_gpa = opts.image_allocator orelse gpa,
+ .kinds = .started(opts.addons),
.pdf_gpa = opts.pdf_allocator orelse gpa,
.tree_sitter_gpa = opts.tree_sitter_allocator orelse gpa,
.opts = opts,
@@ -508,7 +512,7 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes {
const opened = initial_doc: {
if (comptime pdf_enabled) if (look.isPdfPath(path))
break :initial_doc pardes.panes.Pdf.openPane(p, 0, path, opts.file_line, .last);
- if (pardes.Kind.forPath(path)) |kind|
+ if (p.kinds.forPath(path)) |kind|
break :initial_doc pardes.Kind.openFile(p, 0, kind, path);
break :initial_doc pardes.panes.File.open(p, 0, path, opts.file_line);
};
@@ -1192,7 +1196,7 @@ pub fn dropPendingWrite(p: *Pardes, id: usize) void {
pub fn postEvent(p: *Pardes, ev: Event) void {
switch (ev) {
.key => |k| std.debug.assert(k.text.len == 0),
- .output, .paste, .lsp_resp, .pipe_resp, .search, .file_changed, .command, .addon => unreachable,
+ .output, .paste, .lsp_resp, .pipe_resp, .search, .file_changed, .command, .addon, .job => unreachable,
else => {},
}
if (p.in_len == p.in_q.len) return;
@@ -1623,7 +1627,8 @@ pub fn update(p: *Pardes, ev: Event) void {
if (focused) if (p.host.vtable.newer_build) |f| if (f(p.host.ctx)) p.setMessage(p.active, newer_build_words);
},
.handed => |h| p.handover.finish(p, h.seq, h.to, h.failure),
- .addon => |a| pardes.Kind.landed(p, a.op, a.pane, a.ok, a.text),
+ .addon => |a| pardes.Addon.landed(p, a.op, a.pane, a.kind.*),
+ .job => |j| pardes.Kind.jobDone(p, j.pane, j.serial, j.token, j.gen, j.bytes),
.frontend => |f| {
p.frontend = f;
},
@@ -2166,6 +2171,8 @@ pub const Options = struct {
recent_import: ?[]const u8 = null,
startup_config_path: ?[]const u8 = null,
image_allocator: ?std.mem.Allocator = null,
+ /// What the host's scan of the addon directories found (Addon.scan).
+ addons: []const pardes.Kind.Loaded = &.{},
pdf_allocator: ?std.mem.Allocator = null,
tree_sitter_allocator: ?std.mem.Allocator = null,
/// Where each frame's Surface text is built. Hosts pass a purpose-built
@@ -2471,7 +2478,7 @@ test "Filter is ordered after Del and toggles only its terminal or +Pager pane"
try testing.expect(!first.tty_filter);
const doc_id = p.freeSlot().?;
- const doc = try pardes.Kind.open(p, doc_id, &image.kind, "/tmp/filter-inert.ppm", "");
+ const doc = try pardes.Kind.open(p, doc_id, pardes.Kind.image, "/tmp/filter-inert.ppm", "");
try testing.expect(!doc.tty_filter);
try testing.expect(p.executeBuiltinLine(doc_id, "Filter"));
try testing.expect(!doc.tty_filter);
@@ -2641,7 +2648,7 @@ test "unknown Exec from a document runs as a command pane in its directory, type
// A terminal free at a prompt in the same directory is not borrowed.
p.setCwd(0, "/tmp/pardes-image-dir");
- const image_doc = try pardes.Kind.open(p, 1, &image.kind, "/tmp/pardes-image-dir/pic.ppm", null);
+ const image_doc = try pardes.Kind.open(p, 1, pardes.Kind.image, "/tmp/pardes-image-dir/pic.ppm", null);
try std.testing.expectEqualStrings("/tmp/pardes-image-dir", Pardes.paneDir(image_doc));
const dst = exec.execute(p, 1, "echo image-fallback") orelse return error.ExecFoundNowhereToRun;
try std.testing.expect(dst != 0 and dst != 1);
@@ -2695,7 +2702,7 @@ test "a command of several lines keeps its tag one row, and its echo does not st
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 });
defer p.deinit();
while (p.nextEffect()) |_| {}
- _ = try pardes.Kind.open(p, 1, &image.kind, "/tmp/pic.ppm", null);
+ _ = try pardes.Kind.open(p, 1, pardes.Kind.image, "/tmp/pic.ppm", null);
const two = "def greet(name):\n return name\n\nprint(greet(\"x\"))\n";
const dst = exec.execute(p, 1, two) orelse return error.NoCommandPane;
while (p.nextEffect()) |_| {}
@@ -3043,7 +3050,7 @@ test "a command pane shows how its command ended, and the next command there run
defer p.deinit();
while (p.nextEffect()) |_| {}
p.setCwd(0, "/tmp/pardes-cmd");
- _ = try pardes.Kind.open(p, 1, &image.kind, "/tmp/pardes-cmd/pic.ppm", null);
+ _ = try pardes.Kind.open(p, 1, pardes.Kind.image, "/tmp/pardes-cmd/pic.ppm", null);
const dst = exec.execute(p, 1, "make -j8") orelse return error.NoCommandPane;
while (p.nextEffect()) |_| {}
@@ -3143,7 +3150,7 @@ test "image dump restores source bytes renderer choices and exact custom tail" {
p.panes[0] = null;
const source = "\x00embedded image bytes\xff";
- const pane = try pardes.Kind.open(p, 0, &image.kind, "/missing/restored-image.ppm", source);
+ const pane = try pardes.Kind.open(p, 0, pardes.Kind.image, "/missing/restored-image.ppm", source);
pane.addon.?.art = .{ .glyph = true, .palette = .terminal, .ascii = false };
if (pane.tag.own) |own| p.gpa.free(own);
pane.tag.own = try p.gpa.dupe(u8, " Keep Del");
@@ -3166,8 +3173,8 @@ test "image dump restores source bytes renderer choices and exact custom tail" {
try dump.dumpState(restored);
const again = try dump.load(gpa, .{ .tty_only = true }, restored.dump_out.?, null);
defer again.deinit();
- const again_slot = again.panes[0].?.addon.?;
- try std.testing.expectEqualSlices(u8, source, kept[0..image.kind.dump.?(again_slot.st, &kept, kept.len)]);
+ // Loaded as a replica loads it: a placeholder holding the record.
+ try std.testing.expectEqualSlices(u8, source, again.panes[0].?.addon.?.record.?);
}
test "a terminal its program gave back takes command lines again" {