Skip to content

Commit 350f909

Browse files
committed
One place to define progress bar style
Also no right-side character for no-colour terminals
1 parent 38780d1 commit 350f909

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
@@ -15,7 +15,7 @@ use crate::utils::is_valid_julia_path;
1515
use anyhow::{anyhow, bail, Context, Result};
1616
use bstr::ByteSlice;
1717
use bstr::ByteVec;
18-
use console::style;
18+
use console::{colors_enabled, style};
1919
#[cfg(not(target_os = "freebsd"))]
2020
use flate2::read::GzDecoder;
2121
use indicatif::{ProgressBar, ProgressStyle};
@@ -88,6 +88,19 @@ where
8888
Ok(())
8989
}
9090

91+
fn bar_style() -> ProgressStyle {
92+
let pchars = if colors_enabled() {
93+
"━╸━"
94+
} else {
95+
"━╸ "
96+
};
97+
98+
ProgressStyle::default_bar()
99+
.template("{prefix:.cyan.bold}: {bar:.cyan/black.bright} {bytes}/{total_bytes} eta: {eta}")
100+
.unwrap()
101+
.progress_chars(pchars)
102+
}
103+
91104
#[cfg(not(windows))]
92105
pub fn download_extract_sans_parent(
93106
url: &str,
@@ -106,14 +119,7 @@ pub fn download_extract_sans_parent(
106119
};
107120

108121
pb.set_prefix(" Downloading");
109-
pb.set_style(
110-
ProgressStyle::default_bar()
111-
.template(
112-
"{prefix:.cyan.bold}: {bar:.cyan/black.bright} {bytes}/{total_bytes} eta: {eta}",
113-
)
114-
.unwrap()
115-
.progress_chars("━╸━"),
116-
);
122+
pb.set_style(bar_style());
117123

118124
let last_modified = match response
119125
.headers()
@@ -207,12 +213,7 @@ pub fn download_extract_sans_parent(
207213
};
208214

209215
pb.set_prefix(" Downloading");
210-
pb.set_style(
211-
ProgressStyle::default_bar()
212-
.template("{prefix:.cyan.bold}: {bar:.cyan/white} {bytes}/{total_bytes} eta: {eta}")
213-
.unwrap()
214-
.progress_chars("━╸━"),
215-
);
216+
pb.set_style(bar_style());
216217

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

0 commit comments

Comments
 (0)