Skip to content

Commit

Permalink
do not merge; incredibly hacky fix for console-rs#451
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-laplante committed Aug 3, 2022
1 parent 626ebdb commit fb8b10e
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ pub(crate) struct MultiState {
alignment: MultiProgressAlignment,
/// Orphaned lines are carried over across draw operations
orphan_lines: Vec<String>,
/// Number of lines from zombies that have been reaped
zombie_line_count: usize,
}

impl MultiState {
Expand All @@ -199,6 +201,7 @@ impl MultiState {
move_cursor: false,
alignment: Default::default(),
orphan_lines: Vec::new(),
zombie_line_count: 0,
}
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit fb8b10e

Please sign in to comment.