Skip to content

Commit 388cf4e

Browse files
committed
syntax: Only use color output if the terminal supports it
1 parent 869a895 commit 388cf4e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/libsyntax/errors/emitter.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,14 @@ enum Destination {
683683
impl Destination {
684684
fn from_stderr() -> Destination {
685685
match term::stderr() {
686-
Some(t) => Terminal(t),
687-
None => Raw(Box::new(io::stderr())),
686+
Some(t) => {
687+
if t.supports_color() {
688+
Terminal(t)
689+
} else {
690+
Raw(Box::new(io::stderr()))
691+
}
692+
}
693+
None => Raw(Box::new(io::stderr())),
688694
}
689695
}
690696

src/libterm/terminfo/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ impl<T: Write + Send> Terminal for TerminfoTerminal<T> {
230230
("sgr", &[Param::Number(0)]),
231231
("op", &[])]
232232
.iter()
233-
.filter_map(|&(cap, params)| self.ti.strings.get(cap).map(|c| (c, params)))
233+
.filter_map(|&(cap, params)| {
234+
self.ti.strings.get(cap).map(|c| (c, params))
235+
})
234236
.next() {
235237
Some((op, params)) => {
236238
match expand(op, params, &mut Variables::new()) {

0 commit comments

Comments
 (0)