Skip to content

Commit

Permalink
Un-mystify terminal overflow checking
Browse files Browse the repository at this point in the history
  • Loading branch information
spoutn1k authored and djc committed Nov 15, 2024
1 parent d3cf542 commit edcab5a
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,18 +543,14 @@ impl DrawState {
let line_height = line.wrapped_height(term_width);

// Check here for bar lines that exceed the terminal height
if text_line_count <= idx {
// If all the orphan lines have been drawn, then `real_height` should be
// at least `orphan_visual_line_count`.
debug_assert!(text_height <= real_height);

// Don't consider orphan lines when comparing to terminal height.
if real_height - text_height + line_height > term.height().into() {
if matches!(line, LineType::Bar(_)) {
// Stop here if printing this bar would exceed the terminal height
if real_height + line_height > term.height().into() {
break;
}
}

real_height += line_height;
real_height += line_height;
}

// Print a new line if this is not the first line printed this tick
// the first line will automatically wrap due to the filler below
Expand All @@ -573,7 +569,7 @@ impl DrawState {
}

term.flush()?;
*bar_count = real_height - text_height + shift;
*bar_count = real_height + shift;

Ok(())
}
Expand Down

0 comments on commit edcab5a

Please sign in to comment.