Simplfy color availability check
This commit is contained in:
parent
704001b929
commit
32d64edcf9
6 changed files with 41 additions and 45 deletions
|
@ -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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue