Zig aligned plain-text terminal table
Zig
const std = @import("std");
const Row = struct { name: []const u8, stars: u32 };
fn printTable(rows: []const Row) void {
const w = std.io.getStdOut().writer();
w.print("{s: <12} {s: >7}\n", .{ "name", "stars" }) catch return;
w.print("{s:-<12} {s:-<7}\n", .{ "", "" }) catch return;
for (rows) |r| w.print("{s: <12} {d: >7}\n", .{ r.name, r.stars }) catch return;
}
pub fn main() void {
printTable(&[_]Row{
.{ .name = "zig", .stars = 12 },
.{ .name = "rust", .stars = 3 },
.{ .name = "go", .stars = 40 },
});
}