Skip to content

Commit

Permalink
One place to define progress bar style
Browse files Browse the repository at this point in the history
Also no right-side character for no-colour terminals
  • Loading branch information
christiangnrd committed Oct 15, 2024
1 parent 38780d1 commit 350f909
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::utils::is_valid_julia_path;
use anyhow::{anyhow, bail, Context, Result};
use bstr::ByteSlice;
use bstr::ByteVec;
use console::style;
use console::{colors_enabled, style};
#[cfg(not(target_os = "freebsd"))]
use flate2::read::GzDecoder;
use indicatif::{ProgressBar, ProgressStyle};
Expand Down Expand Up @@ -88,6 +88,19 @@ where
Ok(())
}

fn bar_style() -> ProgressStyle {
let pchars = if colors_enabled() {
"━╸━"
} else {
"━╸ "
};

ProgressStyle::default_bar()
.template("{prefix:.cyan.bold}: {bar:.cyan/black.bright} {bytes}/{total_bytes} eta: {eta}")
.unwrap()
.progress_chars(pchars)
}

#[cfg(not(windows))]
pub fn download_extract_sans_parent(
url: &str,
Expand All @@ -106,14 +119,7 @@ pub fn download_extract_sans_parent(
};

pb.set_prefix(" Downloading");
pb.set_style(
ProgressStyle::default_bar()
.template(
"{prefix:.cyan.bold}: {bar:.cyan/black.bright} {bytes}/{total_bytes} eta: {eta}",
)
.unwrap()
.progress_chars("━╸━"),
);
pb.set_style(bar_style());

let last_modified = match response
.headers()
Expand Down Expand Up @@ -207,12 +213,7 @@ pub fn download_extract_sans_parent(
};

pb.set_prefix(" Downloading");
pb.set_style(
ProgressStyle::default_bar()
.template("{prefix:.cyan.bold}: {bar:.cyan/white} {bytes}/{total_bytes} eta: {eta}")
.unwrap()
.progress_chars("━╸━"),
);
pb.set_style(bar_style());

let response_with_pb = pb.wrap_read(DataReaderWrap(reader));

Expand Down

0 comments on commit 350f909

Please # to comment.