cli: add pager support for +show-config

This commit is contained in:
Jon Parise
2026-03-30 10:47:21 -04:00
parent 62f8a1cbcf
commit 11d45cd43c

View File

@@ -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;
}