summaryrefslogtreecommitdiff
path: root/src/pager.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 22:59:25 -0300
committerGabriel Schneider <[email protected]>2026-11-05 23:58:31 -0300
commit3ebdbe26a14546f8e4ee06462850aad85f1c9646 (patch)
tree10b81fa631e70d5ec0659ea05bb770587cf99405 /src/pager.zig
parentdfcc040ac979b695dc2e68b9d866c2769ba6d928 (diff)
downloadpardes-3ebdbe26a14546f8e4ee06462850aad85f1c9646.tar.gz
pardes-3ebdbe26a14546f8e4ee06462850aad85f1c9646.zip
settings #3, the terminal's three go, each the value it had by default: Pager (a terminal's shell pages into a +Pager where the environment names no pager, so PAGER and GIT_PAGER set by the user are what an opt-out is; host_io's Paging.terminal_off goes), PagerColor (a +Pager keeps its program's colours; pager.parse loses its colour argument, its callers in Core.zig and ninep/ctl.zig with it) and TermImages (a new terminal draws its images as pixels where it can, Petscii still flips one; terminal.adoptSettings and its call in panes.zig go); deleted tests: "settings: Pager is pardes by default, off taken, anything else refused with its choices" and "PagerColor off: the same text, no spans, overstrike included" (the man page's overstrike case pins what stays); rewritten: TermImages' test as a new terminal drawing pixels, ctl's pager test with the second +Pager keeping its colours, host_io's environment test for the one terminal paging, process/tree's /commands row on Wrap; the reference, setup and changelog say an environment's PAGER is the way out; no golden changes; gates on tui: core-test 964/964, behaviour-test 241/241, unit-test 1480/1481, pane-test 171/172, snap all 105 scripts ok, process-test 0 of 37 failed; gui unit-test 1524/1525
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/pager.zig')
-rw-r--r--src/pager.zig22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/pager.zig b/src/pager.zig
index 9102fb84..e4ccbab4 100644
--- a/src/pager.zig
+++ b/src/pager.zig
@@ -28,10 +28,10 @@ pub const Page = struct {
}
};
-/// `raw`, a program's output for a terminal, as text and, `colour` on
-/// (PagerColor), its spans. Both are `gpa`'s.
-pub fn parse(gpa: std.mem.Allocator, raw: []const u8, colour: bool) !Page {
- var h: Handler = .{ .gpa = gpa, .colour = colour };
+/// `raw`, a program's output for a terminal, as text and its spans. Both
+/// are `gpa`'s.
+pub fn parse(gpa: std.mem.Allocator, raw: []const u8) !Page {
+ var h: Handler = .{ .gpa = gpa };
errdefer h.text.deinit(gpa);
errdefer h.spans.deinit(gpa);
try h.text.ensureTotalCapacity(gpa, raw.len);
@@ -46,7 +46,6 @@ pub fn parse(gpa: std.mem.Allocator, raw: []const u8, colour: bool) !Page {
const Handler = struct {
gpa: std.mem.Allocator,
- colour: bool,
text: std.ArrayList(u8) = .empty,
spans: std.ArrayList(Span) = .empty,
/// What SGR has set so far.
@@ -74,7 +73,7 @@ const Handler = struct {
const cp = std.unicode.utf8Decode(h.text.items[h.last..]) catch return;
for (0..@min(value, 1024)) |_| h.print(cp);
},
- .set_attribute => if (h.colour) h.attribute(value),
+ .set_attribute => h.attribute(value),
.linefeed => {
h.append("\n");
h.line_start = h.text.items.len;
@@ -178,7 +177,7 @@ const Handler = struct {
/// `from` to the text's end drawn in `style`: the span before it goes
/// on when it ends there in the same style.
fn span(h: *Handler, from: usize, style: CellStyle) void {
- if (!h.colour or std.meta.eql(style, CellStyle{})) return;
+ if (std.meta.eql(style, CellStyle{})) return;
const end: u32 = @intCast(h.text.items.len);
if (h.spans.items.len > 0) {
const tail = &h.spans.items[h.spans.items.len - 1];
@@ -249,7 +248,7 @@ const testing = std.testing;
/// The text `raw` pages to, and its spans as `text[start..end]=style` lines.
fn expectPage(raw: []const u8, text: []const u8, spans: []const struct { []const u8, CellStyle }) !void {
- const page = try parse(testing.allocator, raw, true);
+ const page = try parse(testing.allocator, raw);
defer page.deinit(testing.allocator);
try testing.expectEqualStrings(text, page.text);
for (spans, 0..) |want, i| {
@@ -350,13 +349,6 @@ test "bytes that are not UTF-8 page as U+FFFD, the text around them kept" {
try expectPage("caf\xe9 \xff\xfe ok\n", "caf\u{fffd} \u{fffd}\u{fffd} ok\n", &.{});
}
-test "PagerColor off: the same text, no spans, overstrike included" {
- const page = try parse(testing.allocator, "\x1b[31mred\x1b[m N\x08N\n", false);
- defer page.deinit(testing.allocator);
- try testing.expectEqualStrings("red N\n", page.text);
- try testing.expectEqual(@as(usize, 0), page.spans.len);
-}
-
test "a carriage return's rewrite takes the spans of what it rewrote with it" {
try expectPage("\x1b[31m10%\r\x1b[32m100%\x1b[m\n", "100%\n", &.{.{ "100%", .{ .fg = .{ .index = 2 } } }});
}