Skip to content

syntax::diagnostics: Color the ^~~~ in green for better visibility #7230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/libsyntax/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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);
}
}

Expand Down