Skip to content
Closed
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
21 changes: 21 additions & 0 deletions src/cargo/core/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -78,6 +79,7 @@ impl Shell {
},
verbosity: Verbosity::Verbose,
needs_clear: false,
force_progress: false,
}
}

Expand All @@ -87,6 +89,7 @@ impl Shell {
err: ShellOut::Write(out),
verbosity: Verbosity::Verbose,
needs_clear: false,
force_progress: false,
}
}

Expand Down Expand Up @@ -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<String>) -> 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 {
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ impl Config {
struct TermConfig {
verbose: Option<bool>,
color: Option<String>,
progress: Option<String>,
}

// Ignore errors in the configuration files.
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/cargo/util/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down