about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-11-08 07:49:28 -0800
committerAlex Crichton <alex@alexcrichton.com>2018-11-08 07:53:03 -0800
commit255cc1aed33442567c29c95fa445a534575e925c (patch)
treef3e843496ae2cf9295cca99601bcc418f2355665 /src
parent8315b11b6352cbd91ee096571c31ae7d3ac9613d (diff)
downloadrust-255cc1aed33442567c29c95fa445a534575e925c.tar.gz
rust-255cc1aed33442567c29c95fa445a534575e925c.zip
rustc: Request ansi colors if stderr isn't a tty
Currently Cargo will always capture the output of rustc meaning that
rustc is never hooked up to a tty. To retain colors Cargo uses the
`fwdansi` crate to ensure that ansi color codes are translated to
windows terminal methods (and ansi codes otherwise just go their natural
route on Unix).

Cargo passes `--color always` to rustc to ensure that using a pipe
doesn't trick it into not emitting colors at all. It turns out, however,
that `--color always` ends up still accidentally using the native shell
api on native windows shells.

The fix here is to instead pass `AlwaysAnsi` to `termcolor` instead of
`Always`, ensuring that when `--color always` is passed to rustc and its
output isn't a terminal, we're always generating ansi colors regardless
of the platform.

Closes #55769
Diffstat (limited to 'src')
-rw-r--r--src/librustc_errors/emitter.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs
index 720e8def5ab..7e69e98071d 100644
--- a/src/librustc_errors/emitter.rs
+++ b/src/librustc_errors/emitter.rs
@@ -108,7 +108,13 @@ pub enum ColorConfig {
 impl ColorConfig {
     fn to_color_choice(&self) -> ColorChoice {
         match *self {
-            ColorConfig::Always => ColorChoice::Always,
+            ColorConfig::Always => {
+                if atty::is(atty::Stream::Stderr) {
+                    ColorChoice::Always
+                } else {
+                    ColorChoice::AlwaysAnsi
+                }
+            }
             ColorConfig::Never => ColorChoice::Never,
             ColorConfig::Auto if atty::is(atty::Stream::Stderr) => {
                 ColorChoice::Auto