From edad6d960dc0fc1165cbb3b801e0538045b2247f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 1 Oct 2026 10:09:54 -0300 Subject: A +Pager keeps its program's colours: the session parses what /pager is written after its directory with ghostty-vt, SGR becomes spans drawn over the plain text, every other escape is dropped, and PagerColor off pages it plain --- src/pardes.zig | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/pardes.zig') diff --git a/src/pardes.zig b/src/pardes.zig index c6850451..5d9f8606 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -11,6 +11,7 @@ pub const ctlfs = @import("ninep/tree.zig"); pub const syntax = @import("syntax.zig"); const tracy = @import("tracy.zig"); pub const panes = @import("panes.zig"); +pub const pager = @import("pager.zig"); const locations = @import("locations.zig"); pub const tagline = @import("tagline.zig"); pub const exec = @import("exec.zig"); @@ -496,6 +497,7 @@ test { _ = @import("recent.zig"); _ = @import("Presentation.zig"); _ = @import("animation.zig"); + _ = @import("pager.zig"); } pub const Builtin = builtins.registry.Builtin(); @@ -4221,7 +4223,8 @@ pub const Options = struct { file: ?[]const u8 = null, file_line: usize = 0, missing: ?struct { word: []const u8, dir: []const u8 } = null, - /// `pardes -`: stdin, its escapes stripped, for a +Pager pane at boot. + /// `pardes -`: stdin as it came, for a +Pager pane at boot (pager.zig + /// parses it). stdin_text: ?[]const u8 = null, tty_toggle: u21 = config.tty_toggle_default, /// load a dump of another instance instead of spawning shells (acme -l) @@ -4638,7 +4641,9 @@ pub const Pardes = struct { p.oneColumn(); }, .stdin => { - const content = try gpa.dupe(u8, opts.stdin_text.?); + const page = try pager.parse(gpa, opts.stdin_text.?, p.settings.pager_color); + errdefer gpa.free(page.spans); + const content = page.text; errdefer gpa.free(content); const dir = p.sessionDir(); const shown = try panes.Output.open(p, 0, dir, .{ .cmd = .New }, "", content); @@ -4647,6 +4652,7 @@ pub const Pardes = struct { gpa.free(shown.file.?.path); shown.file.?.path = named; shown.file.?.pager_diff = panes.File.looksLikeDiff(content[0..@min(content.len, 64 * 1024)]); + shown.file.?.pager_spans = page.spans; p.oneColumn(); }, .embedded => { @@ -5748,6 +5754,8 @@ pub const Pardes = struct { if (v.now) |clock| p.advance(clock(h.ctx)); // What a 9P open wrote in a row goes in once the writes pause. ctlfs.pane.flushPausedBatch(p); + // ...and what a /pager open was written before its close. + ctlfs.ctl.fillClosedPagers(p); while (p.nextQueued()) |ev| p.update(ev); while (p.nextEffect()) |e| p.perform(e); turn.settle(); -- cgit v1.3