Skip to content

Introduce RUSTUP_TERM_WIDTH and RUSTUP_TERM_PROGRESS_WHEN #4406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/user-guide/src/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
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.

- `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
Expand Down
18 changes: 11 additions & 7 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,11 +805,15 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
// Ensure that `.buffered()` is never called with 0 as this will cause a hang.
// See: https://github.com/rust-lang/futures-rs/pull/1194#discussion_r209501774
if num_channels > 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(
Expand Down Expand Up @@ -869,7 +873,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
// If we are running in a TTY, we can use `buffer_unordered` since
// displaying the output in the correct order is already handled by
// `indicatif`.
let channels = if is_a_tty {
let channels = if !multi_progress_bars.is_hidden() {
channels
.buffer_unordered(num_channels)
.collect::<Vec<_>>()
Expand All @@ -884,7 +888,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
if update_a {
update_available = true;
}
if !is_a_tty {
if multi_progress_bars.is_hidden() {
writeln!(t.lock(), "{message}")?;
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/process/terminalsource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -57,6 +58,7 @@ pub struct ColorableTerminal {
inner: Arc<Mutex<TerminalInner>>,
is_a_tty: bool,
color_choice: ColorChoice,
width: Option<NonZero<u16>>,
}

/// Internal state for ColorableTerminal
Expand Down Expand Up @@ -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::<NonZero<u16>>().ok());
ColorableTerminal {
inner: Arc::new(Mutex::new(inner)),
is_a_tty,
color_choice: choice,
width,
}
}

Expand Down Expand Up @@ -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<()> {
Expand Down