Skip to content

Commit a2cf5c4

Browse files
FranciscoTGouveiarami3l
authored andcommitted
feat(updates): introduce RUSTUP_TERM_WIDTH to override terminal width
1 parent 3480065 commit a2cf5c4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
- `RUSTUP_TERM_PROGRESS_WHEN` (defaults: `auto`). Controls whether progress bars are shown or not.
6565
Set to `always` to always enable progress bars, and to `never` to disable them.
6666

67+
- `RUSTUP_TERM_WIDTH` (default: none). Allows to override the terminal width for progress bars.
68+
6769
[directive syntax]: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives
6870
[dc]: https://docs.docker.com/storage/storagedriver/overlayfs-driver/#modifying-files-or-directories
6971
[override]: overrides.md

src/process/terminalsource.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use indicatif::TermLike;
33
use std::{
44
io::{self, Write},
55
mem::MaybeUninit,
6+
num::NonZero,
67
ops::DerefMut,
78
ptr::addr_of_mut,
89
sync::{Arc, Mutex, MutexGuard},
@@ -57,6 +58,7 @@ pub struct ColorableTerminal {
5758
inner: Arc<Mutex<TerminalInner>>,
5859
is_a_tty: bool,
5960
color_choice: ColorChoice,
61+
width: Option<NonZero<u16>>,
6062
}
6163

6264
/// Internal state for ColorableTerminal
@@ -107,10 +109,15 @@ impl ColorableTerminal {
107109
#[cfg(all(test, feature = "test"))]
108110
StreamSelector::TestTtyWriter(w) => TerminalInner::TestWriter(w, choice),
109111
};
112+
let width = process
113+
.var("RUSTUP_TERM_WIDTH")
114+
.ok()
115+
.and_then(|s| s.parse::<NonZero<u16>>().ok());
110116
ColorableTerminal {
111117
inner: Arc::new(Mutex::new(inner)),
112118
is_a_tty,
113119
color_choice: choice,
120+
width,
114121
}
115122
}
116123

@@ -240,7 +247,10 @@ impl io::Write for ColorableTerminalLocked {
240247

241248
impl TermLike for ColorableTerminal {
242249
fn width(&self) -> u16 {
243-
Term::stdout().size().1
250+
match self.width {
251+
Some(n) => n.get(),
252+
None => Term::stdout().size().1,
253+
}
244254
}
245255

246256
fn move_cursor_up(&self, n: usize) -> io::Result<()> {

0 commit comments

Comments
 (0)