diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2020-11-11 16:44:02 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2020-11-17 10:33:14 +0100 |
| commit | 32d64edcf9d31ded609ab70b31bd3779d6f85ec1 (patch) | |
| tree | 685f3663dfc9d72589f64553192033702657051c /compiler/rustc_errors/src | |
| parent | 704001b929b9e93f67d4affa9cae27bdb64d1aeb (diff) | |
| download | rust-32d64edcf9d31ded609ab70b31bd3779d6f85ec1.tar.gz rust-32d64edcf9d31ded609ab70b31bd3779d6f85ec1.zip | |
Simplfy color availability check
Diffstat (limited to 'compiler/rustc_errors/src')
| -rw-r--r-- | compiler/rustc_errors/src/emitter.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 302713a21db..32104e6f00d 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -200,6 +200,11 @@ pub trait Emitter { true } + /// Checks if we can use colors in the current output stream. + fn supports_color(&self) -> bool { + false + } + fn source_map(&self) -> Option<&Lrc<SourceMap>>; /// Formats the substitutions of the primary_span @@ -504,6 +509,10 @@ impl Emitter for EmitterWriter { fn should_show_explain(&self) -> bool { !self.short_message } + + fn supports_color(&self) -> bool { + self.dst.supports_color() + } } /// An emitter that does nothing when emitting a diagnostic. @@ -2057,6 +2066,14 @@ impl Destination { Destination::Raw(ref mut t, true) => WritableDst::ColoredRaw(Ansi::new(t)), } } + + fn supports_color(&self) -> bool { + match *self { + Self::Terminal(ref stream) => stream.supports_color(), + Self::Buffered(ref buffer) => buffer.buffer().supports_color(), + Self::Raw(_, supports_color) => supports_color, + } + } } impl<'a> WritableDst<'a> { |
