pull,ui,report: render the pull downloads as byte progress
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.
This commit is contained in:
+1
-2
@@ -503,8 +503,7 @@ async fn download_file_checksum_once(
|
|||||||
buffer.extend_from_slice(&chunk);
|
buffer.extend_from_slice(&chunk);
|
||||||
|
|
||||||
if let Some(total) = total_size {
|
if let Some(total) = total_size {
|
||||||
let index = min(buffer.len(), total as usize);
|
view.byte_progress("Downloading...", min(buffer.len() as u64, total), total);
|
||||||
view.progress("Downloading...", index, total as usize);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ pub struct BuildTarget<'a> {
|
|||||||
/// the build thread; long-lived views are expected to be `Send + Sync`
|
/// 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
|
/// because builds may run inside async tasks. The pull flow only emits the
|
||||||
/// [`BuildView::message`], [`BuildView::progress`] and
|
/// [`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 {
|
pub trait BuildView: Send + Sync {
|
||||||
/// The build target was identified; the events that follow belong to it
|
/// The build target was identified; the events that follow belong to it
|
||||||
/// (including the earliest subprocess output, e.g. a chroot download).
|
/// (including the earliest subprocess output, e.g. a chroot download).
|
||||||
|
|||||||
@@ -41,6 +41,17 @@ pub(crate) fn transfer_style() -> ProgressStyle {
|
|||||||
.progress_chars("=> ")
|
.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
|
/// A standalone spinner for one-line waits outside a build view (the
|
||||||
/// prune size pass): braille frames over the message behind the `> `
|
/// prune size pass): braille frames over the message behind the `> `
|
||||||
/// prompt prefix, drawn only on terminals. Callers finish it with
|
/// 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);
|
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 {
|
fn is_enabled(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user