A pretty printer for zig
zig
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

allow custom pretty fn

Altagos eebc4326 a025f81f

+17 -2
+11
example/main.zig
··· 23 23 const Person = struct { 24 24 age: u8, 25 25 gender: ?Gender, 26 + 27 + pub fn pretty(self: *const @This(), comptime ctx: pretty_mod.Context, run: *const pretty_mod.Runtime) !void { 28 + run.setColor(ctx, .dim); 29 + try run.write("AGE = "); 30 + run.resetColor(); 31 + try run.print("{d}", .{self.age}); 32 + run.setColor(ctx, .dim); 33 + try run.write(", GENDER = "); 34 + run.resetColor(); 35 + try run.print("{?}", .{self.gender}); 36 + } 26 37 }; 27 38 28 39 const Nested = struct {
+6 -2
pretty.zig
··· 147 147 }; 148 148 } 149 149 150 - const Runtime = struct { 150 + pub const Runtime = struct { 151 151 out: *Io.Writer, 152 152 tty: Io.Terminal, 153 153 ··· 185 185 } 186 186 }; 187 187 188 - const Context = struct { 188 + pub const Context = struct { 189 189 depth: comptime_int = 0, 190 190 191 191 options: Options, ··· 212 212 213 213 if (!opts.skip_type_name) 214 214 try printType(T, ctx, run, value); 215 + 216 + if (std.meta.hasMethod(T, "pretty")) { 217 + return value.pretty(ctx, run); 218 + } 215 219 216 220 return switch (info) { 217 221 .bool => formatBool(ctx, run, value),