summary refs log tree commit diff
path: root/src/libsyntax/diagnostic.rs
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2013-05-30 02:13:35 -0400
committerCorey Richardson <corey@octayn.net>2013-05-31 20:02:49 -0400
commitcf64324e19efd159fe0411f55a608f4f747e298d (patch)
tree8daee41b13b1a418501c4c8b1a34e7e0ee8b21d1 /src/libsyntax/diagnostic.rs
parent55c23bc55706d71e2168c0eef42f59f20e06b75f (diff)
downloadrust-cf64324e19efd159fe0411f55a608f4f747e298d.tar.gz
rust-cf64324e19efd159fe0411f55a608f4f747e298d.zip
extra::term overhaul
Diffstat (limited to 'src/libsyntax/diagnostic.rs')
-rw-r--r--src/libsyntax/diagnostic.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs
index 76ede098ac3..094082f41e7 100644
--- a/src/libsyntax/diagnostic.rs
+++ b/src/libsyntax/diagnostic.rs
@@ -191,19 +191,27 @@ fn diagnosticcolor(lvl: level) -> u8 {
 }
 
 fn print_diagnostic(topic: &str, lvl: level, msg: &str) {
-    let use_color = term::color_supported() &&
-        io::stderr().get_type() == io::Screen;
+    let term = term::Terminal::new(io::stderr());
+
+    let stderr = io::stderr();
+
     if !topic.is_empty() {
-        io::stderr().write_str(fmt!("%s ", topic));
-    }
-    if use_color {
-        term::fg(io::stderr(), diagnosticcolor(lvl));
+        stderr.write_str(fmt!("%s ", topic));
     }
-    io::stderr().write_str(fmt!("%s:", diagnosticstr(lvl)));
-    if use_color {
-        term::reset(io::stderr());
+
+    match term {
+        Ok(t) => {
+            if stderr.get_type() == io::Screen {
+                t.fg(diagnosticcolor(lvl));
+                stderr.write_str(fmt!("%s: ", diagnosticstr(lvl)));
+                t.reset();
+                stderr.write_str(fmt!("%s\n", msg));
+            }
+        }
+        Err(_) => {
+            stderr.write_str(fmt!("%s: %s\n", diagnosticstr(lvl), msg));
+        }
     }
-    io::stderr().write_str(fmt!(" %s\n", msg));
 }
 
 pub fn collect(messages: @mut ~[~str])