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 {...@@ -60,7 +60,7 @@ pub const Options = struct {
60 /// Must be at least 200 bytes.60 /// Must be at least 200 bytes.
61 draw_buffer: []u8,61 draw_buffer: []u8,
62 /// How many nanoseconds between writing updates to the terminal.62 /// 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,
64 /// How many nanoseconds to keep the output hidden64 /// How many nanoseconds to keep the output hidden
65 initial_delay_ns: u64 = 500 * std.time.ns_per_ms,65 initial_delay_ns: u64 = 500 * std.time.ns_per_ms,
66 /// If provided, causes the progress item to have a denominator.66 /// If provided, causes the progress item to have a denominator.
...@@ -435,8 +435,8 @@ fn computeRedraw() []u8 {...@@ -435,8 +435,8 @@ fn computeRedraw() []u8 {
435 }435 }
436 }436 }
437437
438 // The strategy is: keep the cursor at the beginning, and then with every redraw:438 // The strategy is: keep the cursor at the end, and then with every redraw:
439 // erase to end of screen, write, move cursor to beginning of line, move cursor up N lines439 // move cursor to beginning of line, move cursor up N lines, erase to end of screen, write
440440
441 var i: usize = 0;441 var i: usize = 0;
442 const buf = global_progress.draw_buffer;442 const buf = global_progress.draw_buffer;
...@@ -444,22 +444,26 @@ fn computeRedraw() []u8 {...@@ -444,22 +444,26 @@ fn computeRedraw() []u8 {
444 buf[i..][0..start_sync.len].* = start_sync.*;444 buf[i..][0..start_sync.len].* = start_sync.*;
445 i += start_sync.len;445 i += start_sync.len;
446446
447 buf[0..clear.len].* = clear.*;447 const prev_nl_n = global_progress.newline_count;
448 i = clear.len;448 if (global_progress.newline_count > 0) {
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;
456 global_progress.newline_count = 0;449 global_progress.newline_count = 0;
450 buf[i] = '\r';
451 i += 1;
457 for (0..prev_nl_n) |_| {452 for (0..prev_nl_n) |_| {
458 buf[i..][0..up_one_line.len].* = up_one_line.*;453 buf[i..][0..up_one_line.len].* = up_one_line.*;
459 i += up_one_line.len;454 i += up_one_line.len;
460 }455 }
461 }456 }
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
463 buf[i..][0..finish_sync.len].* = finish_sync.*;467 buf[i..][0..finish_sync.len].* = finish_sync.*;
464 i += finish_sync.len;468 i += finish_sync.len;
465469