A pretty printer for zig
zig

use @typeName(T) for printing type names

altagos.dev 523ab221 85e3cdf9

verified
+2 -16
+2 -16
pretty.zig
··· 97 97 rctx: RuntimeContext, 98 98 ) error{WriteFailed}!void { 99 99 const info = @typeInfo(T); 100 - try printType(T, cctx, rctx, info); 100 + try printType(T, cctx, rctx); 101 101 102 102 return switch (info) { 103 103 .bool => formatBool(rctx, value), ··· 122 122 comptime T: type, 123 123 comptime cctx: ComptimeContext, 124 124 rctx: RuntimeContext, 125 - comptime info: std.builtin.Type, 126 125 ) error{WriteFailed}!void { 127 126 if (cctx.depth != 0 or cctx.options.always_show_type_names) { 128 127 rctx.setColor(.dim); 129 128 130 129 if (cctx.options.show_type_names) { 131 - switch (info) { 132 - .bool => try rctx.write("bool"), 133 - .comptime_int => try rctx.write("comptime_int"), 134 - .comptime_float => try rctx.write("comptime_float"), 135 - .int => |int| try rctx.print( 136 - "{s}{}", 137 - .{ if (int.signedness == .signed) "i" else "u", int.bits }, 138 - ), 139 - .float => |float| try rctx.print("f{}", .{float.bits}), 140 - .enum_literal => try rctx.write("enum literal"), 141 - .@"enum" => try rctx.write(@typeName(T)), 142 - else => try rctx.print("missing type {}", .{info}), 143 - } 130 + try rctx.write(@typeName(T)); 144 131 } 145 - 146 132 try rctx.write(cctx.options.type_value_seperator); 147 133 148 134 rctx.resetColor();