Skip to content

Commit 69da380

Browse files
committed
Highlight rustc's warnings/errors in bold instead of bright white
Clang actually highlights using bold, not using bright white. Match clang on this so our diagnostics are still readable on terminals with a white background.
1 parent 690495d commit 69da380

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/libsyntax/diagnostic.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,22 @@ fn diagnosticcolor(lvl: level) -> term::color::Color {
186186
}
187187
}
188188

189-
fn print_maybe_colored(msg: &str, color: term::color::Color) {
189+
fn print_maybe_styled(msg: &str, color: term::attr::Attr) {
190190
let stderr = io::stderr();
191191

192-
let t = term::Terminal::new(stderr);
192+
if stderr.get_type() == io::Screen {
193+
let t = term::Terminal::new(stderr);
193194

194-
match t {
195-
Ok(term) => {
196-
if stderr.get_type() == io::Screen {
197-
term.fg(color);
195+
match t {
196+
Ok(term) => {
197+
term.attr(color);
198198
stderr.write_str(msg);
199199
term.reset();
200-
} else {
201-
stderr.write_str(msg);
202-
}
203-
},
204-
_ => stderr.write_str(msg)
200+
},
201+
_ => stderr.write_str(msg)
202+
}
203+
} else {
204+
stderr.write_str(msg);
205205
}
206206
}
207207

@@ -212,8 +212,9 @@ fn print_diagnostic(topic: &str, lvl: level, msg: &str) {
212212
stderr.write_str(fmt!("%s ", topic));
213213
}
214214

215-
print_maybe_colored(fmt!("%s: ", diagnosticstr(lvl)), diagnosticcolor(lvl));
216-
print_maybe_colored(fmt!("%s\n", msg), term::color::BRIGHT_WHITE);
215+
print_maybe_styled(fmt!("%s: ", diagnosticstr(lvl)),
216+
term::attr::ForegroundColor(diagnosticcolor(lvl)));
217+
print_maybe_styled(fmt!("%s\n", msg), term::attr::Bold);
217218
}
218219

219220
pub fn collect(messages: @mut ~[~str])
@@ -312,7 +313,7 @@ fn highlight_lines(cm: @codemap::CodeMap,
312313
s.push_char('~')
313314
}
314315
}
315-
print_maybe_colored(s + "\n", diagnosticcolor(lvl));
316+
print_maybe_styled(s + "\n", term::attr::ForegroundColor(diagnosticcolor(lvl)));
316317
}
317318
}
318319

0 commit comments

Comments
 (0)