]> git.lizzy.rs Git - rust.git/commitdiff
Give term.fg() and term.bg() a bool return value
authorKevin Ballard <kevin@sb.org>
Thu, 11 Jul 2013 01:26:04 +0000 (18:26 -0700)
committerKevin Ballard <kevin@sb.org>
Sun, 14 Jul 2013 21:37:29 +0000 (14:37 -0700)
src/libextra/term.rs

index cd226e2ad3267ce4245638ee3d6c9efd09e99939..1740f4d1ecc165e41983bfc94b9c4f7e6abfdbfc 100644 (file)
@@ -88,33 +88,41 @@ pub fn new(out: @io::Writer) -> Result<Terminal, ~str> {
     ///
     /// If the color is a bright color, but the terminal only supports 8 colors,
     /// the corresponding normal color will be used instead.
-    pub fn fg(&self, color: color::Color) {
+    ///
+    /// Returns true if the color was set, false otherwise.
+    pub fn fg(&self, color: color::Color) -> bool {
         let color = self.dim_if_necessary(color);
         if self.num_colors > color {
             let s = expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(),
                            [Number(color as int)], &mut Variables::new());
             if s.is_ok() {
                 self.out.write(s.unwrap());
+                return true
             } else {
                 warn!("%s", s.unwrap_err());
             }
         }
+        false
     }
     /// Sets the background color to the given color.
     ///
     /// If the color is a bright color, but the terminal only supports 8 colors,
     /// the corresponding normal color will be used instead.
-    pub fn bg(&self, color: color::Color) {
+    ///
+    /// Rturns true if the color was set, false otherwise.
+    pub fn bg(&self, color: color::Color) -> bool {
         let color = self.dim_if_necessary(color);
         if self.num_colors > color {
             let s = expand(*self.ti.strings.find_equiv(&("setab")).unwrap(),
                            [Number(color as int)], &mut Variables::new());
             if s.is_ok() {
                 self.out.write(s.unwrap());
+                return true
             } else {
                 warn!("%s", s.unwrap_err());
             }
         }
+        false
     }
     pub fn reset(&self) {
         let mut vars = Variables::new();
@@ -144,10 +152,12 @@ pub fn new(out: @io::Writer) -> Result<Terminal, ~str> {
         return Ok(Terminal {out: out, num_colors: 0});
     }
 
-    pub fn fg(&self, _color: color::Color) {
+    pub fn fg(&self, _color: color::Color) -> bool {
+        false
     }
 
-    pub fn bg(&self, _color: color::Color) {
+    pub fn bg(&self, _color: color::Color) -> bool {
+        false
     }
 
     pub fn reset(&self) {