From ae679f29d963fd87681b0393ac5e1e5241793999 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Sat, 3 Oct 2026 02:28:22 +0200 Subject: [PATCH] pull,ui,report: render the pull downloads as byte progress MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pull downloads reported through the plain count port only because byte_progress landed on main after the branch was cut. PullView now implements it with a byte-counter template in the transfer-style family (same shape, {bytes}/{total_bytes} counters, human-formatted by indicatif), downloads emit through it, and the trait doc lists the event among the ones the pull flow emits — un-duplicating the merged 'message, progress and progress' sentence. --- src/pull.rs | 3 +-- src/report.rs | 2 +- src/ui.rs | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/pull.rs b/src/pull.rs index 019a348..85afeb6 100644 --- a/src/pull.rs +++ b/src/pull.rs @@ -503,8 +503,7 @@ async fn download_file_checksum_once( buffer.extend_from_slice(&chunk); if let Some(total) = total_size { - let index = min(buffer.len(), total as usize); - view.progress("Downloading...", index, total as usize); + view.byte_progress("Downloading...", min(buffer.len() as u64, total), total); } } diff --git a/src/report.rs b/src/report.rs index e8ac066..2c362c0 100644 --- a/src/report.rs +++ b/src/report.rs @@ -73,7 +73,7 @@ pub struct BuildTarget<'a> { /// the build thread; long-lived views are expected to be `Send + Sync` /// because builds may run inside async tasks. The pull flow only emits the /// [`BuildView::message`], [`BuildView::progress`] and -/// [`BuildView::progress`] events — no target, phases or outcome. +/// [`BuildView::byte_progress`] events — no target, phases or outcome. pub trait BuildView: Send + Sync { /// The build target was identified; the events that follow belong to it /// (including the earliest subprocess output, e.g. a chroot download). diff --git a/src/ui.rs b/src/ui.rs index c9c1cb9..6d8cdf4 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -41,6 +41,17 @@ pub(crate) fn transfer_style() -> ProgressStyle { .progress_chars("=> ") } +/// [`transfer_style`] with human-formatted byte counters, for the events +/// reported through [`crate::report::BuildView::byte_progress`] +pub(crate) fn byte_style() -> ProgressStyle { + ProgressStyle::default_bar() + .template( + "> {spinner:.blue} {prefix}\n {msg} [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({eta})", + ) + .unwrap() + .progress_chars("=> ") +} + /// A standalone spinner for one-line waits outside a build view (the /// prune size pass): braille frames over the message behind the `> ` /// prompt prefix, drawn only on terminals. Callers finish it with @@ -142,6 +153,17 @@ impl crate::report::BuildView for PullView { self.pb.set_position(pos as u64); } + fn byte_progress(&self, label: &str, pos: u64, total: u64) { + if pos != 0 && total != 0 { + self.pb.set_style(byte_style()); + } else { + self.pb.set_style(spinner_style()); + } + self.pb.set_message(label.to_string()); + self.pb.set_length(total); + self.pb.set_position(pos); + } + fn is_enabled(&self) -> bool { true }