mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
config: formatter can output docs
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
const formatter = @This();
|
const formatter = @This();
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
const help_strings = @import("help_strings");
|
||||||
const Config = @import("Config.zig");
|
const Config = @import("Config.zig");
|
||||||
const Key = @import("key.zig").Key;
|
const Key = @import("key.zig").Key;
|
||||||
|
|
||||||
@ -133,6 +134,9 @@ pub const FileFormatter = struct {
|
|||||||
alloc: Allocator,
|
alloc: Allocator,
|
||||||
config: *const Config,
|
config: *const Config,
|
||||||
|
|
||||||
|
/// Include comments for documentation of each key
|
||||||
|
docs: bool = false,
|
||||||
|
|
||||||
/// Only include changed values from the default.
|
/// Only include changed values from the default.
|
||||||
changed: bool = false,
|
changed: bool = false,
|
||||||
|
|
||||||
@ -164,12 +168,23 @@ pub const FileFormatter = struct {
|
|||||||
} else true;
|
} else true;
|
||||||
|
|
||||||
if (do_format) {
|
if (do_format) {
|
||||||
|
const do_docs = self.docs and @hasDecl(help_strings.Config, field.name);
|
||||||
|
if (do_docs) {
|
||||||
|
const help = @field(help_strings.Config, field.name);
|
||||||
|
var lines = std.mem.splitScalar(u8, help, '\n');
|
||||||
|
while (lines.next()) |line| {
|
||||||
|
try writer.print("# {s}\n", .{line});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try formatEntry(
|
try formatEntry(
|
||||||
field.type,
|
field.type,
|
||||||
field.name,
|
field.name,
|
||||||
value,
|
value,
|
||||||
writer,
|
writer,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (do_docs) try writer.print("\n", .{});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,7 +200,10 @@ test "format default config" {
|
|||||||
defer buf.deinit();
|
defer buf.deinit();
|
||||||
|
|
||||||
// We just make sure this works without errors. We aren't asserting output.
|
// We just make sure this works without errors. We aren't asserting output.
|
||||||
const fmt: FileFormatter = .{ .alloc = alloc, .config = &cfg };
|
const fmt: FileFormatter = .{
|
||||||
|
.alloc = alloc,
|
||||||
|
.config = &cfg,
|
||||||
|
};
|
||||||
try std.fmt.format(buf.writer(), "{}", .{fmt});
|
try std.fmt.format(buf.writer(), "{}", .{fmt});
|
||||||
|
|
||||||
//std.log.warn("{s}", .{buf.items});
|
//std.log.warn("{s}", .{buf.items});
|
||||||
|
Reference in New Issue
Block a user