]> git.proxmox.com Git - cargo.git/blobdiff - vendor/termcolor/src/lib.rs
New upstream version 0.52.0
[cargo.git] / vendor / termcolor / src / lib.rs
index 42eccda1e69cc37a2531544223a18babdd8cb793..735ce97d20afb832ee7338327aed959a49d6b302 100644 (file)
@@ -119,10 +119,10 @@ Currently, `termcolor` does not provide anything to do this for you.
 
 #![deny(missing_docs)]
 
-#[cfg(test)]
-use doc_comment::doctest;
-#[cfg(test)]
-doctest!("../README.md");
+// #[cfg(doctest)]
+// use doc_comment::doctest;
+// #[cfg(doctest)]
+// doctest!("../README.md");
 
 use std::env;
 use std::error;
@@ -1306,6 +1306,9 @@ impl<W: io::Write> WriteColor for Ansi<W> {
         if spec.bold {
             self.write_str("\x1B[1m")?;
         }
+        if spec.dimmed {
+            self.write_str("\x1B[2m")?;
+        }
         if spec.italic {
             self.write_str("\x1B[3m")?;
         }
@@ -1566,6 +1569,7 @@ pub struct ColorSpec {
     bold: bool,
     intense: bool,
     underline: bool,
+    dimmed: bool,
     italic: bool,
     reset: bool,
 }
@@ -1578,6 +1582,7 @@ impl Default for ColorSpec {
             bold: false,
             intense: false,
             underline: false,
+            dimmed: false,
             italic: false,
             reset: true,
         }
@@ -1627,6 +1632,21 @@ impl ColorSpec {
         self
     }
 
+    /// Get whether this is dimmed or not.
+    ///
+    /// Note that the dimmed setting has no effect in a Windows console.
+    pub fn dimmed(&self) -> bool {
+        self.dimmed
+    }
+
+    /// Set whether the text is dimmed or not.
+    ///
+    /// Note that the dimmed setting has no effect in a Windows console.
+    pub fn set_dimmed(&mut self, yes: bool) -> &mut ColorSpec {
+        self.dimmed = yes;
+        self
+    }
+
     /// Get whether this is italic or not.
     ///
     /// Note that the italic setting has no effect in a Windows console.
@@ -1715,6 +1735,7 @@ impl ColorSpec {
             && self.bg_color.is_none()
             && !self.bold
             && !self.underline
+            && !self.dimmed
             && !self.italic
             && !self.intense
     }
@@ -1726,6 +1747,7 @@ impl ColorSpec {
         self.bold = false;
         self.underline = false;
         self.intense = false;
+        self.dimmed = false;
         self.italic = false;
     }
 
@@ -2180,14 +2202,17 @@ mod tests {
                     for underline in vec![false, true] {
                         for intense in vec![false, true] {
                             for italic in vec![false, true] {
-                                let mut color = ColorSpec::new();
-                                color.set_fg(fg);
-                                color.set_bg(bg);
-                                color.set_bold(bold);
-                                color.set_underline(underline);
-                                color.set_intense(intense);
-                                color.set_italic(italic);
-                                result.push(color);
+                                for dimmed in vec![false, true] {
+                                    let mut color = ColorSpec::new();
+                                    color.set_fg(fg);
+                                    color.set_bg(bg);
+                                    color.set_bold(bold);
+                                    color.set_underline(underline);
+                                    color.set_intense(intense);
+                                    color.set_dimmed(dimmed);
+                                    color.set_italic(italic);
+                                    result.push(color);
+                                }
                             }
                         }
                     }