Skip to content

Commit 3480065

Browse files
FranciscoTGouveiarami3l
authored andcommitted
feat(updates): introduce RUSTUP_TERM_PROGRESS_WHEN to toggle the progress bars
1 parent 454f062 commit 3480065

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

doc/user-guide/src/environment-variables.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
symlink proxies and instead always use hardlinks. If you find this fixes
6262
a problem, then please report the issue on the [rustup issue tracker].
6363

64+
- `RUSTUP_TERM_PROGRESS_WHEN` (defaults: `auto`). Controls whether progress bars are shown or not.
65+
Set to `always` to always enable progress bars, and to `never` to disable them.
66+
6467
[directive syntax]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives
6568
[dc]: https://docs.docker.com/storage/storagedriver/overlayfs-driver/#modifying-files-or-directories
6669
[override]: overrides.md

src/cli/rustup_mode.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -805,11 +805,15 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
805805
// Ensure that `.buffered()` is never called with 0 as this will cause a hang.
806806
// See: https://github.com/rust-lang/futures-rs/pull/1194#discussion_r209501774
807807
if num_channels > 0 {
808-
let multi_progress_bars = if is_a_tty {
809-
MultiProgress::with_draw_target(ProgressDrawTarget::term_like(Box::new(t)))
810-
} else {
811-
MultiProgress::with_draw_target(ProgressDrawTarget::hidden())
812-
};
808+
let multi_progress_bars =
809+
MultiProgress::with_draw_target(match cfg.process.var("RUSTUP_TERM_PROGRESS_WHEN") {
810+
Ok(s) if s.eq_ignore_ascii_case("always") => {
811+
ProgressDrawTarget::term_like(Box::new(t))
812+
}
813+
Ok(s) if s.eq_ignore_ascii_case("never") => ProgressDrawTarget::hidden(),
814+
_ if is_a_tty => ProgressDrawTarget::term_like(Box::new(t)),
815+
_ => ProgressDrawTarget::hidden(),
816+
});
813817
let channels = tokio_stream::iter(channels.into_iter()).map(|(name, distributable)| {
814818
let pb = multi_progress_bars.add(ProgressBar::new(1));
815819
pb.set_style(
@@ -869,7 +873,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
869873
// If we are running in a TTY, we can use `buffer_unordered` since
870874
// displaying the output in the correct order is already handled by
871875
// `indicatif`.
872-
let channels = if is_a_tty {
876+
let channels = if !multi_progress_bars.is_hidden() {
873877
channels
874878
.buffer_unordered(num_channels)
875879
.collect::<Vec<_>>()
@@ -884,7 +888,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
884888
if update_a {
885889
update_available = true;
886890
}
887-
if !is_a_tty {
891+
if multi_progress_bars.is_hidden() {
888892
writeln!(t.lock(), "{message}")?;
889893
}
890894
}

0 commit comments

Comments
 (0)