Skip to content

Commit bdd30e7

Browse files
committed
feat(config): Allow overriding unicode detection
1 parent 2f7671b commit bdd30e7

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/cargo/core/shell.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,19 @@ impl Shell {
251251
Ok(())
252252
}
253253

254+
pub fn set_unicode(&mut self, yes: bool) -> CargoResult<()> {
255+
if let ShellOut::Stream {
256+
ref mut stdout_unicode,
257+
ref mut stderr_unicode,
258+
..
259+
} = self.output
260+
{
261+
*stdout_unicode = yes;
262+
*stderr_unicode = yes;
263+
}
264+
Ok(())
265+
}
266+
254267
pub fn set_hyperlinks(&mut self, yes: bool) -> CargoResult<()> {
255268
if let ShellOut::Stream {
256269
ref mut hyperlinks, ..

src/cargo/util/context/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,9 @@ impl GlobalContext {
10491049
if let Some(hyperlinks) = term.hyperlinks {
10501050
self.shell().set_hyperlinks(hyperlinks)?;
10511051
}
1052+
if let Some(unicode) = term.unicode {
1053+
self.shell().set_unicode(unicode)?;
1054+
}
10521055

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

@@ -2646,6 +2649,7 @@ pub struct TermConfig {
26462649
pub quiet: Option<bool>,
26472650
pub color: Option<String>,
26482651
pub hyperlinks: Option<bool>,
2652+
pub unicode: Option<bool>,
26492653
#[serde(default)]
26502654
#[serde(deserialize_with = "progress_or_string")]
26512655
pub progress: Option<ProgressConfig>,

src/doc/src/reference/config.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ quiet = false # whether cargo output is quiet
182182
verbose = false # whether cargo provides verbose output
183183
color = 'auto' # whether cargo colorizes output
184184
hyperlinks = true # whether cargo inserts links into output
185+
unicode = true # whether cargo can render output using non-ASCII unicode characters
185186
progress.when = 'auto' # whether cargo shows progress bar
186187
progress.width = 80 # width of progress bar
187188
```
@@ -1298,6 +1299,13 @@ Can be overridden with the `--color` command-line option.
12981299

12991300
Controls whether or not hyperlinks are used in the terminal.
13001301

1302+
#### `term.unicode`
1303+
* Type: bool
1304+
* Default: auto-detect
1305+
* Environment: `CARGO_TERM_UNICODE`
1306+
1307+
Control whether output can be rendered using non-ASCII unicode characters.
1308+
13011309
#### `term.progress.when`
13021310
* Type: string
13031311
* Default: "auto"

0 commit comments

Comments
 (0)