about summary refs log tree commit diff
path: root/src/librustpkg
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-06-03 13:34:56 -0700
committerbors <bors@rust-lang.org>2013-06-03 13:34:56 -0700
commit8a43b318bf30c26f4e9f3557b6c7036fcb9d5342 (patch)
tree402e0be1b130574e325c772b0ab8e8346566d0fb /src/librustpkg
parentc68c015798998448dd51af138f4a223fb94ea387 (diff)
parentae5f3de5f00368cd8c5e62a472ab0062115d97df (diff)
downloadrust-8a43b318bf30c26f4e9f3557b6c7036fcb9d5342.tar.gz
rust-8a43b318bf30c26f4e9f3557b6c7036fcb9d5342.zip
auto merge of #6826 : cmr/rust/terminfo, r=thestinger
This will let *everyone* (non-windows, at least) who can see colors see the glorious colors rustc produces.
Diffstat (limited to 'src/librustpkg')
-rw-r--r--src/librustpkg/util.rs50
1 files changed, 19 insertions, 31 deletions
diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs
index c5a5aaea178..33745e85387 100644
--- a/src/librustpkg/util.rs
+++ b/src/librustpkg/util.rs
@@ -162,43 +162,31 @@ 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())
 }
 
 // FIXME (#4432): Use workcache to only compile when needed