From fb8b10eeba376d139a79a3b7b4062ed925073618 Mon Sep 17 00:00:00 2001 From: Chris Laplante Date: Wed, 3 Aug 2022 16:31:46 -0400 Subject: [PATCH] do not merge; incredibly hacky fix for #451 --- src/multi.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/multi.rs b/src/multi.rs index c199fa55..c0fa0412 100644 --- a/src/multi.rs +++ b/src/multi.rs @@ -187,6 +187,8 @@ pub(crate) struct MultiState { alignment: MultiProgressAlignment, /// Orphaned lines are carried over across draw operations orphan_lines: Vec, + /// Number of lines from zombies that have been reaped + zombie_line_count: usize, } impl MultiState { @@ -199,6 +201,7 @@ impl MultiState { move_cursor: false, alignment: Default::default(), orphan_lines: Vec::new(), + zombie_line_count: 0, } } @@ -227,6 +230,7 @@ impl MultiState { // Adjust last line count so we don't clear too many lines if let Some(last_line_count) = self.draw_target.last_line_count() { *last_line_count -= adjust; + self.zombie_line_count += adjust; } let orphan_lines_count = self.orphan_lines.len(); @@ -343,10 +347,27 @@ impl MultiState { } fn clear(&mut self, now: Instant) -> io::Result<()> { - match self.draw_target.drawable(true, now) { - Some(drawable) => drawable.clear(), + let mut old_zombie_count = 0; + if let Some(last_line_count) = self.draw_target.last_line_count() { + *last_line_count += self.zombie_line_count; + old_zombie_count = self.zombie_line_count; + self.zombie_line_count = 0; + } + + let ret = match self.draw_target.drawable(true, now) { + Some(drawable) => { + old_zombie_count = 0; + drawable.clear() + }, None => Ok(()), + }; + + if let Some(last_line_count) = self.draw_target.last_line_count() { + *last_line_count -= old_zombie_count; + self.zombie_line_count = old_zombie_count; } + + ret } fn remove_idx(&mut self, idx: usize) {