Skip to content

Commit d293d1e

Browse files
Rollup merge of #55788 - alexcrichton:wincolors, r=petrochenkov
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
2 parents 667904f + 255cc1a commit d293d1e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/librustc_errors/emitter.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ pub enum ColorConfig {
108108
impl ColorConfig {
109109
fn to_color_choice(&self) -> ColorChoice {
110110
match *self {
111-
ColorConfig::Always => ColorChoice::Always,
111+
ColorConfig::Always => {
112+
if atty::is(atty::Stream::Stderr) {
113+
ColorChoice::Always
114+
} else {
115+
ColorChoice::AlwaysAnsi
116+
}
117+
}
112118
ColorConfig::Never => ColorChoice::Never,
113119
ColorConfig::Auto if atty::is(atty::Stream::Stderr) => {
114120
ColorChoice::Auto

0 commit comments

Comments
 (0)