Skip to content

Commit

Permalink
Rollup merge of rust-lang#55788 - alexcrichton:wincolors, r=petrochenkov
Browse files Browse the repository at this point in the history
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 rust-lang#55769
  • Loading branch information
Mark-Simulacrum committed Nov 9, 2018
2 parents 667904f + 255cc1a commit d293d1e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d293d1e

Please sign in to comment.