From bdd30e7ca2d98bc181d803f3b18448202c2993c8 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Mon, 4 Mar 2024 14:20:09 -0600 Subject: [PATCH] feat(config): Allow overriding unicode detection --- src/cargo/core/shell.rs | 13 +++++++++++++ src/cargo/util/context/mod.rs | 4 ++++ src/doc/src/reference/config.md | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index 43c6580c6455..cf890321aa73 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -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, .. diff --git a/src/cargo/util/context/mod.rs b/src/cargo/util/context/mod.rs index 3fc91dd1ef4b..274a3a89af91 100644 --- a/src/cargo/util/context/mod.rs +++ b/src/cargo/util/context/mod.rs @@ -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(); @@ -2646,6 +2649,7 @@ pub struct TermConfig { pub quiet: Option, pub color: Option, pub hyperlinks: Option, + pub unicode: Option, #[serde(default)] #[serde(deserialize_with = "progress_or_string")] pub progress: Option, diff --git a/src/doc/src/reference/config.md b/src/doc/src/reference/config.md index 83962919dada..6b95e621c25a 100644 --- a/src/doc/src/reference/config.md +++ b/src/doc/src/reference/config.md @@ -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 ``` @@ -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"