authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-22 22:09:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 20:56:48-07:00
log582acdf7212949913c0c902b354172502fb00e73
tree8768fc9d1cef6f597ce446df89533cc8756adaa5
parent66c3b6ac65fad662c121073500c3cf3b7c9fcb60

keep the cursor at the end instead of beginning


1 files changed, 16 insertions(+), 12 deletions(-)

lib/std/Progress.zig+16-12
......@@ -60,7 +60,7 @@ pub const Options = struct {
6060 /// Must be at least 200 bytes.
6161 draw_buffer: []u8,
6262 /// How many nanoseconds between writing updates to the terminal.
63 refresh_rate_ns: u64 = 50 * std.time.ns_per_ms,
63 refresh_rate_ns: u64 = 60 * std.time.ns_per_ms,
6464 /// How many nanoseconds to keep the output hidden
6565 initial_delay_ns: u64 = 500 * std.time.ns_per_ms,
6666 /// If provided, causes the progress item to have a denominator.
......@@ -435,8 +435,8 @@ fn computeRedraw() []u8 {
435435 }
436436 }
437437
438 // The strategy is: keep the cursor at the beginning, and then with every redraw:
439 // erase to end of screen, write, move cursor to beginning of line, move cursor up N lines
438 // The strategy is: keep the cursor at the end, and then with every redraw:
439 // move cursor to beginning of line, move cursor up N lines, erase to end of screen, write
440440
441441 var i: usize = 0;
442442 const buf = global_progress.draw_buffer;
......@@ -444,22 +444,26 @@ fn computeRedraw() []u8 {
444444 buf[i..][0..start_sync.len].* = start_sync.*;
445445 i += start_sync.len;
446446
447 buf[0..clear.len].* = clear.*;
448 i = clear.len;
449
450 const root_node_index: Node.Index = @enumFromInt(0);
451 i = computeNode(buf, i, serialized_node_storage, serialized_node_parents, children, root_node_index);
452
453 if (buf[i - 1] == '\n') {
454 buf[i - 1] = '\r';
455 const prev_nl_n = global_progress.newline_count - 1;
447 const prev_nl_n = global_progress.newline_count;
448 if (global_progress.newline_count > 0) {
456449 global_progress.newline_count = 0;
450 buf[i] = '\r';
451 i += 1;
457452 for (0..prev_nl_n) |_| {
458453 buf[i..][0..up_one_line.len].* = up_one_line.*;
459454 i += up_one_line.len;
460455 }
461456 }
462457
458 buf[i..][0..clear.len].* = clear.*;
459 i += clear.len;
460
461 const root_node_index: Node.Index = @enumFromInt(0);
462 i = computeNode(buf, i, serialized_node_storage, serialized_node_parents, children, root_node_index);
463
464 // Truncate trailing newline.
465 //if (buf[i - 1] == '\n') i -= 1;
466
463467 buf[i..][0..finish_sync.len].* = finish_sync.*;
464468 i += finish_sync.len;
465469