From: Andreas Tolfsen Date: Mon, 18 Dec 2017 16:01:30 +0000 (+0000) Subject: util/progress: no progress reporting in dumb terminals X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~4^2~16^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=274f9ce40d300be5ee898809bfeee027a31afc48;p=cargo.git 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. --- diff --git a/src/cargo/util/progress.rs b/src/cargo/util/progress.rs index 21cf0acfa..6c3addade 100644 --- a/src/cargo/util/progress.rs +++ b/src/cargo/util/progress.rs @@ -1,4 +1,5 @@ use std::cmp; +use std::env; use std::iter; use std::time::{Instant, Duration}; @@ -20,8 +21,12 @@ struct State<'cfg> { impl<'cfg> Progress<'cfg> { pub fn new(name: &str, cfg: &'cfg Config) -> Progress<'cfg> { - // no progress if `-q` is passed as, well, we're supposed to be quiet - if cfg.shell().verbosity() == Verbosity::Quiet { + // report no progress when -q (for quiet) or TERM=dumb are set + let dumb = match env::var("TERM") { + Ok(term) => term == "dumb", + Err(_) => false, + }; + if cfg.shell().verbosity() == Verbosity::Quiet || dumb { return Progress { state: None } }