Skip to content

Commit 9b533cc

Browse files
smoeliuschris-laplante
authored andcommitted
Fix "type" error in draw_target.rs
The `multi_progress_println_terminal_wrap` test now passes.
1 parent e68cb3a commit 9b533cc

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/draw_target.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,11 @@ impl DrawState {
499499
let term_height = term.height() as usize;
500500
let term_width = term.width() as usize;
501501
let len = self.lines.len();
502+
debug_assert!(self.orphan_lines_count <= self.lines.len());
503+
let orphan_visual_line_count =
504+
visual_line_count(&self.lines[..self.orphan_lines_count], term_width);
502505
let mut real_len = 0;
503506
let mut last_line_filler = 0;
504-
debug_assert!(self.orphan_lines_count <= self.lines.len());
505507
for (idx, line) in self.lines.iter().enumerate() {
506508
let line_width = console::measure_text_width(line);
507509
let diff = if line.is_empty() {
@@ -518,12 +520,14 @@ impl DrawState {
518520
// subtract with overflow later.
519521
usize::max(terminal_len, 1)
520522
};
521-
// Don't consider orphan lines when comparing to terminal height.
522-
debug_assert!(idx <= real_len);
523-
if self.orphan_lines_count <= idx
524-
&& real_len - self.orphan_lines_count + diff > term_height
525-
{
526-
break;
523+
// Have all orphan lines been drawn?
524+
if self.orphan_lines_count <= idx {
525+
// If so, then `real_len` should be at least `orphan_visual_line_count`.
526+
debug_assert!(orphan_visual_line_count <= real_len);
527+
// Don't consider orphan lines when comparing to terminal height.
528+
if real_len - orphan_visual_line_count + diff > term_height {
529+
break;
530+
}
527531
}
528532
real_len += diff;
529533
if idx != 0 {
@@ -539,7 +543,7 @@ impl DrawState {
539543
term.write_str(&" ".repeat(last_line_filler))?;
540544

541545
term.flush()?;
542-
*last_line_count = real_len - self.orphan_lines_count + shift;
546+
*last_line_count = real_len - orphan_visual_line_count + shift;
543547
Ok(())
544548
}
545549

0 commit comments

Comments
 (0)