commit 11f894702b7c06b87f6e94eff719d9f83eaeeddf (tree)
parent 52ed54d1e7a396f4508829af45c6953f1a827a1c
Author: Andrew Kelley <andrew@ziglang.org>
Date: Mon, 27 May 2024 08:38:02 -0700
std.Progress: avoid scrolling the PS1 off the terminal
Diffstat:
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig
@@ -908,13 +908,13 @@ fn computeNode(
global_progress.newline_count += 1;
}
- if (global_progress.newline_count < global_progress.rows) {
+ if (global_progress.withinRowLimit()) {
if (children[@intFromEnum(node_index)].child.unwrap()) |child| {
i = computeNode(buf, i, serialized, children, child);
}
}
- if (global_progress.newline_count < global_progress.rows) {
+ if (global_progress.withinRowLimit()) {
if (children[@intFromEnum(node_index)].sibling.unwrap()) |sibling| {
i = computeNode(buf, i, serialized, children, sibling);
}
@@ -923,6 +923,11 @@ fn computeNode(
return i;
}
+fn withinRowLimit(p: *Progress) bool {
+ // The +1 here is so that the PS1 is not scrolled off the top of the terminal.
+ return p.newline_count + 1 < p.rows;
+}
+
fn write(buf: []const u8) void {
const tty = global_progress.terminal orelse return;
tty.writeAll(buf) catch {