about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorPhilipp Brüschweiler <blei42@gmail.com>2013-06-19 13:42:47 +0200
committerPhilipp Brüschweiler <blei42@gmail.com>2013-06-19 13:43:19 +0200
commit8066dfd4ad24c011f581c80b818ac352711a5942 (patch)
tree64c18895228e26380acbea5e01aebe0ac7b7b4fc /src/libsyntax
parent1120f8c1e57b7b30134d670dd1dfc18c6444c15f (diff)
syntax::diagnostics: Color the ^~~~ in green for better visibility
Fixes #7164.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/diagnostic.rs33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs
index e67ca5260b8..5af6e3679aa 100644
--- a/src/libsyntax/diagnostic.rs
+++ b/src/libsyntax/diagnostic.rs
@@ -189,30 +189,36 @@ fn diagnosticcolor(lvl: level) -> u8 {
     }
 }
 
-fn print_diagnostic(topic: &str, lvl: level, msg: &str) {
-    let t = term::Terminal::new(io::stderr());
-
+fn print_maybe_colored(msg: &str, color: u8) {
     let stderr = io::stderr();
 
-    if !topic.is_empty() {
-        stderr.write_str(fmt!("%s ", topic));
-    }
+    let t = term::Terminal::new(stderr);
 
     match t {
         Ok(term) => {
             if stderr.get_type() == io::Screen {
-                term.fg(diagnosticcolor(lvl));
-                stderr.write_str(fmt!("%s: ", diagnosticstr(lvl)));
+                term.fg(color);
+                stderr.write_str(msg);
                 term.reset();
-                stderr.write_str(fmt!("%s\n", msg));
             } else {
-                stderr.write_str(fmt!("%s: %s\n", diagnosticstr(lvl), msg));
+                stderr.write_str(msg);
             }
         },
-        _ => stderr.write_str(fmt!("%s: %s\n", diagnosticstr(lvl), msg))
+        _ => stderr.write_str(msg)
     }
 }
 
+fn print_diagnostic(topic: &str, lvl: level, msg: &str) {
+    let stderr = io::stderr();
+
+    if !topic.is_empty() {
+        stderr.write_str(fmt!("%s ", topic));
+    }
+
+    print_maybe_colored(fmt!("%s: ", diagnosticstr(lvl)), diagnosticcolor(lvl));
+    stderr.write_str(fmt!("%s\n", msg));
+}
+
 pub fn collect(messages: @mut ~[~str])
             -> @fn(Option<(@codemap::CodeMap, span)>, &str, level) {
     let f: @fn(Option<(@codemap::CodeMap, span)>, &str, level) =
@@ -292,14 +298,15 @@ fn highlight_lines(cm: @codemap::CodeMap,
                 _ => " "         // -squigly-line as well (instead of a
             };                   // space). This way the squigly-line will
         }                        // usually appear in the correct position.
-        s += "^";
+        io::stderr().write_str(s);
+        let mut s = ~"^";
         let hi = cm.lookup_char_pos(sp.hi);
         if hi.col != lo.col {
             // the ^ already takes up one space
             let num_squiglies = hi.col.to_uint()-lo.col.to_uint()-1u;
             for num_squiglies.times() { s += "~"; }
         }
-        io::stderr().write_str(s + "\n");
+        print_maybe_colored(s + "\n", term::color_bright_green);
     }
 }