Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regressions #414

Merged
merged 3 commits into from Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/draw_target.rs
@@ -1,5 +1,6 @@
use std::io;
use std::sync::{Arc, RwLock, RwLockWriteGuard};
use std::thread::panicking;
use std::time::{Duration, Instant};

use console::Term;
Expand Down Expand Up @@ -378,6 +379,10 @@ impl DrawState {
term: &(impl TermLike + ?Sized),
last_line_count: &mut usize,
) -> io::Result<()> {
if panicking() {
return Ok(());
}

if !self.lines.is_empty() && self.move_cursor {
term.move_cursor_up(*last_line_count)?;
} else {
Expand Down
10 changes: 6 additions & 4 deletions src/multi.rs
Expand Up @@ -113,7 +113,8 @@ impl MultiProgress {
/// If the passed progress bar does not satisfy the condition above,
/// the `remove` method does nothing.
pub fn remove(&self, pb: &ProgressBar) {
let idx = match &pb.state().draw_target.remote() {
let mut state = pb.state();
let idx = match &state.draw_target.remote() {
Some((state, idx)) => {
// Check that this progress bar is owned by the current MultiProgress.
assert!(Arc::ptr_eq(&self.state, state));
Expand All @@ -122,6 +123,7 @@ impl MultiProgress {
_ => return,
};

state.draw_target = ProgressDrawTarget::hidden();
self.state.write().unwrap().remove_idx(idx);
}

Expand Down Expand Up @@ -433,8 +435,8 @@ mod tests {
}

assert_eq!(p0.index().unwrap(), 0);
assert_eq!(p1.index().unwrap(), 1);
assert_eq!(p2.index().unwrap(), 2);
assert_eq!(p1.index(), None);
assert_eq!(p2.index(), None);
assert_eq!(p3.index().unwrap(), 3);
}

Expand Down Expand Up @@ -533,7 +535,7 @@ mod tests {
assert_eq!(state.free_set.last(), Some(&0));

assert_eq!(state.ordering, vec![1]);
assert_eq!(p0.index().unwrap(), 0);
assert_eq!(p0.index(), None);
assert_eq!(p1.index().unwrap(), 1);
}
}
16 changes: 7 additions & 9 deletions src/progress_bar.rs
Expand Up @@ -60,13 +60,8 @@ impl ProgressBar {
}

/// A convenience builder-like function for a progress bar with a given style
pub fn with_style(self, mut style: ProgressStyle) -> ProgressBar {
let mut state = self.state();
mem::swap(&mut state.style.message, &mut style.message);
mem::swap(&mut state.style.prefix, &mut style.prefix);
state.style = style;
drop(state);

pub fn with_style(self, style: ProgressStyle) -> ProgressBar {
self.set_style(style);
self
}

Expand Down Expand Up @@ -122,8 +117,11 @@ impl ProgressBar {
/// Overrides the stored style
///
/// This does not redraw the bar. Call [`ProgressBar::tick()`] to force it.
pub fn set_style(&self, style: ProgressStyle) {
self.state().style = style;
pub fn set_style(&self, mut style: ProgressStyle) {
let mut state = self.state();
mem::swap(&mut state.style.message, &mut style.message);
mem::swap(&mut state.style.prefix, &mut style.prefix);
state.style = style;
}

/// Spawns a background thread to tick the progress bar
Expand Down