diff --git a/src/in_memory.rs b/src/in_memory.rs index 06da6a6c..a026da69 100644 --- a/src/in_memory.rs +++ b/src/in_memory.rs @@ -41,6 +41,7 @@ impl InMemoryTerm { .into_iter() .rev() .skip_while(|line| line.is_empty()) + .map(|line| line.trim_end().to_string()) .collect(); // Un-reverse the rows and join them up with newlines diff --git a/src/state.rs b/src/state.rs index 10396eb3..70012296 100644 --- a/src/state.rs +++ b/src/state.rs @@ -309,6 +309,7 @@ impl Ticker { self.interval = interval; state.draw(false, Instant::now()).ok(); drop(state); // Don't forget to drop the lock before sleeping + drop(arc); // Also need to drop Arc otherwise BarState won't be dropped thread::sleep(self.interval); } } diff --git a/tests/render.rs b/tests/render.rs index 0d8a5a67..1dc368ce 100644 --- a/tests/render.rs +++ b/tests/render.rs @@ -4,6 +4,7 @@ use indicatif::{ InMemoryTerm, MultiProgress, ProgressBar, ProgressDrawTarget, ProgressFinish, ProgressStyle, TermLike, }; +use std::time::Duration; #[test] fn basic_progress_bar() { @@ -242,3 +243,28 @@ Another line printed"# .trim() ); } + +#[test] +fn ticker_drop() { + let in_mem = InMemoryTerm::new(10, 80); + let mp = + MultiProgress::with_draw_target(ProgressDrawTarget::term_like(Box::new(in_mem.clone()))); + + let mut spinner: Option = None; + + for i in 0..5 { + let new_spinner = mp.add( + ProgressBar::new_spinner() + .with_finish(ProgressFinish::AndLeave) + .with_message(format!("doing stuff {}", i)), + ); + new_spinner.enable_steady_tick(Duration::from_millis(50)); + spinner.replace(new_spinner); + } + + drop(spinner); + assert_eq!( + in_mem.contents(), + " doing stuff 0\n doing stuff 1\n doing stuff 2\n doing stuff 3\n doing stuff 4" + ); +}