diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-04-04 19:22:04 +0300 |
|---|---|---|
| committer | Can Celik <ogulcancelik@gmail.com> | 2026-04-05 01:23:06 +0300 |
| commit | 41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch) | |
| tree | 3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/cli/show_config.zig | |
| parent | 55c138263e190a1e79d4b997bfb9397306c0ec1f (diff) | |
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/cli/show_config.zig')
| -rw-r--r-- | vendor/libghostty-vt/src/cli/show_config.zig | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/cli/show_config.zig b/vendor/libghostty-vt/src/cli/show_config.zig new file mode 100644 index 00000000..cd0ba89a --- /dev/null +++ b/vendor/libghostty-vt/src/cli/show_config.zig @@ -0,0 +1,92 @@ +const std = @import("std"); +const args = @import("args.zig"); +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. + default: bool = false, + + /// Only show the options that have been changed from the default. + /// This has no effect if `--default` is specified. + @"changes-only": bool = true, + + /// If true print the documentation above each option as a comment, + /// if available. + docs: bool = false, + + /// Disable automatic paging of output. + @"no-pager": bool = false, + + pub fn deinit(self: Options) void { + _ = self; + } + + /// Enables `-h` and `--help` to work. + pub fn help(self: Options) !void { + _ = self; + return Action.help_error; + } +}; + +/// The `show-config` command shows the current configuration in a valid Ghostty +/// configuration file format. +/// +/// When executed without any arguments this will output the current +/// configuration that is different from the default configuration. If you're +/// using the default configuration this will output nothing. +/// +/// If you are a new user and want to see all available options with +/// documentation, run `ghostty +show-config --default --docs`. +/// +/// The output is not in any specific order, but the order should be consistent +/// between runs. The output is not guaranteed to be exactly match the input +/// configuration files, but it will result in the same behavior. Comments, +/// whitespace, and other formatting is not preserved from user configuration +/// files. +/// +/// Flags: +/// +/// * `--default`: Show the default configuration instead of loading +/// the user configuration. +/// +/// * `--changes-only`: Only show the options that have been changed +/// from the default. This has no effect if `--default` is specified. +/// +/// * `--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(); + + { + var iter = try args.argsIterator(alloc); + defer iter.deinit(); + try args.parse(Options, alloc, &opts, &iter); + } + + var config = if (opts.default) try Config.default(alloc) else try Config.load(alloc); + defer config.deinit(); + + const configfmt: configpkg.FileFormatter = .{ + .alloc = alloc, + .config = &config, + .changed = !opts.default and opts.@"changes-only", + .docs = opts.docs, + }; + + var pager: Pager = if (!opts.@"no-pager") .init(alloc) else .{}; + defer pager.deinit(); + var buffer: [4096]u8 = undefined; + const writer = pager.writer(&buffer); + + try configfmt.format(writer); + try writer.flush(); + return 0; +} |
