diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index eae8a70cc8d..350d7f18dd8 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -25,6 +25,7 @@ pub struct Shell { /// Flag that indicates the current line needs to be cleared before /// printing. Used when a progress bar is currently displayed. needs_clear: bool, + force_progress: bool, } impl fmt::Debug for Shell { @@ -78,6 +79,7 @@ impl Shell { }, verbosity: Verbosity::Verbose, needs_clear: false, + force_progress: false, } } @@ -87,6 +89,7 @@ impl Shell { err: ShellOut::Write(out), verbosity: Verbosity::Verbose, needs_clear: false, + force_progress: false, } } @@ -279,6 +282,24 @@ impl Shell { } } + /// Updates the progress choice (always or auto) from a string.. + pub fn set_progress_choice(&mut self, progress: Option) -> CargoResult<()> { + self.force_progress = match progress.as_deref() { + Some("always") => true, + Some("auto") | None => false, + Some(arg) => anyhow::bail!( + "value for term.progress must be auto or always, \ + but found `{}`", + arg + ), + }; + Ok(()) + } + + pub fn progress_choice(&self) -> bool { + self.force_progress + } + /// Whether the shell supports color. pub fn supports_color(&self) -> bool { match &self.err { diff --git a/src/cargo/util/config/mod.rs b/src/cargo/util/config/mod.rs index 260d011c851..488e05700b5 100644 --- a/src/cargo/util/config/mod.rs +++ b/src/cargo/util/config/mod.rs @@ -698,6 +698,7 @@ impl Config { struct TermConfig { verbose: Option, color: Option, + progress: Option, } // Ignore errors in the configuration files. @@ -728,6 +729,7 @@ impl Config { self.shell().set_verbosity(verbosity); self.shell().set_color_choice(color)?; + self.shell().set_progress_choice(term.progress)?; self.extra_verbose = extra_verbose; self.frozen = frozen; self.locked = locked; diff --git a/src/cargo/util/progress.rs b/src/cargo/util/progress.rs index d62600379cb..4e550488e4b 100644 --- a/src/cargo/util/progress.rs +++ b/src/cargo/util/progress.rs @@ -49,8 +49,14 @@ impl<'cfg> Progress<'cfg> { return Progress { state: None }; } + let err_width = if cfg.shell().progress_choice() { + Some(cfg.shell().err_width().unwrap_or(80)) + } else { + cfg.shell().err_width() + }; + Progress { - state: cfg.shell().err_width().map(|n| State { + state: err_width.map(|n| State { config: cfg, format: Format { style,