From d25d51090cd8c1bdd9d792d63e93a5d0a28a1504 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 15 May 2024 10:36:02 +0200 Subject: [PATCH] Stop showing ETA after download is complete --- src/cli/download_tracker.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cli/download_tracker.rs b/src/cli/download_tracker.rs index 1bd3b208b3..ec07ea5ea0 100644 --- a/src/cli/download_tracker.rs +++ b/src/cli/download_tracker.rs @@ -186,13 +186,13 @@ impl DownloadTracker { (remaining / speed) as u64 }); format!( - "{} / {} ({:3.0} %) {} in {} ETA: {}", + "{} / {} ({:3.0} %) {} in {}{}", total_h, content_len_h, percent, speed_h, elapsed_h.display(), - eta_h.display(), + Eta(eta_h), ) } None => format!( @@ -220,6 +220,17 @@ impl DownloadTracker { } } +struct Eta(Duration); + +impl fmt::Display for Eta { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self.0 { + Duration::ZERO => Ok(()), + _ => write!(f, "{}", self.0.display()), + } + } +} + trait DurationDisplay { fn display(self) -> Display; }