feature. See also
. The project being documented here (as the example) is the Zig library itself.
Progress.computeNode
fn computeNode(
buf: []u8,
start_i: usize,
start_nl_n: usize,
serialized: Serialized,
children: []const Children,
node_index: Node.Index,
) struct
File
Code
fn computeNode(
buf: []u8,
start_i: usize,
start_nl_n: usize,
serialized: Serialized,
children: []const Children,
node_index: Node.Index,
) struct { usize, usize } {
var i = start_i;
var nl_n = start_nl_n;
i = computePrefix(buf, i, nl_n, serialized, children, node_index);
if (i + lineUpperBoundLen(nl_n) > buf.len)
return .{ start_i, start_nl_n };
const storage = &serialized.storage[@backingInt(node_index)];
const estimated_total = storage.estimated_total_count;
const completed_items = storage.completed_count;
const name = if (std.mem.findScalar(u8, &storage.name, 0)) |end| storage.name[0..end] else &storage.name;
const parent = serialized.parents[@backingInt(node_index)];
if (parent != .none) p: {
if (@backingInt(parent) == 0 and serialized.storage[0].name[0] == 0) {
break :p;
}
if (children[@backingInt(node_index)].sibling == .none) {
i = appendTreeSymbol(.langle, buf, i);
} else {
i = appendTreeSymbol(.tee, buf, i);
}
}
const is_empty_root = @backingInt(node_index) == 0 and serialized.storage[0].name[0] == 0;
if (!is_empty_root) {
if (name.len != 0 or estimated_total > 0) {
if (estimated_total > 0) {
if (std.fmt.bufPrint(buf[i..], "[{d}/{d}] ", .{ completed_items, estimated_total })) |b| {
i += b.len;
} else |_| {}
} else if (completed_items != 0) {
if (std.fmt.bufPrint(buf[i..], "[{d}] ", .{completed_items})) |b| {
i += b.len;
} else |_| {}
}
if (name.len != 0) {
if (std.fmt.bufPrint(buf[i..], "{s}", .{name})) |b| {
i += b.len;
} else |_| {}
}
}
i = @min(global_progress.cols + start_i, i);
if (is_windows) {
// ENABLE_VIRTUAL_TERMINAL_PROCESSING | DISABLE_NEWLINE_AUTO_RETURN
// console modes set to behave properly.
buf[i] = '\r';
i += 1;
}
buf[i] = '\n';
i += 1;
nl_n += 1;
}
if (global_progress.withinRowLimit(nl_n)) {
if (children[@backingInt(node_index)].child.unwrap()) |child| {
i, nl_n = computeNode(buf, i, nl_n, serialized, children, child);
}
}
if (global_progress.withinRowLimit(nl_n)) {
if (children[@backingInt(node_index)].sibling.unwrap()) |sibling| {
i, nl_n = computeNode(buf, i, nl_n, serialized, children, sibling);
}
}
return .{ i, nl_n };
}