feat: display packages in progress bars

This commit is contained in:
daimond113 2024-11-10 18:08:59 +01:00
parent f7808e452d
commit 1369fe990b
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
5 changed files with 24 additions and 14 deletions

View file

@ -211,8 +211,9 @@ impl InstallCommand {
graph.values().map(|versions| versions.len() as u64).sum(), graph.values().map(|versions| versions.len() as u64).sum(),
rx, rx,
&multi, &multi,
format!("{} 📥 downloading dependencies", job(3)), format!("{} 📥 ", job(3)),
format!("{} 📥 downloaded dependencies", job(3)), "downloading dependencies".to_string(),
"downloaded dependencies".to_string(),
) )
.await?; .await?;
@ -250,8 +251,9 @@ impl InstallCommand {
manifest.patches.values().map(|v| v.len() as u64).sum(), manifest.patches.values().map(|v| v.len() as u64).sum(),
rx, rx,
&multi, &multi,
format!("{} 🩹 applying patches", job(4)), format!("{} 🩹 ", job(4)),
format!("{} 🩹 applied patches", job(4)), "applying patches".to_string(),
"applied patches".to_string(),
) )
.await?; .await?;
} }

View file

@ -54,8 +54,9 @@ impl UpdateCommand {
graph.values().map(|versions| versions.len() as u64).sum(), graph.values().map(|versions| versions.len() as u64).sum(),
rx, rx,
&multi, &multi,
"📥 downloading dependencies".to_string(), "📥 ".to_string(),
"📥 downloaded dependencies".to_string(), "downloading dependencies".to_string(),
"downloaded dependencies".to_string(),
) )
.await?; .await?;

View file

@ -192,8 +192,9 @@ pub fn parse_gix_url(s: &str) -> Result<gix::Url, gix::url::parse::Error> {
pub async fn progress_bar<E: std::error::Error + Into<anyhow::Error>>( pub async fn progress_bar<E: std::error::Error + Into<anyhow::Error>>(
len: u64, len: u64,
mut rx: tokio::sync::mpsc::Receiver<Result<(), E>>, mut rx: tokio::sync::mpsc::Receiver<Result<String, E>>,
multi: &MultiProgress, multi: &MultiProgress,
prefix: String,
progress_msg: String, progress_msg: String,
finish_msg: String, finish_msg: String,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
@ -201,8 +202,10 @@ pub async fn progress_bar<E: std::error::Error + Into<anyhow::Error>>(
indicatif::ProgressBar::new(len) indicatif::ProgressBar::new(len)
.with_style( .with_style(
indicatif::ProgressStyle::default_bar() indicatif::ProgressStyle::default_bar()
.template("{msg} {bar:40.208/166} {pos}/{len} {percent}% {elapsed_precise}")?, .template("{prefix}[{elapsed_precise}] {bar:40.208/166} {pos}/{len} {msg}")?
.progress_chars("█▓▒░ "),
) )
.with_prefix(prefix)
.with_message(progress_msg), .with_message(progress_msg),
); );
bar.enable_steady_tick(Duration::from_millis(100)); bar.enable_steady_tick(Duration::from_millis(100));
@ -211,7 +214,9 @@ pub async fn progress_bar<E: std::error::Error + Into<anyhow::Error>>(
bar.inc(1); bar.inc(1);
match result { match result {
Ok(()) => {} Ok(text) => {
bar.set_message(text);
}
Err(e) => return Err(e.into()), Err(e) => return Err(e.into()),
} }
} }

View file

@ -17,7 +17,7 @@ use std::{
type MultithreadedGraph = Arc<Mutex<DownloadedGraph>>; type MultithreadedGraph = Arc<Mutex<DownloadedGraph>>;
type MultithreadDownloadJob = ( type MultithreadDownloadJob = (
tokio::sync::mpsc::Receiver<Result<(), errors::DownloadGraphError>>, tokio::sync::mpsc::Receiver<Result<String, errors::DownloadGraphError>>,
MultithreadedGraph, MultithreadedGraph,
); );
@ -119,6 +119,8 @@ impl Project {
} }
} }
let display_name = format!("{name}@{version_id}");
{ {
let mut downloaded_graph = downloaded_graph.lock().unwrap(); let mut downloaded_graph = downloaded_graph.lock().unwrap();
downloaded_graph downloaded_graph
@ -127,7 +129,7 @@ impl Project {
.insert(version_id, DownloadedDependencyGraphNode { node, target }); .insert(version_id, DownloadedDependencyGraphNode { node, target });
} }
tx.send(Ok(())).await.unwrap(); tx.send(Ok(display_name)).await.unwrap();
}); });
} }
} }

View file

@ -76,7 +76,7 @@ impl Project {
&self, &self,
graph: &DownloadedGraph, graph: &DownloadedGraph,
) -> Result< ) -> Result<
tokio::sync::mpsc::Receiver<Result<(), errors::ApplyPatchesError>>, tokio::sync::mpsc::Receiver<Result<String, errors::ApplyPatchesError>>,
errors::ApplyPatchesError, errors::ApplyPatchesError,
> { > {
let manifest = self.deser_manifest().await?; let manifest = self.deser_manifest().await?;
@ -103,7 +103,7 @@ impl Project {
log::warn!( log::warn!(
"patch for {name}@{version_id} not applied because it is not in the graph" "patch for {name}@{version_id} not applied because it is not in the graph"
); );
tx.send(Ok(())).await.unwrap(); tx.send(Ok(format!("{name}@{version_id}"))).await.unwrap();
continue; continue;
}; };
@ -212,7 +212,7 @@ impl Project {
return; return;
} }
tx.send(Ok(())).await.unwrap(); tx.send(Ok(format!("{name}@{version_id}"))).await.unwrap();
}); });
} }
} }