summaryrefslogtreecommitdiff
path: root/cli/util
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-08-14 12:04:07 +0100
committerGitHub <noreply@github.com>2024-08-14 13:04:07 +0200
commitb325bf0a35baea1275f3be89506e34040bf35b21 (patch)
tree70708a25471f18b9ce0c2d83d76ca1b1d0fd60e4 /cli/util
parent2f82873a88cbaea4ebe8e39b5aa7b57ed867512e (diff)
feat(clean): add progress bar (#25026)
Closes https://github.com/denoland/deno/issues/25020
Diffstat (limited to 'cli/util')
-rw-r--r--cli/util/progress_bar/mod.rs17
-rw-r--r--cli/util/progress_bar/renderer.rs23
2 files changed, 31 insertions, 9 deletions
diff --git a/cli/util/progress_bar/mod.rs b/cli/util/progress_bar/mod.rs
index 91bf4950f..85be056d8 100644
--- a/cli/util/progress_bar/mod.rs
+++ b/cli/util/progress_bar/mod.rs
@@ -28,6 +28,7 @@ pub enum ProgressMessagePrompt {
Download,
Blocking,
Initialize,
+ Cleaning,
}
impl ProgressMessagePrompt {
@@ -38,6 +39,7 @@ impl ProgressMessagePrompt {
ProgressMessagePrompt::Initialize => {
colors::green("Initialize").to_string()
}
+ ProgressMessagePrompt::Cleaning => colors::green("Cleaning").to_string(),
}
}
}
@@ -71,7 +73,13 @@ impl UpdateGuard {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ProgressBarStyle {
+ /// Shows a progress bar with human readable download size
DownloadBars,
+
+ /// Shows a progress bar with numeric progres count
+ ProgressBars,
+
+ /// Shows a list of currently downloaded files.
TextOnly,
}
@@ -270,7 +278,14 @@ impl ProgressBar {
Self {
inner: ProgressBarInner::new(match style {
ProgressBarStyle::DownloadBars => {
- Arc::new(renderer::BarProgressBarRenderer)
+ Arc::new(renderer::BarProgressBarRenderer {
+ display_human_download_size: true,
+ })
+ }
+ ProgressBarStyle::ProgressBars => {
+ Arc::new(renderer::BarProgressBarRenderer {
+ display_human_download_size: false,
+ })
}
ProgressBarStyle::TextOnly => {
Arc::new(renderer::TextOnlyProgressBarRenderer::default())
diff --git a/cli/util/progress_bar/renderer.rs b/cli/util/progress_bar/renderer.rs
index 64d533979..a83ceb333 100644
--- a/cli/util/progress_bar/renderer.rs
+++ b/cli/util/progress_bar/renderer.rs
@@ -34,7 +34,9 @@ pub trait ProgressBarRenderer: Send + Sync + std::fmt::Debug {
/// Indicatif style progress bar.
#[derive(Debug)]
-pub struct BarProgressBarRenderer;
+pub struct BarProgressBarRenderer {
+ pub display_human_download_size: bool,
+}
impl ProgressBarRenderer for BarProgressBarRenderer {
fn render(&self, data: ProgressData) -> String {
@@ -48,13 +50,16 @@ impl ProgressBarRenderer for BarProgressBarRenderer {
if total_size == 0 {
(String::new(), 0)
} else {
- let total_size_str = human_download_size(total_size, total_size);
- (
- format!(
- " {}/{}",
+ let (pos_str, total_size_str) = if self.display_human_download_size {
+ (
human_download_size(pos, total_size),
- total_size_str,
- ),
+ human_download_size(total_size, total_size),
+ )
+ } else {
+ (pos.to_string(), total_size.to_string())
+ };
+ (
+ format!(" {}/{}", pos_str, total_size_str,),
2 + total_size_str.len() * 2,
)
}
@@ -244,7 +249,9 @@ mod test {
#[test]
fn should_render_bar_progress() {
- let renderer = BarProgressBarRenderer;
+ let renderer = BarProgressBarRenderer {
+ display_human_download_size: true,
+ };
let mut data = ProgressData {
display_entries: vec![ProgressDataDisplayEntry {
prompt: ProgressMessagePrompt::Download,