]> git.lizzy.rs Git - rust.git/commitdiff
Check term supports colour before printing fancy diffs
authorKamal Marhubi <kamal@marhubi.com>
Fri, 26 Aug 2016 21:08:47 +0000 (17:08 -0400)
committerKamal Marhubi <kamal@marhubi.com>
Fri, 26 Aug 2016 21:08:47 +0000 (17:08 -0400)
For a terminal like DUMB, we were still attempting to print colourful
diffs, which failed with a `NotSupported` error.

Fixes #1140

src/rustfmt_diff.rs

index d5129bd1bca5bbf9df79846368369bea90d357cd..23cb3f21bf2d4dd743f71fe0129f86401cc2cfcb 100644 (file)
@@ -89,7 +89,9 @@ pub fn print_diff<F>(diff: Vec<Mismatch>, get_section_title: F)
     where F: Fn(u32) -> String
 {
     match term::stdout() {
-        Some(_) if isatty() => print_diff_fancy(diff, get_section_title, term::stdout().unwrap()),
+        Some(ref t) if isatty() && t.supports_color() => {
+            print_diff_fancy(diff, get_section_title, term::stdout().unwrap())
+        }
         _ => print_diff_basic(diff, get_section_title),
     }