std.Progress: avoid scrolling the PS1 off the terminal

This commit is contained in:
Andrew Kelley 2024-05-27 08:38:02 -07:00
parent 52ed54d1e7
commit 11f894702b

View file

@ -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 {