Skip to content

Commit 8066dfd

Browse files
committed
syntax::diagnostics: Color the ^~~~ in green for better visibility
Fixes #7164.
1 parent 1120f8c commit 8066dfd

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/libsyntax/diagnostic.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,30 +189,36 @@ fn diagnosticcolor(lvl: level) -> u8 {
189189
}
190190
}
191191

192-
fn print_diagnostic(topic: &str, lvl: level, msg: &str) {
193-
let t = term::Terminal::new(io::stderr());
194-
192+
fn print_maybe_colored(msg: &str, color: u8) {
195193
let stderr = io::stderr();
196194

197-
if !topic.is_empty() {
198-
stderr.write_str(fmt!("%s ", topic));
199-
}
195+
let t = term::Terminal::new(stderr);
200196

201197
match t {
202198
Ok(term) => {
203199
if stderr.get_type() == io::Screen {
204-
term.fg(diagnosticcolor(lvl));
205-
stderr.write_str(fmt!("%s: ", diagnosticstr(lvl)));
200+
term.fg(color);
201+
stderr.write_str(msg);
206202
term.reset();
207-
stderr.write_str(fmt!("%s\n", msg));
208203
} else {
209-
stderr.write_str(fmt!("%s: %s\n", diagnosticstr(lvl), msg));
204+
stderr.write_str(msg);
210205
}
211206
},
212-
_ => stderr.write_str(fmt!("%s: %s\n", diagnosticstr(lvl), msg))
207+
_ => stderr.write_str(msg)
213208
}
214209
}
215210

211+
fn print_diagnostic(topic: &str, lvl: level, msg: &str) {
212+
let stderr = io::stderr();
213+
214+
if !topic.is_empty() {
215+
stderr.write_str(fmt!("%s ", topic));
216+
}
217+
218+
print_maybe_colored(fmt!("%s: ", diagnosticstr(lvl)), diagnosticcolor(lvl));
219+
stderr.write_str(fmt!("%s\n", msg));
220+
}
221+
216222
pub fn collect(messages: @mut ~[~str])
217223
-> @fn(Option<(@codemap::CodeMap, span)>, &str, level) {
218224
let f: @fn(Option<(@codemap::CodeMap, span)>, &str, level) =
@@ -292,14 +298,15 @@ fn highlight_lines(cm: @codemap::CodeMap,
292298
_ => " " // -squigly-line as well (instead of a
293299
}; // space). This way the squigly-line will
294300
} // usually appear in the correct position.
295-
s += "^";
301+
io::stderr().write_str(s);
302+
let mut s = ~"^";
296303
let hi = cm.lookup_char_pos(sp.hi);
297304
if hi.col != lo.col {
298305
// the ^ already takes up one space
299306
let num_squiglies = hi.col.to_uint()-lo.col.to_uint()-1u;
300307
for num_squiglies.times() { s += "~"; }
301308
}
302-
io::stderr().write_str(s + "\n");
309+
print_maybe_colored(s + "\n", term::color_bright_green);
303310
}
304311
}
305312

0 commit comments

Comments
 (0)