summaryrefslogtreecommitdiff
path: root/src/panes.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/panes.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/panes.zig')
-rw-r--r--src/panes.zig76
1 files changed, 20 insertions, 56 deletions
diff --git a/src/panes.zig b/src/panes.zig
index cfe09f33..1ec78bbc 100644
--- a/src/panes.zig
+++ b/src/panes.zig
@@ -20,7 +20,6 @@ const Cell = pardes.Cell;
const BOX_H = pardes.BOX_H;
const MAX_PANES = pardes.MAX_PANES;
const effect_path_cap = pardes.effect_path_cap;
-const pdf_enabled = Pdf.enabled;
/// An owned editable buffer and the absolute surface row of its first line.
/// Files use row zero; terminal overlays may begin anywhere in scrollback.
@@ -35,9 +34,9 @@ pub const Pane = struct {
.derived = .{ "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "notices", "pan" },
.authority = .{"fs"},
.len = .{ .{ "msg", "msg_len" }, .{ "msg_older", "msg_older_len" }, .{ "question", "question_len" }, .{ "shell_tail", "shell_tail_len" }, .{ "sel_snap", "nsel_snap" } },
- // A picture's and a PDF's memory is their own allocators' (a dump
- // loaded makes it there).
- .alloc = .{ .{ "addon", "image" }, .{ "pdf", "pdf" }, .{ "terminal", "terminal" } },
+ // A picture's memory is its own allocator's (a dump loaded makes
+ // it there).
+ .alloc = .{ .{ "addon", "image" }, .{ "pdf", "image" }, .{ "terminal", "terminal" } },
};
/// The words that throw unsaved text away (builtins.zig warnModified).
pub const Discarding = enum { Exit, Restore, get, Del, Delcol };
@@ -78,10 +77,14 @@ pub const Pane = struct {
col1: i32,
};
- /// A PDF's state is its own allocation in the pdf region, as a
- /// terminal's is its own: inline, its raster slots would be every
- /// pane's, and every rollback copy's.
- const PdfSlot = if (Pdf.enabled) ?*Pdf.State else void;
+ /// A PDF pane as a dump of a build before the pdf addon kept it, read
+ /// to open it as the addon's (dump.zig revivePane); never written.
+ pub const LegacyPdf = struct {
+ path: []u8 = &.{},
+ page: usize = 0,
+ fit: enum { width, height } = .width,
+ tint: enum { disabled, filtered, full } = .filtered,
+ };
/// What an open prompt is asking. The answer is typed into `input`.
pub const Prompt = union(enum) {
@@ -203,7 +206,7 @@ pub const Pane = struct {
file: ?File.State = null,
/// A pane of a kind (Kind.zig): a picture, or one a library brought.
addon: ?*@import("Kind.zig").Slot = null,
- pdf: PdfSlot = if (Pdf.enabled) null else {},
+ pdf: ?*LegacyPdf = null,
prompt: Prompt = .none,
/// The text an open prompt answers for: `s`/`S` select in it and `|`
/// pipes it. A header's is whichever has the keyboard; `/` and Save's
@@ -502,8 +505,7 @@ pub const Pane = struct {
}
pub fn isTerminal(pane: *const Pane) bool {
- const no_pdf = if (comptime Pdf.enabled) pane.pdf == null else true;
- return pane.file == null and pane.addon == null and no_pdf;
+ return pane.file == null and pane.addon == null and pane.pdf == null;
}
/// The one coloring choice keyed on what a pane IS, so the highlight
@@ -526,16 +528,6 @@ pub const Pane = struct {
return .none;
}
- pub fn pdfPath(pane: *const Pane) ?[]const u8 {
- if (comptime Pdf.enabled) if (pane.pdf) |pv| return pv.path;
- return null;
- }
-
- pub fn pdfPage(pane: *const Pane) ?usize {
- if (comptime Pdf.enabled) if (pane.pdf) |pv| return pv.page;
- return null;
- }
-
pub fn surfRow(pane: *const Pane, g: i32) i32 {
const o = pane.ovl orelse return g;
if (g <= o.row) return g;
@@ -556,7 +548,6 @@ pub const Pane = struct {
/// current scroll offset: file top line, or the scrollback offset
pub fn scroll(pane: *Pane) i32 {
if (pane.file) |f| return @intCast(f.scroll);
- if (comptime Pdf.enabled) if (pane.pdf) |pv| return @intCast(pv.text_scroll);
return pane.surfRow(terminal.gridOffset(pane) + pane.pan);
}
@@ -592,17 +583,7 @@ pub const Pane = struct {
f.scroll = next;
f.syntax_dirty = true;
}
- } else if (hasPdf(pane)) {
- if (comptime Pdf.enabled) {
- const pv = pane.pdf.?;
- const max: i64 = @intCast(modal.lineCount(pv.text) -| 1);
- pv.text_scroll = @intCast(std.math.clamp(
- @as(i64, @intCast(pv.text_scroll)) + delta,
- 0,
- max,
- ));
- }
- } else {
+ } else if (pane.addon == null) {
// the vt scrolls in SHELL rows; convert through the edit buffer
const off = terminal.gridOffset(pane);
terminal.scrollGrid(pane, pane.gridRow(pane.surfRow(off) + delta) - off);
@@ -654,10 +635,6 @@ pub const Pane = struct {
const lines: i32 = @intCast(File.nlines(pane.gpa, f));
to = @min(to, if (off == 0 and pane.textFits()) @max(pane.body.cur_row, lines - 1 - @intFromBool(std.mem.endsWith(u8, f.content, "\n"))) else lines - 1);
}
- if (comptime Pdf.enabled) {
- if (pane.pdf) |pv|
- to = @min(to, @as(i32, @intCast(modal.lineCount(pv.text) -| 1)));
- }
pane.scrollBy(@max(0, to - last));
}
}
@@ -685,7 +662,7 @@ pub const Pane = struct {
pub fn pinCursor(pane: *Pane) void {
if (pane.body.cur_pinned) return;
- if (pane.file != null or hasPdf(pane)) {
+ if (pane.file != null or pane.addon != null) {
pane.body.cur_row = pane.scroll();
pane.body.cur_col = 0;
} else {
@@ -695,17 +672,6 @@ pub const Pane = struct {
}
pane.body.cur_pinned = true;
}
-
- pub fn hasPdf(pane: *const Pane) bool {
- return if (comptime Pdf.enabled) pane.pdf != null else false;
- }
-
- pub fn hasPdfSelection(pane: *const Pane) bool {
- return if (comptime Pdf.enabled)
- if (pane.pdf) |pv| pv.selection != null and pv.selection_text.len > 0 else false
- else
- false;
- }
};
pub const Text = @import("Text.zig");
@@ -723,8 +689,6 @@ pub const Dir = @import("Dir.zig");
pub const mini = @import("mini.zig");
-pub const Pdf = @import("pdf_view.zig");
-
pub const terminal = @import("terminal.zig");
test {
@@ -735,7 +699,6 @@ test {
_ = Dir;
_ = mini;
_ = @import("Kind.zig");
- _ = Pdf;
_ = terminal;
}
@@ -776,7 +739,7 @@ pub fn retirePane(p: *Pardes, pane: *Pane) void {
// A query pane's places, in whatever panes it fed, go with it.
if (pane.query != null) panes.Query.release(p, pane);
if (pane.file) |*file| panes.File.leaveTwins(p, file);
- const watched = (if (pane.file) |f| f.output == null else false) or pane.hasPdf();
+ const watched = (if (pane.file) |f| f.output == null else false) or (if (pane.addon) |k| k.path.len > 0 else false);
for (p.panes, 0..) |slot, id| if (slot == pane) {
if (watched) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } });
if (pane.isTerminal()) p.emit(.{ .close_pty = .{ .pane = @intCast(id) } });
@@ -803,7 +766,10 @@ pub fn teardownPane(p: *Pardes, pane: *Pane) void {
if (pane.command) |line| p.gpa.free(line);
if (pane.shell) |bin| p.gpa.free(bin);
@import("Kind.zig").close(p, pane);
- if (comptime pdf_enabled) if (pane.pdf) |pv| panes.Pdf.deinitPane(p, pane, pv);
+ if (pane.pdf) |old| {
+ p.image_gpa.free(old.path);
+ p.image_gpa.destroy(old);
+ }
if (pane.file) |*file| panes.File.deinit(p, pane, file);
if (pane.ovl) |o| p.gpa.free(o.text);
views.tornDown(p, pane);
@@ -996,8 +962,6 @@ pub fn paneDir(pane: *const Pane) []const u8 {
.none => {},
}
if (pane.file) |f| return panes.Dir.ofName(f.path);
- if (comptime pdf_enabled) if (pane.pdf) |pv|
- return std.fs.path.dirname(pv.path) orelse "/";
if (pane.addon) |k| if (k.path.len > 0) return std.fs.path.dirname(k.path) orelse "/";
return pane.cwdSlice();
}