authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 08:38:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 20:56:48-07:00
log11f894702b7c06b87f6e94eff719d9f83eaeeddf
treebfd8473bb16cd9f104a416e08c3b1d868e9f4cfc
parent52ed54d1e7a396f4508829af45c6953f1a827a1c

std.Progress: avoid scrolling the PS1 off the terminal


1 files changed, 7 insertions(+), 2 deletions(-)

lib/std/Progress.zig+7-2
...@@ -908,13 +908,13 @@ fn computeNode(...@@ -908,13 +908,13 @@ fn computeNode(
908 global_progress.newline_count += 1;908 global_progress.newline_count += 1;
909 }909 }
910910
911 if (global_progress.newline_count < global_progress.rows) {911 if (global_progress.withinRowLimit()) {
912 if (children[@intFromEnum(node_index)].child.unwrap()) |child| {912 if (children[@intFromEnum(node_index)].child.unwrap()) |child| {
913 i = computeNode(buf, i, serialized, children, child);913 i = computeNode(buf, i, serialized, children, child);
914 }914 }
915 }915 }
916916
917 if (global_progress.newline_count < global_progress.rows) {917 if (global_progress.withinRowLimit()) {
918 if (children[@intFromEnum(node_index)].sibling.unwrap()) |sibling| {918 if (children[@intFromEnum(node_index)].sibling.unwrap()) |sibling| {
919 i = computeNode(buf, i, serialized, children, sibling);919 i = computeNode(buf, i, serialized, children, sibling);
920 }920 }
...@@ -923,6 +923,11 @@ fn computeNode(...@@ -923,6 +923,11 @@ fn computeNode(
923 return i;923 return i;
924}924}
925925
926fn withinRowLimit(p: *Progress) bool {
927 // The +1 here is so that the PS1 is not scrolled off the top of the terminal.
928 return p.newline_count + 1 < p.rows;
929}
930
926fn write(buf: []const u8) void {931fn write(buf: []const u8) void {
927 const tty = global_progress.terminal orelse return;932 const tty = global_progress.terminal orelse return;
928 tty.writeAll(buf) catch {933 tty.writeAll(buf) catch {