From 135e4d64dd80549a3224a5cb3f281a1afd677104 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sun, 6 Nov 2022 16:31:25 -0800 Subject: [PATCH] cli: clean up progress error handling --- src/commands.rs | 2 +- src/progress.rs | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 1409195e7e..d4fd1a2c6c 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -4104,7 +4104,7 @@ fn with_remote_callbacks(ui: &mut Ui, f: impl FnOnce(git::RemoteCallbacks<'_> let mut progress = Progress::new(Instant::now()); let ui = &ui; callback = Some(move |x: &git::Progress| { - progress.update(Instant::now(), x, *ui.lock().unwrap()); + _ = progress.update(Instant::now(), x, *ui.lock().unwrap()); }); } let mut callbacks = git::RemoteCallbacks::default(); diff --git a/src/progress.rs b/src/progress.rs index c97a9eb12c..6bccd0ca23 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -1,3 +1,4 @@ +use std::io; use std::time::{Duration, Instant}; use crossterm::terminal::{Clear, ClearType}; @@ -20,19 +21,24 @@ impl Progress { } } - pub fn update(&mut self, now: Instant, progress: &git::Progress, ui: &mut Ui) { + pub fn update( + &mut self, + now: Instant, + progress: &git::Progress, + ui: &mut Ui, + ) -> io::Result<()> { use std::fmt::Write as _; if progress.overall == 1.0 { - _ = write!(ui, "\r{}", Clear(ClearType::CurrentLine)); - return; + write!(ui, "\r{}", Clear(ClearType::CurrentLine))?; + return Ok(()); } let rate = progress .bytes_downloaded .and_then(|x| self.rate.update(now, x)); if now < self.next_print { - return; + return Ok(()); } self.next_print = now.min(self.next_print + Duration::from_secs(1) / UPDATE_HZ); @@ -54,8 +60,9 @@ impl Progress { draw_progress(progress.overall, &mut self.buffer, bar_width); self.buffer.push(']'); - _ = write!(ui, "{}", self.buffer); - _ = ui.flush(); + write!(ui, "{}", self.buffer)?; + ui.flush()?; + Ok(()) } }