diff --git a/example/main.zig b/example/main.zig index d76b3dd..e7f6121 100644 --- a/example/main.zig +++ b/example/main.zig @@ -107,4 +107,8 @@ pub fn main(init: std.process.Init) !void { print("Error set - {f}\n", .{pretty(ErrorSet.OutOfMemory)}); print("Error union error - {f}\n", .{pretty(eu_error)}); print("Error union ok - {f}\n", .{pretty(eu_ok)}); + + print("\nFunctions\n", .{}); + print("Function Pretty - {f}\n", .{pretty(Pretty)}); + print("Function main - {f}\n", .{pretty(main)}); } diff --git a/pretty.zig b/pretty.zig index 8bbdac7..c484775 100644 --- a/pretty.zig +++ b/pretty.zig @@ -152,7 +152,8 @@ fn innerFmt( ) error{WriteFailed}!void { const info = @typeInfo(T); - if (!opts.skip_type_name) try printType(T, ctx, run); + if (!opts.skip_type_name) + try printType(T, ctx, run); return switch (info) { .bool => formatBool(ctx, run, value), @@ -180,7 +181,7 @@ fn innerFmt( // TODO: .pointer => |ptr| {}, // TODO: .vector => |vec| {}, - // TODO: .@"fn" => |f| {}, + .@"fn" => formatFn(T, ctx, run), else => { run.setColor(ctx, .@"error"); @@ -197,7 +198,7 @@ inline fn printType( ) error{WriteFailed}!void { const active_type = comptime std.meta.activeTag(@typeInfo(T)); const excluded = comptime switch (active_type) { - .void, .noreturn, .undefined, .null => true, + .void, .noreturn, .undefined, .null, .@"fn" => true, else => false, }; @@ -333,6 +334,20 @@ inline fn formatValue( run.resetColor(); } +inline fn formatFn( + comptime T: type, + comptime ctx: Context, + run: *const Runtime, +) !void { + run.setColor(ctx, .dim); + run.setColor(ctx, .type); + run.setColorRaw(.bold); + + try run.write(@typeName(T)); + + run.resetColor(); +} + inline fn indent(comptime ctx: Context, run: *const Runtime) void { if (ctx.options.inline_structs) return;