A pretty printer for zig
zig

allow overriding default options

altagos.dev c195ec1c 7011c7de

verified
+8 -1
+2
example/main.zig
··· 5 5 const pretty = pretty_mod.pretty; 6 6 const Pretty = pretty_mod.PrettyWithOptions; 7 7 8 + pub const pretty_options = pretty_mod.Options{ .always_show_type_names = true }; 9 + 8 10 const Hello = enum { world, developer }; 9 11 10 12 pub fn main(init: std.process.Init) !void {
+6 -1
pretty.zig
··· 1 1 const std = @import("std"); 2 2 const Io = std.Io; 3 + const Type = std.builtin.Type; 4 + 5 + const root = @import("root"); 3 6 4 7 pub const Options = struct { 5 8 indent_width: comptime_int = 2, ··· 11 14 type_value_sep: []const u8 = " = ", 12 15 }; 13 16 17 + const default_options: Options = if (@hasDecl(root, "pretty_options")) root.pretty_options else .{}; 18 + 14 19 pub fn pretty(value: anytype) Pretty(@TypeOf(value)) { 15 20 return Pretty(@TypeOf(value)).init(value); 16 21 } 17 22 18 23 pub fn Pretty(comptime T: type) type { 19 - return PrettyWithOptions(T, .{}); 24 + return PrettyWithOptions(T, default_options); 20 25 } 21 26 22 27 pub fn PrettyWithOptions(comptime T: type, comptime options: Options) type {