From 69da3808444d71a39d3c05519a45d5186537cfcb Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Wed, 10 Jul 2013 23:35:13 -0700 Subject: 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. --- src/libsyntax/diagnostic.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 0180c2b31d7..fc0dc4c8f52 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -186,22 +186,22 @@ fn diagnosticcolor(lvl: level) -> term::color::Color { } } -fn print_maybe_colored(msg: &str, color: term::color::Color) { +fn print_maybe_styled(msg: &str, color: term::attr::Attr) { let stderr = io::stderr(); - let t = term::Terminal::new(stderr); + if stderr.get_type() == io::Screen { + let t = term::Terminal::new(stderr); - match t { - Ok(term) => { - if stderr.get_type() == io::Screen { - term.fg(color); + match t { + Ok(term) => { + term.attr(color); stderr.write_str(msg); term.reset(); - } else { - stderr.write_str(msg); - } - }, - _ => stderr.write_str(msg) + }, + _ => stderr.write_str(msg) + } + } else { + stderr.write_str(msg); } } @@ -212,8 +212,9 @@ fn print_diagnostic(topic: &str, lvl: level, msg: &str) { stderr.write_str(fmt!("%s ", topic)); } - print_maybe_colored(fmt!("%s: ", diagnosticstr(lvl)), diagnosticcolor(lvl)); - print_maybe_colored(fmt!("%s\n", msg), term::color::BRIGHT_WHITE); + print_maybe_styled(fmt!("%s: ", diagnosticstr(lvl)), + term::attr::ForegroundColor(diagnosticcolor(lvl))); + print_maybe_styled(fmt!("%s\n", msg), term::attr::Bold); } pub fn collect(messages: @mut ~[~str]) @@ -312,7 +313,7 @@ fn highlight_lines(cm: @codemap::CodeMap, s.push_char('~') } } - print_maybe_colored(s + "\n", diagnosticcolor(lvl)); + print_maybe_styled(s + "\n", term::attr::ForegroundColor(diagnosticcolor(lvl))); } } -- cgit 1.4.1-3-g733a5 From 1d4c3146f5e35ce60db73849da8806d73c6ecee2 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Thu, 11 Jul 2013 00:56:26 -0700 Subject: Don't re-parse terminfo (twice!) on every compiler diagnostic Stuff the term::Terminal into TLS to avoid re-parsing for every single message we want to color. Fixes #6827. --- src/libsyntax/diagnostic.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index fc0dc4c8f52..2971ad5cc29 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -13,6 +13,7 @@ use codemap; use std::io; use std::uint; +use std::local_data; use extra::term; pub type Emitter = @fn(cmsp: Option<(@codemap::CodeMap, span)>, @@ -187,13 +188,29 @@ fn diagnosticcolor(lvl: level) -> term::color::Color { } fn print_maybe_styled(msg: &str, color: term::attr::Attr) { + #[cfg(not(stage0))] + static tls_terminal: local_data::Key<@Option> = &local_data::Key; + #[cfg(stage0)] + fn tls_terminal(_: @Option) {} + let stderr = io::stderr(); if stderr.get_type() == io::Screen { - let t = term::Terminal::new(stderr); + let t = match local_data::get(tls_terminal, |v| v.map_consume(|&k|k)) { + None => { + let t = term::Terminal::new(stderr); + let tls = @match t { + Ok(t) => Some(t), + Err(_) => None + }; + local_data::set(tls_terminal, tls); + &*tls + } + Some(tls) => &*tls + }; match t { - Ok(term) => { + &Some(ref term) => { term.attr(color); stderr.write_str(msg); term.reset(); -- cgit 1.4.1-3-g733a5