Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 60 additions & 3 deletions src/cli/download_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ impl DownloadTracker {
self.retrying_download(url);
true
}
Notification::Install(In::InstallingComponent(component, _, _)) => {
self.installing_component(component);
true
}
Notification::Install(In::ComponentInstalled(component, _, _)) => {
self.component_installed(component);
true
}
_ => false,
}
}
Expand Down Expand Up @@ -125,10 +133,13 @@ impl DownloadTracker {
return;
};
pb.set_style(
ProgressStyle::with_template("{msg:>12.bold} downloaded {total_bytes} in {elapsed}")
.unwrap(),
ProgressStyle::with_template(if pb.position() != 0 {
"{msg:>12.bold} downloaded {total_bytes} in {elapsed}"
} else {
"{msg:>12.bold} component already downloaded"
})
.unwrap(),
);
pb.finish();
}

/// Notifies self that the download has failed.
Expand All @@ -151,4 +162,50 @@ impl DownloadTracker {
*retry_time = Some(Instant::now());
pb.set_style(ProgressStyle::with_template("{msg:>12.bold} retrying download").unwrap());
}

/// Notifies self that the component is being installed.
pub(crate) fn installing_component(&mut self, component: &str) {
let key = self
.file_progress_bars
.keys()
.find(|comp| comp.contains(component))
.cloned();
if let Some(key) = key
&& let Some((pb, _)) = self.file_progress_bars.get(&key)
{
pb.set_style(
ProgressStyle::with_template( if pb.position() != 0 {
"{msg:>12.bold} downloaded {total_bytes} in {elapsed} and installing {spinner:.green}"
} else {
"{msg:>12.bold} component already downloaded and installing {spinner:.green}"
}
)
.unwrap()
.tick_chars(r"|/-\ "),
);
pb.enable_steady_tick(Duration::from_millis(100));
}
}

/// Notifies self that the component has been installed.
pub(crate) fn component_installed(&mut self, component: &str) {
let key = self
.file_progress_bars
.keys()
.find(|comp| comp.contains(component))
.cloned();
if let Some(key) = key
&& let Some((pb, _)) = self.file_progress_bars.get(&key)
{
pb.set_style(
ProgressStyle::with_template(if pb.position() != 0 {
"{msg:>12.bold} downloaded {total_bytes} and installed"
} else {
"{msg:>12.bold} component already downloaded and installed"
})
.unwrap(),
);
pb.finish();
}
}
}
Loading
Loading