Are you an LLM? You can read better optimized documentation at /loaders.zig/examples/01-basic-bar.md for this page in Markdown format
Basic Bar
Minimal 50-step progress bar with percentage display.
Source
zig
const std = @import("std");
const loaders = @import("loaders");
pub fn main(init: std.process.Init) !void {
const io = init.io;
const total: usize = 50;
var bar = loaders.Bar.init(io, .{
.label = "Processing",
.total = total,
.show_percent = true,
});
defer bar.done();
for (0..total) |i| {
bar.setCompleted(i + 1);
bar.render();
try io.sleep(std.Io.Duration.fromMilliseconds(40), .awake);
}
}Run
bash
zig build run-01_basic_barOutput
Processing [██████████████████████████████████████████████████] 100%The bar animates from 0% to 100%, overwriting the same line on each frame.
