]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #6826 : cmr/rust/terminfo, r=thestinger
authorbors <bors@rust-lang.org>
Mon, 3 Jun 2013 20:34:56 +0000 (13:34 -0700)
committerbors <bors@rust-lang.org>
Mon, 3 Jun 2013 20:34:56 +0000 (13:34 -0700)
This will let *everyone* (non-windows, at least) who can see colors see the glorious colors rustc produces.

1  2 
src/libextra/test.rs
src/librustpkg/util.rs

Simple merge
index c5a5aaea178ade81f1236a0fed65ceead4d934ba,8071546136f067b3e48f5d9f874aebb1609fc251..33745e85387e5109e1f6a59c25de62e8920e2e9e
@@@ -162,47 -277,42 +162,35 @@@ pub fn need_dir(s: &Path) 
      }
  }
  
- pub fn note(msg: ~str) {
-     let out = io::stdout();
-     if term::color_supported() {
-         term::fg(out, term::color_green);
-         out.write_str("note: ");
-         term::reset(out);
-         out.write_line(msg);
-     } else {
-         out.write_line(~"note: " + msg);
+ fn pretty_message<'a>(msg: &'a str, prefix: &'a str, color: u8, out: @io::Writer) {
+     let term = term::Terminal::new(out);
+     match term {
+         Ok(ref t) => {
+             t.fg(color);
+             out.write_str(prefix);
+             t.reset();
+         },
+         _ => {
+             out.write_str(prefix);
+         }
      }
+     out.write_line(msg);
  }
  
- pub fn warn(msg: ~str) {
-     let out = io::stdout();
-     if term::color_supported() {
-         term::fg(out, term::color_yellow);
-         out.write_str("warning: ");
-         term::reset(out);
-         out.write_line(msg);
-     } else {
-         out.write_line(~"warning: " + msg);
-     }
+ pub fn note(msg: &str) {
+     pretty_message(msg, "note: ", term::color_green, io::stdout())
  }
  
- pub fn error(msg: ~str) {
-     let out = io::stdout();
+ pub fn warn(msg: &str) {
+     pretty_message(msg, "warning: ", term::color_yellow, io::stdout())
+ }
  
-     if term::color_supported() {
-         term::fg(out, term::color_red);
-         out.write_str("error: ");
-         term::reset(out);
-         out.write_line(msg);
-     } else {
-         out.write_line(~"error: " + msg);
-     }
+ pub fn error(msg: &str) {
+     pretty_message(msg, "error: ", term::color_red, io::stdout())
  }
  
 -pub fn hash(data: ~str) -> ~str {
 -    let mut hasher = hash::default_state();
 -    let buffer = str::as_bytes_slice(data);
 -    hasher.write(buffer);
 -    hasher.result_str()
 -}
 -
  // FIXME (#4432): Use workcache to only compile when needed
 -pub fn compile_input(sysroot: Option<@Path>,
 +pub fn compile_input(ctxt: &Ctx,
                       pkg_id: &PkgId,
                       in_file: &Path,
                       out_dir: &Path,