chiark / gitweb /
progress: Provide termprogress::clear()
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 10:59:26 +0000 (11:59 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 13:58:58 +0000 (14:58 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/termprogress.rs

index 8fa4b5c18e16b43a058a010b9da59f32e0215cd2..db6f5a4f043cac5b1ca3464220f491d3b619a7d0 100644 (file)
@@ -11,6 +11,7 @@ type Col = usize;
 
 pub trait Reporter {
   fn report(&mut self, pi: &ProgressInfo<'_>);
+  fn clear(&mut self);
 }
 
 pub struct NullReporter;
@@ -18,6 +19,7 @@ pub struct NullReporter;
 #[allow(unused_variables)]
 impl Reporter for NullReporter {
   fn report(&mut self, pi: &ProgressInfo<'_>) { }
+  fn clear(&mut self) { }
 }
 
 pub fn new() -> Box<dyn Reporter> {
@@ -99,6 +101,11 @@ impl Reporter for TermReporter {
     }
     self.term.flush().unwrap_or(());
   }
+
+  fn clear(&mut self) {
+    self.clear_line();
+    self.term.flush().unwrap_or(());
+  }
 }
 
 impl TermReporter {
@@ -149,7 +156,6 @@ impl TermReporter {
 
 impl Drop for TermReporter {
   fn drop(&mut self) {
-    self.clear_line();
-    self.term.flush().unwrap_or(());
+    self.clear();
   }
 }