about summary refs log tree commit diff
path: root/src/librustpkg
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2013-05-30 02:13:35 -0400
committerCorey Richardson <corey@octayn.net>2013-05-31 20:02:49 -0400
commitcf64324e19efd159fe0411f55a608f4f747e298d (patch)
tree8daee41b13b1a418501c4c8b1a34e7e0ee8b21d1 /src/librustpkg
parent55c23bc55706d71e2168c0eef42f59f20e06b75f (diff)
downloadrust-cf64324e19efd159fe0411f55a608f4f747e298d.tar.gz
rust-cf64324e19efd159fe0411f55a608f4f747e298d.zip
extra::term overhaul
Diffstat (limited to 'src/librustpkg')
-rw-r--r--src/librustpkg/util.rs48
1 files changed, 18 insertions, 30 deletions
diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs
index 8019b3b8afb..f6f8c6f6754 100644
--- a/src/librustpkg/util.rs
+++ b/src/librustpkg/util.rs
@@ -277,43 +277,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) if t.color_supported => {
+            t.fg(color);
+            out.write_str(prefix);
+            t.reset();
+        },
+        _ => {
+            out.write_str(prefix);
+        }
     }
+    out.write_line(msg);
+}
+
+pub fn note(msg: ~str) {
+    pretty_message(msg, "note: ", term::color_green, io::stdout())
 }
 
 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);
-    }
+    pretty_message(msg, "warning: ", term::color_yellow, io::stdout())
 }
 
 pub fn error(msg: ~str) {
-    let out = 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);
-    }
+    pretty_message(msg, "error: ", term::color_red, io::stdout())
 }
 
 pub fn hash(data: ~str) -> ~str {