From 11d45cd43c14cc8a2028d85428349066402054fa Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Mon, 30 Mar 2026 10:47:21 -0400 Subject: [PATCH] cli: add pager support for +show-config --- src/cli/show_config.zig | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/cli/show_config.zig b/src/cli/show_config.zig index 1b73b77c1..cd0ba89a7 100644 --- a/src/cli/show_config.zig +++ b/src/cli/show_config.zig @@ -4,6 +4,7 @@ const Allocator = std.mem.Allocator; const Action = @import("ghostty.zig").Action; const configpkg = @import("../config.zig"); const Config = configpkg.Config; +const Pager = @import("Pager.zig"); pub const Options = struct { /// If true, do not load the user configuration, only load the defaults. @@ -17,6 +18,9 @@ pub const Options = struct { /// if available. docs: bool = false, + /// Disable automatic paging of output. + @"no-pager": bool = false, + pub fn deinit(self: Options) void { _ = self; } @@ -55,6 +59,8 @@ pub const Options = struct { /// * `--docs`: Print the documentation above each option as a comment, /// This is very noisy but is very useful to learn about available /// options, especially paired with `--default`. +/// +/// * `--no-pager`: Disable automatic paging of output. pub fn run(alloc: Allocator) !u8 { var opts: Options = .{}; defer opts.deinit(); @@ -75,12 +81,12 @@ pub fn run(alloc: Allocator) !u8 { .docs = opts.docs, }; - // For some reason `std.fmt.format` isn't working here but it works in - // tests so we just do configfmt.format. - var stdout: std.fs.File = .stdout(); + var pager: Pager = if (!opts.@"no-pager") .init(alloc) else .{}; + defer pager.deinit(); var buffer: [4096]u8 = undefined; - var stdout_writer = stdout.writer(&buffer); - try configfmt.format(&stdout_writer.interface); - try stdout_writer.end(); + const writer = pager.writer(&buffer); + + try configfmt.format(writer); + try writer.flush(); return 0; }