about summary refs log tree commit diff
path: root/src/rustfmt_diff.rs
diff options
context:
space:
mode:
authorDavid Alber <alber.david@gmail.com>2017-12-13 00:40:07 -0800
committerDavid Alber <alber.david@gmail.com>2018-01-04 00:01:18 -0800
commit85ccb98469596a595e747466b7fd789971203a6d (patch)
treee91d1c2eca636358b5b9525994ed7ad03363600b /src/rustfmt_diff.rs
parent91a332483bfeac25db9d0dd315b01cf2d05250c0 (diff)
Adding test to verify code block idempotency in Configurations.md
Diffstat (limited to 'src/rustfmt_diff.rs')
-rw-r--r--src/rustfmt_diff.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/rustfmt_diff.rs b/src/rustfmt_diff.rs
index 69633568755..f37ab5c16ef 100644
--- a/src/rustfmt_diff.rs
+++ b/src/rustfmt_diff.rs
@@ -97,15 +97,28 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma
     results
 }
 
+// A representation of how to write output.
+pub enum PrintType {
+    Fancy, // want to output color and the terminal supports it
+    Basic, // do not want to output color or the terminal does not support color
+}
+
+impl PrintType {
+    pub fn get(color: Color) -> Self {
+        match term::stdout() {
+            Some(ref t) if use_colored_tty(color) && t.supports_color() => PrintType::Fancy,
+            _ => PrintType::Basic,
+        }
+    }
+}
+
 pub fn print_diff<F>(diff: Vec<Mismatch>, get_section_title: F, color: Color)
 where
     F: Fn(u32) -> String,
 {
-    match term::stdout() {
-        Some(ref t) if use_colored_tty(color) && t.supports_color() => {
-            print_diff_fancy(diff, get_section_title, term::stdout().unwrap())
-        }
-        _ => print_diff_basic(diff, get_section_title),
+    match PrintType::get(color) {
+        PrintType::Fancy => print_diff_fancy(diff, get_section_title, term::stdout().unwrap()),
+        PrintType::Basic => print_diff_basic(diff, get_section_title),
     }
 }