A pretty printer for zig
zig

resolve theme colors at comptime

altagos.dev b657057a 967a7ac2

verified
+12 -4
+12 -4
pretty.zig
··· 38 38 color_true: Io.Terminal.Color = .bright_green, 39 39 color_false: Io.Terminal.Color = .bright_red, 40 40 41 - pub fn getColor(this: Theme, color: Colors) Io.Terminal.Color { 41 + pub inline fn getColor(comptime this: Theme, comptime color: Colors) Io.Terminal.Color { 42 42 return switch (color) { 43 43 inline else => |col| @field(this, "color_" ++ @tagName(col)), 44 44 }; ··· 96 96 97 97 indent_level: usize = 0, 98 98 99 - pub inline fn print(this: *const RuntimeContext, comptime fmt: []const u8, args: anytype) error{WriteFailed}!void { 99 + pub inline fn print( 100 + this: *const RuntimeContext, 101 + comptime fmt: []const u8, 102 + args: anytype, 103 + ) error{WriteFailed}!void { 100 104 return this.out.print(fmt, args); 101 105 } 102 106 ··· 107 111 pub inline fn setColor( 108 112 this: *const RuntimeContext, 109 113 comptime ctx: ComptimeContext, 110 - color: Theme.Colors, 114 + comptime color: Theme.Colors, 111 115 ) void { 112 116 this.tty.setColor(ctx.options.theme.getColor(color)) catch {}; 113 117 } ··· 205 209 rctx: *const RuntimeContext, 206 210 value: bool, 207 211 ) !void { 208 - rctx.setColor(cctx, if (value) .true else .false); 212 + if (value) 213 + rctx.setColor(cctx, .true) 214 + else 215 + rctx.setColor(cctx, .false); 216 + 209 217 try rctx.print("{}", .{value}); 210 218 rctx.resetColor(); 211 219 }