Skip to content

Commit 576ac63

Browse files
committed
Auto merge of #4832 - andreastt:dumb_terminal_progress, r=alexcrichton
util/progress: no progress reporting in dumb terminals cargo should not assume that all terminals have direct access to the terminal. Dumb terminals are those that can interpret only a limited number of control codes (CR, LF, &c.) and the escape codes used by the progress bar breaks output in these by asserting control over the cursor position to draw a bar. A dumb terminal is identified by the TERM output variable being set to "dumb". This adds a direct check for this in src/cargo/util/progress.rs because TERM=dumb does not imply the same as the -q flag.
2 parents 4bbfc70 + 274f9ce commit 576ac63

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/cargo/util/progress.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::cmp;
2+
use std::env;
23
use std::iter;
34
use std::time::{Instant, Duration};
45

@@ -20,8 +21,12 @@ struct State<'cfg> {
2021

2122
impl<'cfg> Progress<'cfg> {
2223
pub fn new(name: &str, cfg: &'cfg Config) -> Progress<'cfg> {
23-
// no progress if `-q` is passed as, well, we're supposed to be quiet
24-
if cfg.shell().verbosity() == Verbosity::Quiet {
24+
// report no progress when -q (for quiet) or TERM=dumb are set
25+
let dumb = match env::var("TERM") {
26+
Ok(term) => term == "dumb",
27+
Err(_) => false,
28+
};
29+
if cfg.shell().verbosity() == Verbosity::Quiet || dumb {
2530
return Progress { state: None }
2631
}
2732

0 commit comments

Comments
 (0)