Skip to content

Commit 8315a50

Browse files
committed
std.Progress: fix line upper bound calculation
closes #20161 problem introduced in e09963d
1 parent 64ef45e commit 8315a50

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/std/Progress.zig

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,7 @@ fn computeRedraw(serialized_buffer: *Serialized.Buffer) struct { []u8, usize } {
11061106
fn computePrefix(
11071107
buf: []u8,
11081108
start_i: usize,
1109+
nl_n: usize,
11091110
serialized: Serialized,
11101111
children: []const Children,
11111112
node_index: Node.Index,
@@ -1118,23 +1119,27 @@ fn computePrefix(
11181119
{
11191120
return i;
11201121
}
1121-
i = computePrefix(buf, i, serialized, children, parent_index);
1122+
i = computePrefix(buf, i, nl_n, serialized, children, parent_index);
11221123
if (children[@intFromEnum(parent_index)].sibling == .none) {
11231124
const prefix = " ";
1124-
const upper_bound_len = prefix.len + line_upper_bound_len;
1125+
const upper_bound_len = prefix.len + lineUpperBoundLen(nl_n);
11251126
if (i + upper_bound_len > buf.len) return buf.len;
11261127
buf[i..][0..prefix.len].* = prefix.*;
11271128
i += prefix.len;
11281129
} else {
1129-
const upper_bound_len = comptime (TreeSymbol.line.maxByteLen() + line_upper_bound_len);
1130+
const upper_bound_len = TreeSymbol.line.maxByteLen() + lineUpperBoundLen(nl_n);
11301131
if (i + upper_bound_len > buf.len) return buf.len;
11311132
i = appendTreeSymbol(.line, buf, i);
11321133
}
11331134
return i;
11341135
}
11351136

1136-
const line_upper_bound_len = @max(TreeSymbol.tee.maxByteLen(), TreeSymbol.langle.maxByteLen()) +
1137-
"[4294967296/4294967296] ".len + Node.max_name_len + (1 + up_one_line.len) + finish_sync.len;
1137+
fn lineUpperBoundLen(nl_n: usize) usize {
1138+
return @max(TreeSymbol.tee.maxByteLen(), TreeSymbol.langle.maxByteLen()) +
1139+
"[4294967296/4294967296] ".len + Node.max_name_len + 1 +
1140+
(1 + (nl_n + 1) * up_one_line.len) +
1141+
finish_sync.len;
1142+
}
11381143

11391144
fn computeNode(
11401145
buf: []u8,
@@ -1147,9 +1152,9 @@ fn computeNode(
11471152
var i = start_i;
11481153
var nl_n = start_nl_n;
11491154

1150-
i = computePrefix(buf, i, serialized, children, node_index);
1155+
i = computePrefix(buf, i, nl_n, serialized, children, node_index);
11511156

1152-
if (i + line_upper_bound_len > buf.len)
1157+
if (i + lineUpperBoundLen(nl_n) > buf.len)
11531158
return .{ start_i, start_nl_n };
11541159

11551160
const storage = &serialized.storage[@intFromEnum(node_index)];

0 commit comments

Comments
 (0)