From 3ebdbe26a14546f8e4ee06462850aad85f1c9646 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 5 Nov 2026 22:59:25 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/CHANGELOG.md | 5 +++++ src/Core.zig | 2 +- src/TerminalImages.zig | 2 +- src/config.zig | 25 +++---------------------- src/host_io.zig | 46 ++++++++++++++++++++++------------------------ src/main.zig | 2 +- src/ninep/ctl.zig | 11 +++++------ src/pager.zig | 22 +++++++--------------- src/panes.zig | 1 - src/terminal.zig | 17 ++--------------- 10 files changed, 47 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md index 88482e92..3869aa07 100644 --- a/src/CHANGELOG.md +++ b/src/CHANGELOG.md @@ -11,6 +11,11 @@ - FocusTint: the focused pane's and column's tags are tinted. - SyntaxBold: keywords are not bold. - Ligatures: the window draws a font's ligatures. + - Pager: a terminal's shell pages into a +Pager (`pardes -`) where your + environment names no pager; set `PAGER` and `GIT_PAGER` to keep yours. + - PagerColor: a +Pager keeps its program's colours. + - TermImages: a new terminal draws its program's images as pixels where + the shell can; Petscii still flips one terminal to glyph art. - What pardes keeps on disk is in xitdb databases now (a pinned commit of github.com/xit-vcs/xitdb, pure Zig). The state file, `pardes.xitdb` in diff --git a/src/Core.zig b/src/Core.zig index a455cf1c..0f90f4cb 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -545,7 +545,7 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { p.oneColumn(); }, .stdin => { - const page = try pager.parse(gpa, opts.stdin_text.?, p.settings.pager_color); + const page = try pager.parse(gpa, opts.stdin_text.?); errdefer gpa.free(page.spans); const content = page.text; errdefer gpa.free(content); diff --git a/src/TerminalImages.zig b/src/TerminalImages.zig index 86c20d2c..9c44ec40 100644 --- a/src/TerminalImages.zig +++ b/src/TerminalImages.zig @@ -21,7 +21,7 @@ const PixelRect = image.PixelRect; pub const storage_limit = 64 * 1024 * 1024; /// This pane asks for its images as glyph art even where pixels could be -/// drawn (the Petscii builtin; TermImages sets it for a new pane). +/// drawn (the Petscii builtin). petscii: bool = false, /// Pixels in RGBA for images ghostty-vt holds in another format (RGB, /// grey): only for images on screen, dropped the frame they are not. diff --git a/src/config.zig b/src/config.zig index edfaf3ed..3d5de631 100644 --- a/src/config.zig +++ b/src/config.zig @@ -117,9 +117,6 @@ pub const leader_path = paths: { .Search = null, .Panes = null, .More = null, - .Pager = null, - .PagerColor = null, - .TermImages = null, .JumpScope = null, .Debug = "td", .Msg = null, @@ -740,17 +737,6 @@ pub const Runtime = struct { tagline_percent: u8 = 100, } = .{}, - /// What a terminal's shell pages through (host_io.ChildEnv): `pardes`, - /// PAGER and GIT_PAGER set to `pardes -`, a +Pager pane, where the - /// user's environment set neither; `off`, the environment as it is. - pager: Pager = .pardes, - /// A +Pager keeps its program's colours (SGR, as spans over the text, - /// pager.zig), or is plain; for the next text paged. - pager_color: bool = true, - /// How a new terminal pane draws the kitty graphics its program sends - /// (yazi's previews): `real`, as pixels where the shell can, or - /// `petscii`, as glyph art. The Petscii builtin flips one pane. - term_images: TermImages = .real, /// What Back and Forward keep to (Jump.jumpBy): `file`, the places in /// the focused pane's file first, other files only once those run out /// that way; `all`, every place in the order it was jumped to. @@ -769,13 +755,11 @@ pub const Runtime = struct { /// +Preview with): it never resizes itself after. search_rows: u16 = 8, - pub const Pager = enum { pardes, off }; - pub const TermImages = enum { real, petscii }; pub const JumpScope = enum { file, all }; pub const SearchPlace = enum { attached, column }; pub const SearchPane = enum { reuse, new }; /// A setting that is one of a few words, each an enum field of Runtime. - pub const Choice = enum { pager, term_images, jump_scope, search_place, search_pane, pet }; + pub const Choice = enum { jump_scope, search_place, search_pane, pet }; pub const Pet = enum { off, cat, frog }; pub const tagline_percent_min: u8 = 1; @@ -845,7 +829,7 @@ pub const Runtime = struct { pub const Capability = std.meta.FieldEnum(Capabilities); - pub const Toggle = enum { wrap, debug, pager_color, verbose, cursor_blink, jump_trail, program_esc }; + pub const Toggle = enum { wrap, debug, verbose, cursor_blink, jump_trail, program_esc }; pub const Action = union(enum) { toggle: Toggle, @@ -917,9 +901,6 @@ pub const Runtime = struct { .{ .word = "TaglineSize", .action = .tagline_size, .doc = "Scale the tag font, a percentage." }, .{ .word = "WindowOpacity", .action = .window_opacity, .doc = "The window's opacity, a percentage." }, .{ .word = "WindowBlur", .action = .window_blur, .doc = "The blur behind a translucent window, a radius." }, - .{ .word = "Pager", .action = .{ .choice = .pager }, .doc = "What a terminal's commands page through: pardes, a +Pager pane (pardes -), or off, the environment's own; for terminals started after it." }, - .{ .word = "PagerColor", .action = .{ .toggle = .pager_color }, .doc = "A +Pager keeps its program's colours, on or off; for the next text paged." }, - .{ .word = "TermImages", .action = .{ .choice = .term_images }, .doc = "How a new terminal draws its program's kitty graphics: real, as pixels where it can, or petscii, as glyph art." }, .{ .word = "JumpScope", .action = .{ .choice = .jump_scope }, .doc = "What Back and Forward keep to: file, the focused pane's file until it runs out that way, or all, every place in order." }, .{ .word = "CallstackDepth", .action = .callstack_depth, .doc = "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit." }, .{ .word = "Tab", .action = .tab, .doc = "A tab's width in cells, 1 through 16, in every pane; bare, it says the width." }, @@ -1332,7 +1313,7 @@ pub const Runtime = struct { }; const values = [_][2][]const u8{ .{ "TaglineSize", "73" }, .{ "WindowOpacity", "85" }, .{ "WindowBlur", "40" }, - .{ "MessageLinger", "1500" }, .{ "DumpDir", "~/dumps" }, .{ "TermImages", "petscii" }, + .{ "MessageLinger", "1500" }, .{ "DumpDir", "~/dumps" }, .{ "JumpScope", "all" }, .{ "SearchPlace", "column" }, .{ "SearchPane", "new" }, .{ "GripWidth", "200" }, .{ "InactiveDim", "35" }, .{ "CallstackDepth", "16" }, .{ "Tab", "8" }, .{ "SearchRows", "12" }, diff --git a/src/host_io.zig b/src/host_io.zig index b7e58506..86df754b 100644 --- a/src/host_io.zig +++ b/src/host_io.zig @@ -1841,8 +1841,8 @@ pub const ChildEnv = struct { /// Which pager a child is given where the user's environment names none: /// a command pane's one-shot shell `cat` (its output is a pane already), - /// a terminal's shell `pardes -` (a +Pager pane) unless `Pager off`. - pub const Paging = enum { command, terminal, terminal_off }; + /// a terminal's shell `pardes -` (a +Pager pane). + pub const Paging = enum { command, terminal }; pub fn build(slots: *Slots, paging: Paging) ?[*:null]const ?[*:0]const u8 { var n: usize = 0; @@ -1865,7 +1865,6 @@ pub const ChildEnv = struct { const defaults: []const [*:0]const u8 = switch (paging) { .command => &cat_pagers, .terminal => pardesPagers(), - .terminal_off => &.{}, }; for (defaults) |default| { const set = for (libc.environ[0..i]) |entry| { @@ -1962,28 +1961,26 @@ test "the child environment replaces the launcher's terminal identity exactly on var slots: ChildEnv.Slots = undefined; // Where the user named no pager: a terminal's shell pages into a - // +Pager pane (`pardes -`), or, Pager off, as the environment says; a - // command pane's through cat. A pager the user named is kept. - for ([_]ChildEnv.Paging{ .terminal, .terminal_off }) |paging| { - var shell_slots: ChildEnv.Slots = undefined; - const shell_envp = ChildEnv.build(&shell_slots, paging) orelse return error.EnvironmentTooLarge; - var said: usize = 0; - var systemd: usize = 0; - var j: usize = 0; - while (shell_envp[j]) |entry| : (j += 1) { - const line = std.mem.span(entry); - if (std.c.getenv("SYSTEMD_PAGER") == null and std.mem.startsWith(u8, line, "SYSTEMD_PAGER=")) systemd += 1; - if (std.c.getenv("SYSTEMD_PAGERSECURE") == null and std.mem.eql(u8, line, "SYSTEMD_PAGERSECURE=0")) systemd += 1; - if (std.mem.startsWith(u8, line, "PAGER=") and std.c.getenv("PAGER") == null) { - try std.testing.expect(paging == .terminal and std.mem.endsWith(u8, line, " -")); - said += 1; - } + // +Pager pane (`pardes -`); a command pane's through cat. A pager the + // user named is kept. + var shell_slots: ChildEnv.Slots = undefined; + const shell_envp = ChildEnv.build(&shell_slots, .terminal) orelse return error.EnvironmentTooLarge; + var said: usize = 0; + var systemd: usize = 0; + var j: usize = 0; + while (shell_envp[j]) |entry| : (j += 1) { + const line = std.mem.span(entry); + if (std.c.getenv("SYSTEMD_PAGER") == null and std.mem.startsWith(u8, line, "SYSTEMD_PAGER=")) systemd += 1; + if (std.c.getenv("SYSTEMD_PAGERSECURE") == null and std.mem.eql(u8, line, "SYSTEMD_PAGERSECURE=0")) systemd += 1; + if (std.mem.startsWith(u8, line, "PAGER=") and std.c.getenv("PAGER") == null) { + try std.testing.expect(std.mem.endsWith(u8, line, " -")); + said += 1; } - if (std.c.getenv("PAGER") == null) try std.testing.expectEqual(@as(usize, if (paging == .terminal) 1 else 0), said); - // systemd's pager and its secure mode off, with ours only. - if (std.c.getenv("SYSTEMD_PAGER") == null and std.c.getenv("SYSTEMD_PAGERSECURE") == null) - try std.testing.expectEqual(@as(usize, if (paging == .terminal) 2 else 0), systemd); } + if (std.c.getenv("PAGER") == null) try std.testing.expectEqual(@as(usize, 1), said); + // systemd's pager and its secure mode off, with ours only. + if (std.c.getenv("SYSTEMD_PAGER") == null and std.c.getenv("SYSTEMD_PAGERSECURE") == null) + try std.testing.expectEqual(@as(usize, 2), systemd); const envp = ChildEnv.build(&slots, .command) orelse return error.EnvironmentTooLarge; var terms: usize = 0; var colorterms: usize = 0; @@ -2126,7 +2123,8 @@ pub fn forkShell( const pages = if (core) |c| if (c.panes[pane]) |pn| pn.command_pages else false else false; const paging: ChildEnv.Paging = if (one_line != null and !pages) .command - else if (core) |c| (if (c.settings.pager == .off) .terminal_off else .terminal) else .terminal; + else + .terminal; const envp = ChildEnv.build(&env_slots, paging); const ws = ptyWinsize(core, cols, rows); // The child says here why it could not become the shell (its chdir or diff --git a/src/main.zig b/src/main.zig index afa72881..be66e8e2 100644 --- a/src/main.zig +++ b/src/main.zig @@ -61,7 +61,7 @@ const help_text = \\With no arguments the shell pane starts in tty mode. A FILE argument \\(optionally file:LINE) opens it alone, filling the window; a DIRECTORY \\argument becomes the cwd shells spawn in. `-` reads stdin into a +Pager - \\pane, its colours kept (PagerColor) and every other escape dropped: + \\pane, its colours kept and every other escape dropped: \\inside a pardes pane the outer session's, returning at once (a \\terminal's PAGER), else a new editor's. \\ diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig index f8cda59a..3784cf41 100644 --- a/src/ninep/ctl.zig +++ b/src/ninep/ctl.zig @@ -690,7 +690,7 @@ pub fn writePager(p: *Pardes, req: Req) Reply { /// The text a /pager open wrote after its directory (`held`), a program's /// output for a terminal, put in the +Pager `serial` as `pardes -` once /// wrote it to the body: through ghostty-vt (pager.zig), its colours kept -/// as the pane's spans unless PagerColor is off, one undo step, and left +/// as the pane's spans, one undo step, and left /// clean. Reads of the pane are its plain text. The held bytes go either way. pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfMemory}!void { if (held.items.len == 0) return; @@ -698,7 +698,7 @@ pub fn fillPager(p: *Pardes, serial: u32, held: *std.ArrayList(u8)) error{OutOfM const id = p.paneBySerial(serial) orelse return; const pane = p.panes[id].?; const f = if (pane.file) |*file| file else return; - const page = try pardes.pager.parse(p.gpa, held.items, p.settings.pager_color); + const page = try pardes.pager.parse(p.gpa, held.items); held.clearAndFree(p.gpa); if (page.text.len == 0 and f.content.len == 0) return page.deinit(p.gpa); if (!pane.fs.nomark) panes.File.pushUndo(p, pane); @@ -2715,9 +2715,8 @@ test "what a /pager open writes after its directory is the text: plain in the bo try testing.expectEqualStrings("red /a\nNext\n", f.content); try testing.expectEqual(@as(usize, 0), f.pager_spans.len); - // PagerColor off, and an open closed with no read: the same text, plain, - // in at the editor's next step (a close through a mount never waits). - p.settings.pager_color = false; + // An open closed with no read: the text in at the editor's next step + // (a close through a mount never waits), its colours kept. const kept = try testing.allocator.dupe(u8, f.content); defer testing.allocator.free(kept); const shut = call(p, .{ .tag = 7, .op = .open, .node = pager, .omode = 1 }).reply.handle; @@ -2734,7 +2733,7 @@ test "what a /pager open writes after its directory is the text: plain in the bo try testing.expectEqualStrings("", next.content); fillClosedPagers(p); try testing.expectEqualStrings("green\n", next.content); - try testing.expectEqual(@as(usize, 0), next.pager_spans.len); + try testing.expectEqual(@as(usize, 1), next.pager_spans.len); try testing.expectEqual(next.revision, next.saved_revision); } 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 } } }}); } diff --git a/src/panes.zig b/src/panes.zig index c0783ac7..2e1e9262 100644 --- a/src/panes.zig +++ b/src/panes.zig @@ -845,7 +845,6 @@ pub fn installPane(p: *Pardes, id: usize, pane: *Pane) void { p.rects[id] = .{}; p.panes[id] = pane; views.installed(p, pane); - panes.terminal.adoptSettings(p, pane); // /log hears of it once the update that made it ends, when it has // its file, name and place (`ctlfs.events.announce`). pane.fs.unannounced = true; diff --git a/src/terminal.zig b/src/terminal.zig index 4cde89a4..c9c60b5b 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -3088,13 +3088,6 @@ pub fn petscii(pane: *const Pane) ?bool { return state.images.petscii; } -/// A new terminal takes TermImages: pixels, or glyph art. -pub fn adoptSettings(p: *const Pardes, pane: *Pane) void { - if (comptime !images_enabled) return; - const state = pane.terminal orelse return; - state.images.petscii = p.settings.term_images == .petscii; -} - /// Whether the screen showing holds any kitty graphics image. pub fn hasImages(pane: *const Pane) bool { if (comptime !images_enabled) return false; @@ -3399,23 +3392,17 @@ test "a terminal's image is a placement whatever the frontend draws, and the Pet try std.testing.expect(!imagePlaces(s)[0].art.glyph); } -test "TermImages is real by default, and petscii makes new terminals draw glyph art" { +test "a new terminal draws its program's images as pixels, and one without images says nothing of them" { if (comptime !images_enabled) return error.SkipZigTest; const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .shells = 1 }); defer p.deinit(); - try std.testing.expectEqual(config.Runtime.TermImages.real, p.settings.term_images); try std.testing.expectEqual(false, petscii(p.panes[0].?).?); // A pane without images says nothing of them. try std.testing.expect(std.mem.indexOf(u8, try tagline.tagPrefix(p, p.panes[0].?), "petscii") == null); - try std.testing.expect(p.executeBuiltinLine(0, "TermImages petscii")); - try std.testing.expectEqual(config.Runtime.TermImages.petscii, p.settings.term_images); - // The setting is for new panes: the one there keeps its choice. - try std.testing.expectEqual(false, petscii(p.panes[0].?).?); const id = p.freeSlot().?; const fresh = try p.newShell(id, ""); - try std.testing.expectEqual(true, petscii(fresh).?); - try std.testing.expect(std.mem.indexOf(u8, try tagline.tagPrefix(p, fresh), " petscii:on") != null); + try std.testing.expectEqual(false, petscii(fresh).?); } test "a program asking the cell size in pixels (CSI 16 t) is told the shell's" { -- cgit v1.3