From 24f5d0d879ba9893ab53f84ebc92f90067b4efa5 Mon Sep 17 00:00:00 2001 From: Francisco Gouveia Date: Tue, 8 Jul 2025 22:40:55 +0100 Subject: [PATCH 1/2] feat(updates): introduce `RUSTUP_TERM_PROGRESS_WHEN` to toggle the progress bars --- doc/user-guide/src/environment-variables.md | 3 +++ src/cli/rustup_mode.rs | 18 +++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/doc/user-guide/src/environment-variables.md b/doc/user-guide/src/environment-variables.md index e51d42fb9f..7fbb71ed37 100644 --- a/doc/user-guide/src/environment-variables.md +++ b/doc/user-guide/src/environment-variables.md @@ -61,6 +61,9 @@ symlink proxies and instead always use hardlinks. If you find this fixes a problem, then please report the issue on the [rustup issue tracker]. +- `RUSTUP_TERM_PROGRESS_WHEN` (defaults: `auto`). Controls whether progress bars are shown or not. + Set to `always` to always enable progress bars, and to `never` to disable them. + [directive syntax]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives [dc]: https://docs.docker.com/storage/storagedriver/overlayfs-driver/#modifying-files-or-directories [override]: overrides.md diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index e72f5203b5..83cf22b4f7 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -805,11 +805,15 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result 0 { - let multi_progress_bars = if is_a_tty { - MultiProgress::with_draw_target(ProgressDrawTarget::term_like(Box::new(t))) - } else { - MultiProgress::with_draw_target(ProgressDrawTarget::hidden()) - }; + let multi_progress_bars = + MultiProgress::with_draw_target(match cfg.process.var("RUSTUP_TERM_PROGRESS_WHEN") { + Ok(s) if s.eq_ignore_ascii_case("always") => { + ProgressDrawTarget::term_like(Box::new(t)) + } + Ok(s) if s.eq_ignore_ascii_case("never") => ProgressDrawTarget::hidden(), + _ if is_a_tty => ProgressDrawTarget::term_like(Box::new(t)), + _ => ProgressDrawTarget::hidden(), + }); let channels = tokio_stream::iter(channels.into_iter()).map(|(name, distributable)| { let pb = multi_progress_bars.add(ProgressBar::new(1)); pb.set_style( @@ -869,7 +873,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result>() @@ -884,7 +888,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result Date: Tue, 8 Jul 2025 23:11:13 +0100 Subject: [PATCH 2/2] feat(updates): introduce `RUSTUP_TERM_WIDTH` to override terminal width --- doc/user-guide/src/environment-variables.md | 2 ++ src/process/terminalsource.rs | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/user-guide/src/environment-variables.md b/doc/user-guide/src/environment-variables.md index 7fbb71ed37..135be3d105 100644 --- a/doc/user-guide/src/environment-variables.md +++ b/doc/user-guide/src/environment-variables.md @@ -64,6 +64,8 @@ - `RUSTUP_TERM_PROGRESS_WHEN` (defaults: `auto`). Controls whether progress bars are shown or not. Set to `always` to always enable progress bars, and to `never` to disable them. +- `RUSTUP_TERM_WIDTH` (default: none). Allows to override the terminal width for progress bars. + [directive syntax]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives [dc]: https://docs.docker.com/storage/storagedriver/overlayfs-driver/#modifying-files-or-directories [override]: overrides.md diff --git a/src/process/terminalsource.rs b/src/process/terminalsource.rs index 29b90c4d33..4e841060e3 100644 --- a/src/process/terminalsource.rs +++ b/src/process/terminalsource.rs @@ -3,6 +3,7 @@ use indicatif::TermLike; use std::{ io::{self, Write}, mem::MaybeUninit, + num::NonZero, ops::DerefMut, ptr::addr_of_mut, sync::{Arc, Mutex, MutexGuard}, @@ -57,6 +58,7 @@ pub struct ColorableTerminal { inner: Arc>, is_a_tty: bool, color_choice: ColorChoice, + width: Option>, } /// Internal state for ColorableTerminal @@ -107,10 +109,15 @@ impl ColorableTerminal { #[cfg(all(test, feature = "test"))] StreamSelector::TestTtyWriter(w) => TerminalInner::TestWriter(w, choice), }; + let width = process + .var("RUSTUP_TERM_WIDTH") + .ok() + .and_then(|s| s.parse::>().ok()); ColorableTerminal { inner: Arc::new(Mutex::new(inner)), is_a_tty, color_choice: choice, + width, } } @@ -240,7 +247,10 @@ impl io::Write for ColorableTerminalLocked { impl TermLike for ColorableTerminal { fn width(&self) -> u16 { - Term::stdout().size().1 + match self.width { + Some(n) => n.get(), + None => Term::stdout().size().1, + } } fn move_cursor_up(&self, n: usize) -> io::Result<()> {