Skip to content

Commit a0731bf

Browse files
committed
One place to define progress bar style
Also no right-side character for no-colour terminals
1 parent cde2e76 commit a0731bf

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/operations.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::utils::is_valid_julia_path;
1717
use anyhow::{anyhow, bail, Context, Error, Result};
1818
use bstr::ByteSlice;
1919
use bstr::ByteVec;
20-
use console::style;
20+
use console::{colors_enabled, style};
2121
#[cfg(not(target_os = "freebsd"))]
2222
use flate2::read::GzDecoder;
2323
use indicatif::{ProgressBar, ProgressStyle};
@@ -92,6 +92,19 @@ where
9292
Ok(())
9393
}
9494

95+
fn bar_style() -> ProgressStyle {
96+
let pchars = if colors_enabled() {
97+
"━╸━"
98+
} else {
99+
"━╸ "
100+
};
101+
102+
ProgressStyle::default_bar()
103+
.template("{prefix:.cyan.bold}: {bar:.cyan/black.bright} {bytes}/{total_bytes} eta: {eta}")
104+
.unwrap()
105+
.progress_chars(pchars)
106+
}
107+
95108
#[cfg(not(windows))]
96109
pub fn download_extract_sans_parent(
97110
url: &str,
@@ -110,14 +123,7 @@ pub fn download_extract_sans_parent(
110123
};
111124

112125
pb.set_prefix(" Downloading");
113-
pb.set_style(
114-
ProgressStyle::default_bar()
115-
.template(
116-
"{prefix:.cyan.bold}: {bar:.cyan/black.bright} {bytes}/{total_bytes} eta: {eta}",
117-
)
118-
.unwrap()
119-
.progress_chars("━╸━"),
120-
);
126+
pb.set_style(bar_style());
121127

122128
let last_modified = match response
123129
.headers()
@@ -211,12 +217,7 @@ pub fn download_extract_sans_parent(
211217
};
212218

213219
pb.set_prefix(" Downloading");
214-
pb.set_style(
215-
ProgressStyle::default_bar()
216-
.template("{prefix:.cyan.bold}: {bar:.cyan/white} {bytes}/{total_bytes} eta: {eta}")
217-
.unwrap()
218-
.progress_chars("━╸━"),
219-
);
220+
pb.set_style(bar_style());
220221

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

0 commit comments

Comments
 (0)