summaryrefslogtreecommitdiff
path: root/src/Core.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Core.zig')
-rw-r--r--src/Core.zig53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/Core.zig b/src/Core.zig
index 76f59247..54f0233e 100644
--- a/src/Core.zig
+++ b/src/Core.zig
@@ -508,8 +508,8 @@ 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 (look.isImagePath(path))
- break :initial_doc pardes.panes.Image.create(p, 0, path, &.{});
+ if (pardes.Kind.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);
};
if (opened) |_| {} else |err| {
@@ -660,11 +660,11 @@ pub fn noteClosed(p: *Pardes, pane: *const Pane) void {
pub const RecentPlace = struct { path: []const u8, line: u32, col: u32, aline: u32 = 0, acol: u32 = 0 };
/// Where a pane is, as Recent keeps it: a file's dot, a PDF's page
-/// (`:page:1`), an image's path alone (line 0). Null for any other.
+/// (`:page:1`), a kind's pane's path alone (line 0). Null for any other.
pub fn recentPlace(pane: *const Pane) ?RecentPlace {
if (recentDot(pane)) |d| return .{ .path = d.path, .line = d.line, .col = d.col, .aline = d.aline, .acol = d.acol };
if (pane.pdfPath()) |path| return .{ .path = path, .line = @intCast(pane.pdfPage().? + 1), .col = 1 };
- if (pane.image) |iv| return .{ .path = iv.path, .line = 0, .col = 0 };
+ if (pane.addon) |k| if (k.path.len > 0) return .{ .path = k.path, .line = 0, .col = 0 };
return null;
}
@@ -1635,6 +1635,8 @@ pub fn update(p: *Pardes, ev: Event) void {
look.advanceLookHover(p);
},
}
+ // Each kind's pane whose time has come steps, and its jobs' answers land.
+ pardes.Kind.step(p);
// Each pane's places find a frame's more on a tick, and on any other
// step the ones an edit or a scroll left unfound in the view.
for (p.panes) |slot| if (slot) |pane| pane.places.settle(p, pane, ev == .tick);
@@ -1924,7 +1926,8 @@ pub fn nextWake(p: *const Pardes) ?u64 {
// Places still to find resume on the next frame; a picture being
// decoded is looked for.
for (p.panes) |slot| if (slot) |pane| if (pane.places.busy(pane)) return next;
- for (p.panes) |slot| if (slot) |pane| if (pane.image) |iv| if (iv.decoder != null) return next;
+ const kinds = pardes.Kind.wake(p);
+ if (kinds) |due| if (due <= next) return next;
// A PDF page being rendered on a lane lands on the frame after it is done.
if (comptime pdf_enabled) for (p.panes) |slot| if (slot) |pane| if (pane.pdf) |st| if (pardes.panes.Pdf.rendering(st)) return next;
// A markdown text's tables still being read from the top (Tables.zig).
@@ -1965,6 +1968,11 @@ pub fn nextWake(p: *const Pardes) ?u64 {
frames = if (frames) |soonest| @min(soonest, wait) else wait;
}
};
+ // A kind's next tick (Kind.zig).
+ if (kinds) |due| {
+ const wait = @max(1, (due -| p.clock.stepped_ns + frame_ns - 1) / frame_ns);
+ frames = if (frames) |soonest| @min(soonest, wait) else wait;
+ }
return if (frames) |n| p.clock.stepped_ns + n * frame_ns else null;
}
@@ -2461,7 +2469,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.panes.Image.create(p, doc_id, "/tmp/filter-inert.ppm", &.{});
+ const doc = try pardes.Kind.open(p, doc_id, &image.kind, "/tmp/filter-inert.ppm", "");
try testing.expect(!doc.tty_filter);
try testing.expect(p.executeBuiltinLine(doc_id, "Filter"));
try testing.expect(!doc.tty_filter);
@@ -2631,8 +2639,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 p.newDocPane(1);
- image_doc.image = .{ .path = try gpa.dupe(u8, "/tmp/pardes-image-dir/pic.ppm") };
+ const image_doc = try pardes.Kind.open(p, 1, &image.kind, "/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);
@@ -2686,8 +2693,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()) |_| {}
- const doc = try p.newDocPane(1);
- doc.image = .{ .path = try gpa.dupe(u8, "/tmp/pic.ppm") };
+ _ = try pardes.Kind.open(p, 1, &image.kind, "/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()) |_| {}
@@ -3035,8 +3041,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");
- const doc = try p.newDocPane(1);
- doc.image = .{ .path = try gpa.dupe(u8, "/tmp/pardes-cmd/pic.ppm") };
+ _ = try pardes.Kind.open(p, 1, &image.kind, "/tmp/pardes-cmd/pic.ppm", null);
const dst = exec.execute(p, 1, "make -j8") orelse return error.NoCommandPane;
while (p.nextEffect()) |_| {}
@@ -3136,14 +3141,8 @@ test "image dump restores source bytes renderer choices and exact custom tail" {
p.panes[0] = null;
const source = "\x00embedded image bytes\xff";
- const raw = try p.image_gpa.dupe(u8, source);
- const pane = pardes.panes.Image.create(p, 0, "/missing/restored-image.ppm", raw) catch |err| {
- p.image_gpa.free(raw);
- return err;
- };
- pane.image.?.glyph_art = true;
- pane.image.?.pmode = .terminal;
- pane.image.?.ascii = false;
+ const pane = try pardes.Kind.open(p, 0, &image.kind, "/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");
try dump.dumpState(p);
@@ -3151,18 +3150,22 @@ test "image dump restores source bytes renderer choices and exact custom tail" {
const restored = try dump.initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?);
defer restored.deinit();
const restored_pane = restored.panes[0].?;
- try std.testing.expect(restored_pane.image.?.glyph_art);
- try std.testing.expectEqual(image.PaletteMode.terminal, restored_pane.image.?.pmode);
- try std.testing.expect(!restored_pane.image.?.ascii);
+ const art = restored_pane.addon.?.art;
+ try std.testing.expect(art.glyph);
+ try std.testing.expectEqual(image.PaletteMode.terminal, art.palette);
+ try std.testing.expect(!art.ascii);
try std.testing.expect(restored_pane.tag.own != null);
try std.testing.expectEqualStrings(" Keep Del", tagline.curTail(restored_pane));
- try std.testing.expectEqualSlices(u8, source, restored_pane.image.?.raw);
+ var kept: [64]u8 = undefined;
+ const slot = restored_pane.addon.?;
+ try std.testing.expectEqualSlices(u8, source, kept[0..image.kind.dump.?(slot.st, &kept, kept.len)]);
// And dumped again, its bytes still there.
try dump.dumpState(restored);
const again = try dump.load(gpa, .{ .tty_only = true }, restored.dump_out.?, null);
defer again.deinit();
- try std.testing.expectEqualSlices(u8, source, again.panes[0].?.image.?.raw);
+ const again_slot = again.panes[0].?.addon.?;
+ try std.testing.expectEqualSlices(u8, source, kept[0..image.kind.dump.?(again_slot.st, &kept, kept.len)]);
}
test "a terminal its program gave back takes command lines again" {