A pretty printer for zig
zig
0
fork

Configure Feed

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

pretty functions

Altagos 0ad06c6f 788a716a

+22 -3
+4
example/main.zig
··· 107 107 print("Error set - {f}\n", .{pretty(ErrorSet.OutOfMemory)}); 108 108 print("Error union error - {f}\n", .{pretty(eu_error)}); 109 109 print("Error union ok - {f}\n", .{pretty(eu_ok)}); 110 + 111 + print("\nFunctions\n", .{}); 112 + print("Function Pretty - {f}\n", .{pretty(Pretty)}); 113 + print("Function main - {f}\n", .{pretty(main)}); 110 114 }
+18 -3
pretty.zig
··· 152 152 ) error{WriteFailed}!void { 153 153 const info = @typeInfo(T); 154 154 155 - if (!opts.skip_type_name) try printType(T, ctx, run); 155 + if (!opts.skip_type_name) 156 + try printType(T, ctx, run); 156 157 157 158 return switch (info) { 158 159 .bool => formatBool(ctx, run, value), ··· 180 181 // TODO: .pointer => |ptr| {}, 181 182 // TODO: .vector => |vec| {}, 182 183 183 - // TODO: .@"fn" => |f| {}, 184 + .@"fn" => formatFn(T, ctx, run), 184 185 185 186 else => { 186 187 run.setColor(ctx, .@"error"); ··· 197 198 ) error{WriteFailed}!void { 198 199 const active_type = comptime std.meta.activeTag(@typeInfo(T)); 199 200 const excluded = comptime switch (active_type) { 200 - .void, .noreturn, .undefined, .null => true, 201 + .void, .noreturn, .undefined, .null, .@"fn" => true, 201 202 else => false, 202 203 }; 203 204 ··· 330 331 ) !void { 331 332 run.setColor(ctx, .value); 332 333 try run.print("{}", .{value}); 334 + run.resetColor(); 335 + } 336 + 337 + inline fn formatFn( 338 + comptime T: type, 339 + comptime ctx: Context, 340 + run: *const Runtime, 341 + ) !void { 342 + run.setColor(ctx, .dim); 343 + run.setColor(ctx, .type); 344 + run.setColorRaw(.bold); 345 + 346 + try run.write(@typeName(T)); 347 + 333 348 run.resetColor(); 334 349 } 335 350