From 8066dfd4ad24c011f581c80b818ac352711a5942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Br=C3=BCschweiler?= Date: Wed, 19 Jun 2013 13:42:47 +0200 Subject: [PATCH] syntax::diagnostics: Color the ^~~~ in green for better visibility Fixes #7164. --- src/libsyntax/diagnostic.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index e67ca5260b8f0..5af6e3679aad9 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); } }