diff options
| author | Hanno Braun <mail@hannobraun.de> | 2014-05-08 13:10:03 +0000 |
|---|---|---|
| committer | Hanno Braun <mail@hannobraun.de> | 2014-05-15 13:12:53 +0000 |
| commit | b7676f2df5e1ff97e0baa3f7e70936d4bd4dacb5 (patch) | |
| tree | a70df2c0d394b84d3741321d22bc91888a75d541 /src/libsyntax | |
| parent | 579e0a5f5555ed926cf9378ef61b034b0c316e76 (diff) | |
| download | rust-b7676f2df5e1ff97e0baa3f7e70936d4bd4dacb5.tar.gz rust-b7676f2df5e1ff97e0baa3f7e70936d4bd4dacb5.zip | |
Add compiler flag to configure output coloring
This adds the flag --color, which allows the user to force coloring or turn it off. The default behavior stays the same as before (colorize, if output goes to tty). Why this is beneficial is explained in issue #12881. Please note that this commit doesn't include any regression tests. I thought about how I'd write a test for this and it doesn't seem to be worth the effort to me for a UI change like this. Fixes #12881.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/diagnostic.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 4 |
2 files changed, 20 insertions, 6 deletions
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 73027013090..94132988d97 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -49,6 +49,13 @@ impl RenderSpan { } } +#[deriving(Clone)] +pub enum ColorConfig { + Auto, + Always, + Never +} + pub trait Emitter { fn emit(&mut self, cmsp: Option<(&codemap::CodeMap, Span)>, msg: &str, lvl: Level); @@ -176,8 +183,8 @@ pub fn mk_span_handler(handler: Handler, cm: codemap::CodeMap) -> SpanHandler { } } -pub fn default_handler() -> Handler { - mk_handler(box EmitterWriter::stderr()) +pub fn default_handler(color_config: ColorConfig) -> Handler { + mk_handler(box EmitterWriter::stderr(color_config)) } pub fn mk_handler(e: Box<Emitter:Send>) -> Handler { @@ -257,9 +264,16 @@ enum Destination { } impl EmitterWriter { - pub fn stderr() -> EmitterWriter { + pub fn stderr(color_config: ColorConfig) -> EmitterWriter { let stderr = io::stderr(); - if stderr.get_ref().isatty() { + + let use_color = match color_config { + Always => true, + Never => false, + Auto => stderr.get_ref().isatty() + }; + + if use_color { let dst = match term::Terminal::new(stderr.unwrap()) { Ok(t) => Terminal(t), Err(..) => Raw(box io::stderr()), diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 28f235a3da0..d8a9f69e293 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -13,7 +13,7 @@ use ast; use codemap::{Span, CodeMap, FileMap}; -use diagnostic::{SpanHandler, mk_span_handler, default_handler}; +use diagnostic::{SpanHandler, mk_span_handler, default_handler, Auto}; use parse::attr::ParserAttr; use parse::parser::Parser; @@ -41,7 +41,7 @@ pub struct ParseSess { pub fn new_parse_sess() -> ParseSess { ParseSess { - span_diagnostic: mk_span_handler(default_handler(), CodeMap::new()), + span_diagnostic: mk_span_handler(default_handler(Auto), CodeMap::new()), included_mod_stack: RefCell::new(Vec::new()), } } |
