Skip to content

Commit 3c8b18d

Browse files
committed
---
yaml --- r: 151727 b: refs/heads/try2 c: 0481d62 h: refs/heads/master i: 151725: cf5e296 151723: d514957 151719: a24a5f8 151711: 4d7aa39 v: v3
1 parent e64822e commit 3c8b18d

File tree

8 files changed

+47
-13
lines changed

8 files changed

+47
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 17df573a2e47d5815b5feb938626f9b6ec9ee4ee
8+
refs/heads/try2: 0481d628b826104085c5df267cf6089a89fcd17b
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/driver/config.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use syntax::ast;
2727
use syntax::ast::{IntTy, UintTy};
2828
use syntax::attr;
2929
use syntax::attr::AttrMetaMethods;
30+
use syntax::diagnostic::{ColorConfig, Auto, Always, Never};
3031
use syntax::parse;
3132
use syntax::parse::token::InternedString;
3233

@@ -92,6 +93,7 @@ pub struct Options {
9293
/// Crate id-related things to maybe print. It's (crate_id, crate_name, crate_file_name).
9394
pub print_metas: (bool, bool, bool),
9495
pub cg: CodegenOptions,
96+
pub color: ColorConfig,
9597
}
9698

9799
/// Some reasonable defaults
@@ -115,6 +117,7 @@ pub fn basic_options() -> Options {
115117
write_dependency_info: (false, None),
116118
print_metas: (false, false, false),
117119
cg: basic_codegen_options(),
120+
color: Auto,
118121
}
119122
}
120123

@@ -537,7 +540,11 @@ pub fn optgroups() -> Vec<getopts::OptGroup> {
537540
optmulti("F", "forbid", "Set lint forbidden", "OPT"),
538541
optmulti("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
539542
optmulti("Z", "", "Set internal debugging options", "FLAG"),
540-
optflag( "v", "version", "Print version info and exit")
543+
optflag("v", "version", "Print version info and exit"),
544+
optopt("", "color", "Configure coloring of output:
545+
auto = colorize, if output goes to a tty (default);
546+
always = always colorize output;
547+
never = never colorize output", "auto|always|never")
541548
)
542549
}
543550

@@ -708,6 +715,18 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
708715
matches.opt_present("crate-file-name"));
709716
let cg = build_codegen_options(matches);
710717

718+
let color = match matches.opt_str("color").as_ref().map(|s| s.as_slice()) {
719+
Some("auto") => Auto,
720+
Some("always") => Always,
721+
Some("never") => Never,
722+
723+
None => Auto,
724+
725+
Some(arg) => early_error(format!(
726+
"argument for --color must be auto, always or never (instead was `{}`)",
727+
arg))
728+
};
729+
711730
Options {
712731
crate_types: crate_types,
713732
gc: gc,
@@ -727,6 +746,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
727746
write_dependency_info: write_dependency_info,
728747
print_metas: print_metas,
729748
cg: cg,
749+
color: color
730750
}
731751
}
732752

branches/try2/src/librustc/driver/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fn parse_crate_attrs(sess: &Session, input: &Input) ->
335335
}
336336

337337
pub fn early_error(msg: &str) -> ! {
338-
let mut emitter = diagnostic::EmitterWriter::stderr();
338+
let mut emitter = diagnostic::EmitterWriter::stderr(diagnostic::Auto);
339339
emitter.emit(None, msg, diagnostic::Fatal);
340340
fail!(diagnostic::FatalError);
341341
}
@@ -380,7 +380,7 @@ fn monitor(f: proc():Send) {
380380
Err(value) => {
381381
// Task failed without emitting a fatal diagnostic
382382
if !value.is::<diagnostic::FatalError>() {
383-
let mut emitter = diagnostic::EmitterWriter::stderr();
383+
let mut emitter = diagnostic::EmitterWriter::stderr(diagnostic::Auto);
384384

385385
// a .span_bug or .bug call has already printed what
386386
// it wants to print.

branches/try2/src/librustc/driver/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub fn build_session(sopts: config::Options,
196196
-> Session {
197197
let codemap = codemap::CodeMap::new();
198198
let diagnostic_handler =
199-
diagnostic::default_handler();
199+
diagnostic::default_handler(sopts.color);
200200
let span_diagnostic_handler =
201201
diagnostic::mk_span_handler(diagnostic_handler, codemap);
202202

branches/try2/src/librustdoc/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<StrBuf>)
7878

7979

8080
let codemap = syntax::codemap::CodeMap::new();
81-
let diagnostic_handler = syntax::diagnostic::default_handler();
81+
let diagnostic_handler = syntax::diagnostic::default_handler(syntax::diagnostic::Auto);
8282
let span_diagnostic_handler =
8383
syntax::diagnostic::mk_span_handler(diagnostic_handler, codemap);
8484

branches/try2/src/librustdoc/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn run(input: &str,
5353

5454

5555
let codemap = CodeMap::new();
56-
let diagnostic_handler = diagnostic::default_handler();
56+
let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto);
5757
let span_diagnostic_handler =
5858
diagnostic::mk_span_handler(diagnostic_handler, codemap);
5959

branches/try2/src/libsyntax/diagnostic.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ impl RenderSpan {
4949
}
5050
}
5151

52+
#[deriving(Clone)]
53+
pub enum ColorConfig {
54+
Auto,
55+
Always,
56+
Never
57+
}
58+
5259
pub trait Emitter {
5360
fn emit(&mut self, cmsp: Option<(&codemap::CodeMap, Span)>,
5461
msg: &str, lvl: Level);
@@ -176,8 +183,8 @@ pub fn mk_span_handler(handler: Handler, cm: codemap::CodeMap) -> SpanHandler {
176183
}
177184
}
178185

179-
pub fn default_handler() -> Handler {
180-
mk_handler(box EmitterWriter::stderr())
186+
pub fn default_handler(color_config: ColorConfig) -> Handler {
187+
mk_handler(box EmitterWriter::stderr(color_config))
181188
}
182189

183190
pub fn mk_handler(e: Box<Emitter:Send>) -> Handler {
@@ -257,9 +264,16 @@ enum Destination {
257264
}
258265

259266
impl EmitterWriter {
260-
pub fn stderr() -> EmitterWriter {
267+
pub fn stderr(color_config: ColorConfig) -> EmitterWriter {
261268
let stderr = io::stderr();
262-
if stderr.get_ref().isatty() {
269+
270+
let use_color = match color_config {
271+
Always => true,
272+
Never => false,
273+
Auto => stderr.get_ref().isatty()
274+
};
275+
276+
if use_color {
263277
let dst = match term::Terminal::new(stderr.unwrap()) {
264278
Ok(t) => Terminal(t),
265279
Err(..) => Raw(box io::stderr()),

branches/try2/src/libsyntax/parse/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use ast;
1515
use codemap::{Span, CodeMap, FileMap};
16-
use diagnostic::{SpanHandler, mk_span_handler, default_handler};
16+
use diagnostic::{SpanHandler, mk_span_handler, default_handler, Auto};
1717
use parse::attr::ParserAttr;
1818
use parse::parser::Parser;
1919

@@ -41,7 +41,7 @@ pub struct ParseSess {
4141

4242
pub fn new_parse_sess() -> ParseSess {
4343
ParseSess {
44-
span_diagnostic: mk_span_handler(default_handler(), CodeMap::new()),
44+
span_diagnostic: mk_span_handler(default_handler(Auto), CodeMap::new()),
4545
included_mod_stack: RefCell::new(Vec::new()),
4646
}
4747
}

0 commit comments

Comments
 (0)