mdgen stylistic changes

This commit is contained in:
Mitchell Hashimoto
2024-01-21 14:53:34 -08:00
parent d569334fe9
commit daac7943f3
3 changed files with 17 additions and 18 deletions

View File

@ -1,19 +1,26 @@
const std = @import("std"); const std = @import("std");
const Config = @import("../../config/Config.zig");
const Action = @import("../../cli/action.zig").Action;
const help_strings = @import("help_strings"); const help_strings = @import("help_strings");
const build_options = @import("build_options"); const build_options = @import("build_options");
const Config = @import("../../config/Config.zig");
const Action = @import("../../cli/action.zig").Action;
pub fn substitute(alloc: std.mem.Allocator, input: []const u8, writer: anytype) !void { pub fn substitute(alloc: std.mem.Allocator, input: []const u8, writer: anytype) !void {
const version_string = try std.fmt.allocPrint(alloc, "{}", .{build_options.version}); const version_string = try std.fmt.allocPrint(alloc, "{}", .{build_options.version});
defer alloc.free(version_string);
const output = try alloc.alloc(u8, std.mem.replacementSize(u8, input, "@@VERSION@@", version_string)); const output = try alloc.alloc(u8, std.mem.replacementSize(
u8,
input,
"@@VERSION@@",
version_string,
));
defer alloc.free(output); defer alloc.free(output);
_ = std.mem.replace(u8, input, "@@VERSION@@", version_string, output); _ = std.mem.replace(u8, input, "@@VERSION@@", version_string, output);
try writer.writeAll(output); try writer.writeAll(output);
} }
pub fn generate_config(writer: anytype, cli: bool) !void { pub fn genConfig(writer: anytype, cli: bool) !void {
try writer.writeAll( try writer.writeAll(
\\ \\
\\# CONFIGURATION OPTIONS \\# CONFIGURATION OPTIONS
@ -21,10 +28,7 @@ pub fn generate_config(writer: anytype, cli: bool) !void {
\\ \\
); );
const info = @typeInfo(Config); inline for (@typeInfo(Config).Struct.fields) |field| {
std.debug.assert(info == .Struct);
inline for (info.Struct.fields) |field| {
if (field.name[0] == '_') continue; if (field.name[0] == '_') continue;
try writer.writeAll("`"); try writer.writeAll("`");
@ -45,7 +49,7 @@ pub fn generate_config(writer: anytype, cli: bool) !void {
} }
} }
pub fn generate_actions(writer: anytype) !void { pub fn genActions(writer: anytype) !void {
try writer.writeAll( try writer.writeAll(
\\ \\
\\# COMMAND LINE ACTIONS \\# COMMAND LINE ACTIONS
@ -53,12 +57,7 @@ pub fn generate_actions(writer: anytype) !void {
\\ \\
); );
const info = @typeInfo(Action); inline for (@typeInfo(Action).Enum.fields) |field| {
std.debug.assert(info == .Enum);
inline for (info.Enum.fields) |field| {
if (field.name[0] == '_') continue;
const action = std.meta.stringToEnum(Action, field.name).?; const action = std.meta.stringToEnum(Action, field.name).?;
switch (action) { switch (action) {

View File

@ -7,7 +7,7 @@ pub fn main() !void {
const writer = std.io.getStdOut().writer(); const writer = std.io.getStdOut().writer();
try gen.substitute(alloc, @embedFile("build/mdgen/ghostty_1_header.md"), writer); try gen.substitute(alloc, @embedFile("build/mdgen/ghostty_1_header.md"), writer);
try gen.generate_actions(writer); try gen.genActions(writer);
try gen.generate_config(writer, true); try gen.genConfig(writer, true);
try gen.substitute(alloc, @embedFile("build/mdgen/ghostty_1_footer.md"), writer); try gen.substitute(alloc, @embedFile("build/mdgen/ghostty_1_footer.md"), writer);
} }

View File

@ -7,6 +7,6 @@ pub fn main() !void {
const output = std.io.getStdOut().writer(); const output = std.io.getStdOut().writer();
try gen.substitute(alloc, @embedFile("build/mdgen/ghostty_5_header.md"), output); try gen.substitute(alloc, @embedFile("build/mdgen/ghostty_5_header.md"), output);
try gen.generate_config(output, false); try gen.genConfig(output, false);
try gen.substitute(alloc, @embedFile("build/mdgen/ghostty_5_footer.md"), output); try gen.substitute(alloc, @embedFile("build/mdgen/ghostty_5_footer.md"), output);
} }