1974 shaares
6 private links
6 private links
2 results
tagged
progressbar
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.
/ scroll down a bit to avoid visual glitch when the screen
// area shrinks by one row
std::cout << "\n";
// save cursor
std::cout << "\0337";
// set scroll region (this will place the cursor in the top left)
std::cout << "\033[0;" << std::to_string(nr_rows - 1) << "r";
// restore cursor but ensure its inside the scrolling area
std::cout << "\0338";
static const char *move_cursor_up = "\033[1A";
std::cout << move_cursor_up;