From 3633f6b611c451be57cee7160c492a280f55aa2b Mon Sep 17 00:00:00 2001 From: Altagos Date: Sat, 24 Jan 2026 22:28:22 +0100 Subject: [PATCH] pretty vectors --- example/main.zig | 5 +++++ pretty.zig | 27 ++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/example/main.zig b/example/main.zig index cd9b7c2..9c4bb9a 100644 --- a/example/main.zig +++ b/example/main.zig @@ -119,6 +119,11 @@ pub fn main(init: std.process.Init) !void { })}, ); + const zig_logo_color: @Vector(4, u8) = .{ 247, 164, 29, 255 }; + + print("\nVectors\n", .{}); + print("Pretty vector of u8s - {f}\n", .{pretty(zig_logo_color)}); + const eu_error: Result = error.OutOfMemory; const eu_ok: Result = .world; diff --git a/pretty.zig b/pretty.zig index 84571c7..595a9c5 100644 --- a/pretty.zig +++ b/pretty.zig @@ -190,7 +190,7 @@ fn innerFmt( .array => |arr| formatArray(ctx, arr, run, value), // TODO: .pointer => |ptr| {}, - // TODO: .vector => |vec| {}, + .vector => |vec| formatVector(ctx, vec, run, value), .@"fn" => formatFn(T, ctx, run), @@ -374,6 +374,31 @@ inline fn formatArray( } } +inline fn formatVector( + comptime ctx: Context, + comptime vec: Type.Vector, + run: *Runtime, + value: @Vector(vec.len, vec.child), +) !void { + run.setColor(ctx, .dim); + try run.write("( "); + run.resetColor(); + + inline for (0..vec.len) |idx| { + if (idx != 0) { + run.setColor(ctx, .dim); + try run.write(", "); + run.resetColor(); + } + + try innerFmt(vec.child, ctx, run, value[idx], .{ .skip_type_name = true }); + } + + run.setColor(ctx, .dim); + try run.write(" )"); + run.resetColor(); +} + inline fn formatErrorSet( comptime ctx: Context, run: *const Runtime, -- 2.51.2