Daily Shaarli

All links of one day in a single page.

May 30, 2024

Zig's New CLI Progress Bar Explained - Andrew Kelley

When the ZIG_PROGRESS=X environment variable is present, where X is an unsigned decimal integer in range 0...65535, a process-wide progress reporting channel is available.

The integer is a writable file descriptor opened in non-blocking mode. Subsequent messages to the stream supersede previous ones.

The stream supports exactly one kind of message that looks like this:

len: u8 - number of nodes, limited to 253 max, reserving 0xfe and 0xff for special meaning.
48 bytes for every len:
    completed: u32le - how many items already done
    estimated_total: u32le - guessed number of items to be completed, or 0 (unknown)
    name: [40]u8 - task description; remaining bytes zeroed out
1 byte for every len:
    parent: u8 - creates an edge to a parent node in the tree, or 0xff (none)

Future versions of this protocol, if necessary, will use different environment variable names.