mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-06 07:38:21 +00:00
cli: add pager support for +show-config
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user