A pretty printer for zig
zig

print braces for empty arrays

altagos.dev aa04716e da8f80cb

verified
+17 -1
+17 -1
pretty.zig
··· 206 206 } 207 207 }; 208 208 209 - const InnerFmtOptions = struct { 209 + pub const InnerFmtOptions = struct { 210 210 skip_type_name: bool = !default_options.show_type_names, 211 211 }; 212 212 ··· 426 426 run: *const Runtime, 427 427 value: anytype, 428 428 ) !void { 429 + if (arr.len == 0) { 430 + try run.write(ctx.options.theme.array_open); 431 + try run.write(ctx.options.theme.array_close); 432 + return; 433 + } 434 + 429 435 const next_ctx = Context{ 430 436 .depth = ctx.depth + 1, 431 437 .exited_comptime = ctx.exited_comptime, ··· 520 526 521 527 if (ctx.options.ptr_slice_inline) try arrayOpen(ctx, run); 522 528 529 + var count: usize = 0; 523 530 for (value, 0..) |val, idx| { 531 + count += 1; 532 + 524 533 indent( 525 534 next_ctx, 526 535 next_ctx.options.ptr_slice_inline, ··· 541 550 run.resetColor(); 542 551 543 552 try innerFmt(ptr.child, next_ctx, run, val, .{ .skip_type_name = true }); 553 + } 554 + 555 + if (count == 0) { 556 + run.setColor(ctx, .dim); 557 + try run.write(ctx.options.theme.array_open); 558 + try run.write(ctx.options.theme.array_close); 559 + run.resetColor(); 544 560 } 545 561 546 562 if (ctx.options.ptr_slice_inline) try arrayClose(ctx, run);