]> git.lizzy.rs Git - rust.git/blobdiff - src/rustfmt_diff.rs
Remove BlockIndentStyle::Inherit
[rust.git] / src / rustfmt_diff.rs
index fe521029cb5a75f3d5a1a17769357fd6ba4d5d7d..23cb3f21bf2d4dd743f71fe0129f86401cc2cfcb 100644 (file)
@@ -88,10 +88,30 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma
 pub fn print_diff<F>(diff: Vec<Mismatch>, get_section_title: F)
     where F: Fn(u32) -> String
 {
-    if let Some(t) = term::stdout() {
-        print_diff_fancy(diff, get_section_title, t);
-    } else {
-        print_diff_basic(diff, get_section_title);
+    match term::stdout() {
+        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),
+    }
+
+    // isatty shamelessly adapted from cargo.
+    #[cfg(unix)]
+    fn isatty() -> bool {
+        extern crate libc;
+
+        unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
+    }
+    #[cfg(windows)]
+    fn isatty() -> bool {
+        extern crate kernel32;
+        extern crate winapi;
+
+        unsafe {
+            let handle = kernel32::GetStdHandle(winapi::winbase::STD_OUTPUT_HANDLE);
+            let mut out = 0;
+            kernel32::GetConsoleMode(handle, &mut out) != 0
+        }
     }
 }