Skip to content

Commit

Permalink
feat(config): Allow overriding unicode detection
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Mar 4, 2024
1 parent 2f7671b commit bdd30e7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/cargo/core/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,19 @@ impl Shell {
Ok(())
}

pub fn set_unicode(&mut self, yes: bool) -> CargoResult<()> {
if let ShellOut::Stream {
ref mut stdout_unicode,
ref mut stderr_unicode,
..
} = self.output
{
*stdout_unicode = yes;
*stderr_unicode = yes;
}
Ok(())
}

pub fn set_hyperlinks(&mut self, yes: bool) -> CargoResult<()> {
if let ShellOut::Stream {
ref mut hyperlinks, ..
Expand Down
4 changes: 4 additions & 0 deletions src/cargo/util/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,9 @@ impl GlobalContext {
if let Some(hyperlinks) = term.hyperlinks {
self.shell().set_hyperlinks(hyperlinks)?;
}
if let Some(unicode) = term.unicode {
self.shell().set_unicode(unicode)?;
}

self.progress_config = term.progress.unwrap_or_default();

Expand Down Expand Up @@ -2646,6 +2649,7 @@ pub struct TermConfig {
pub quiet: Option<bool>,
pub color: Option<String>,
pub hyperlinks: Option<bool>,
pub unicode: Option<bool>,
#[serde(default)]
#[serde(deserialize_with = "progress_or_string")]
pub progress: Option<ProgressConfig>,
Expand Down
8 changes: 8 additions & 0 deletions src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ quiet = false # whether cargo output is quiet
verbose = false # whether cargo provides verbose output
color = 'auto' # whether cargo colorizes output
hyperlinks = true # whether cargo inserts links into output
unicode = true # whether cargo can render output using non-ASCII unicode characters
progress.when = 'auto' # whether cargo shows progress bar
progress.width = 80 # width of progress bar
```
Expand Down Expand Up @@ -1298,6 +1299,13 @@ Can be overridden with the `--color` command-line option.

Controls whether or not hyperlinks are used in the terminal.

#### `term.unicode`
* Type: bool
* Default: auto-detect
* Environment: `CARGO_TERM_UNICODE`

Control whether output can be rendered using non-ASCII unicode characters.

#### `term.progress.when`
* Type: string
* Default: "auto"
Expand Down

0 comments on commit bdd30e7

Please sign in to comment.