diff options
| author | bors <bors@rust-lang.org> | 2013-07-14 15:55:20 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-07-14 15:55:20 -0700 |
| commit | 68a32aad1ab60b29ebfffd7c2f8d5967371955fc (patch) | |
| tree | 62ece0bc2d2668d51ea96e1a4384a6ece703d831 /src/libsyntax | |
| parent | 4f333023e9d2d0b7a8d2c62df836158c880845b4 (diff) | |
| parent | 1d4c3146f5e35ce60db73849da8806d73c6ecee2 (diff) | |
| download | rust-68a32aad1ab60b29ebfffd7c2f8d5967371955fc.tar.gz rust-68a32aad1ab60b29ebfffd7c2f8d5967371955fc.zip | |
auto merge of #7716 : kballard/rust/term-attr, r=cmr
Teach `extra::term` to support more terminal attributes than just color. Fix the compiler diagnostic messages to print in bold instead of bright white. This matches Clang's output. Cache the term::Terminal instead of re-parsing for every diagnostic (fixes #6827).
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/diagnostic.rs | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 0180c2b31d7..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)>, @@ -186,22 +187,38 @@ 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) { + #[cfg(not(stage0))] + static tls_terminal: local_data::Key<@Option<term::Terminal>> = &local_data::Key; + #[cfg(stage0)] + fn tls_terminal(_: @Option<term::Terminal>) {} + let stderr = io::stderr(); - let t = term::Terminal::new(stderr); + if stderr.get_type() == io::Screen { + 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) => { - if stderr.get_type() == io::Screen { - term.fg(color); + match t { + &Some(ref 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 +229,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 +330,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))); } } |
