zli v3.7.0
Important
Introducing Spinners! by @xcaeser in #16
Spinners are a new feature in zli v3.7.0. Accessible through ctx.spinner, They are a powerful and customizable CLI spinner that can be used in any command's execFn.
Here's an example of how it works:
fn run(ctx: CLICommandContext) !void {
const writer = ctx.command.stdout; // Convenience
// --- Example 1: Basic single-line spinner ---
try writer.print("\n--- Example 1: Single-Line Spinner ---\n", .{});
try ctx.spinner.start(.{}, "Starting a simple, single-line task...", .{});
std.time.sleep(2 * std.time.ns_per_s);
try ctx.spinner.succeed("Single-line task complete!", .{});
std.time.sleep(1 * std.time.ns_per_s);
// --- Example 2: Multi-step process ---
try writer.print("\n--- Example 2: Multi-Step Process ---\n", .{});
try ctx.spinner.start(.{}, "Step 1: Initializing network...", .{});
std.time.sleep(1500 * std.time.ms_per_s);
try ctx.spinner.nextStep("Step 2: Authenticating user...", .{});
std.time.sleep(1500 * std.time.ms_per_s);
try ctx.spinner.updateText("Step 2: Authentication is taking a moment...", .{});
std.time.sleep(1500 * std.time.ms_per_s);
try ctx.spinner.nextStep("Step 3: Fetching data...", .{});
std.time.sleep(2 * std.time.ns_per_s);
try ctx.spinner.fail("Failed to fetch data from server.", .{});
std.time.sleep(1 * std.time.ns_per_s);
// --- Example 3: Adding log lines during a process ---
try writer.print("\n--- Example 3: Process with Log Lines ---\n", .{});
try ctx.spinner.start(.{}, "Downloading and unpacking files...", .{});
std.time.sleep(1 * std.time.ns_per_s);
try ctx.spinner.addLine("Downloaded archive.zip (2.5 MB)", .{});
std.time.sleep(1 * std.time.ns_per_s);
try ctx.spinner.addLine("Unpacking to /tmp/my-app...", .{});
std.time.sleep(1500 * std.time.ms_per_s);
try ctx.spinner.addLine("Verified file integrity.", .{});
std.time.sleep(1 * std.time.ns_per_s);
try ctx.spinner.succeed("All files ready.", .{});
std.time.sleep(1 * std.time.ns_per_s);
// --- Example 4: Customizing style at runtime ---
try writer.print("\n--- Example 4: Customizing Style at Start ---\n", .{});
try ctx.spinner.start(.{
.frames = zli.SpinnerStyles.bouncing_bar,
.interval_ms = 120,
}, "Running with a different style...", .{});
std.time.sleep(3 * std.time.ns_per_s);
try ctx.spinner.info("Custom run finished for your information.", .{});
try writer.print("\n", .{});
}
full changelog: v3.6.3...v3.7.0