]> git.lizzy.rs Git - rust.git/commitdiff
Only output colors if colors are supported (removes burden from caller)
authorCorey Richardson <corey@octayn.net>
Thu, 30 May 2013 17:21:41 +0000 (13:21 -0400)
committerCorey Richardson <corey@octayn.net>
Sat, 1 Jun 2013 00:02:49 +0000 (20:02 -0400)
src/libextra/term.rs

index eb1a0897e3315074fab3ba42e8da133e779a78c6..691a6b4dc6242cded46512a45f5d1853854c1b5d 100644 (file)
@@ -43,8 +43,6 @@
 pub static color_bright_cyan: u8 = 14u8;
 pub static color_bright_white: u8 = 15u8;
 
-pub fn esc(writer: @io::Writer) { writer.write([0x1bu8, '[' as u8]); }
-
 pub struct Terminal {
     color_supported: bool,
     priv out: @io::Writer,
@@ -75,12 +73,20 @@ pub fn new(out: @io::Writer) -> Result<Terminal, ~str> {
         return Ok(Terminal {out: out, ti: inf, color_supported: cs});
     }
     fn fg(&self, color: u8) {
-        self.out.write(expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(), [Number(color as int)], [], []));
+        if self.color_supported {
+            self.out.write(expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(), 
+                                  [Number(color as int)], [], []));
+        }
     }
     fn bg(&self, color: u8) {
-        self.out.write(expand(*self.ti.strings.find_equiv(&("setab")).unwrap(), [Number(color as int)], [], []));
+        if self.color_supported {
+            self.out.write(expand(*self.ti.strings.find_equiv(&("setab")).unwrap(),
+                                  [Number(color as int)], [], []));
+        }
     }
     fn reset(&self) {
-        self.out.write(expand(*self.ti.strings.find_equiv(&("op")).unwrap(), [], [], []));
+        if self.color_supported {
+            self.out.write(expand(*self.ti.strings.find_equiv(&("op")).unwrap(), [], [], []));
+        }
     }
 }