authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-22 22:23:49-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 20:56:48-07:00
log67e08e7b3cbed652953b21fb50ffff337318ae16
treec83089804461e4e77de080252fd43a688d4e0649
parent582acdf7212949913c0c902b354172502fb00e73

fix clearing and sibling iteration


1 files changed, 28 insertions(+), 8 deletions(-)

lib/std/Progress.zig+28-8
...@@ -361,7 +361,30 @@ const tree_line = "\x1B\x28\x30\x78\x1B\x28\x42 "; // │...@@ -361,7 +361,30 @@ const tree_line = "\x1B\x28\x30\x78\x1B\x28\x42 "; // │
361const tree_langle = "\x1B\x28\x30\x6d\x71\x1B\x28\x42 "; // └─361const tree_langle = "\x1B\x28\x30\x6d\x71\x1B\x28\x42 "; // └─
362362
363fn clearTerminal() void {363fn clearTerminal() void {
364 write(clear);364 var i: usize = 0;
365 const buf = global_progress.draw_buffer;
366
367 buf[i..][0..start_sync.len].* = start_sync.*;
368 i += start_sync.len;
369
370 const prev_nl_n = global_progress.newline_count;
371 if (prev_nl_n > 0) {
372 global_progress.newline_count = 0;
373 buf[i] = '\r';
374 i += 1;
375 for (0..prev_nl_n) |_| {
376 buf[i..][0..up_one_line.len].* = up_one_line.*;
377 i += up_one_line.len;
378 }
379 }
380
381 buf[i..][0..clear.len].* = clear.*;
382 i += clear.len;
383
384 buf[i..][0..finish_sync.len].* = finish_sync.*;
385 i += finish_sync.len;
386
387 write(buf[0..i]);
365}388}
366389
367const Children = struct {390const Children = struct {
...@@ -428,8 +451,8 @@ fn computeRedraw() []u8 {...@@ -428,8 +451,8 @@ fn computeRedraw() []u8 {
428 const children_node = &children[@intFromEnum(parent_index)];451 const children_node = &children[@intFromEnum(parent_index)];
429 if (children_node.child.unwrap()) |existing_child_index| {452 if (children_node.child.unwrap()) |existing_child_index| {
430 const existing_child = &children[@intFromEnum(existing_child_index)];453 const existing_child = &children[@intFromEnum(existing_child_index)];
431 existing_child.sibling = child_index.toOptional();
432 children[@intFromEnum(child_index)].sibling = existing_child.sibling;454 children[@intFromEnum(child_index)].sibling = existing_child.sibling;
455 existing_child.sibling = child_index.toOptional();
433 } else {456 } else {
434 children_node.child = child_index.toOptional();457 children_node.child = child_index.toOptional();
435 }458 }
...@@ -445,7 +468,7 @@ fn computeRedraw() []u8 {...@@ -445,7 +468,7 @@ fn computeRedraw() []u8 {
445 i += start_sync.len;468 i += start_sync.len;
446469
447 const prev_nl_n = global_progress.newline_count;470 const prev_nl_n = global_progress.newline_count;
448 if (global_progress.newline_count > 0) {471 if (prev_nl_n > 0) {
449 global_progress.newline_count = 0;472 global_progress.newline_count = 0;
450 buf[i] = '\r';473 buf[i] = '\r';
451 i += 1;474 i += 1;
...@@ -539,11 +562,8 @@ fn computeNode(...@@ -539,11 +562,8 @@ fn computeNode(
539 i = computeNode(buf, i, serialized_node_storage, serialized_node_parents, children, child);562 i = computeNode(buf, i, serialized_node_storage, serialized_node_parents, children, child);
540 }563 }
541564
542 {565 if (children[@intFromEnum(node_index)].sibling.unwrap()) |sibling| {
543 var opt_sibling = children[@intFromEnum(node_index)].sibling;566 i = computeNode(buf, i, serialized_node_storage, serialized_node_parents, children, sibling);
544 while (opt_sibling.unwrap()) |sibling| {
545 i = computeNode(buf, i, serialized_node_storage, serialized_node_parents, children, sibling);
546 }
547 }567 }
548568
549 return i;569 return i;