]> git.proxmox.com Git - cargo.git/blobdiff - vendor/env_logger/src/fmt/writer/termcolor/extern_impl.rs
Merge branch 'debian/sid' into proxmox/bullseye
[cargo.git] / vendor / env_logger / src / fmt / writer / termcolor / extern_impl.rs
index 11012fb1582c81c9565da9cd2d4badb31c648e45..fbe37a77bf3f5755c12e0b1a317ee3c1f09c23c9 100644 (file)
@@ -71,19 +71,19 @@ impl Formatter {
 
 pub(in crate::fmt::writer) struct BufferWriter {
     inner: termcolor::BufferWriter,
-    test_target: Option<WritableTarget>,
+    uncolored_target: Option<WritableTarget>,
 }
 
 pub(in crate::fmt) struct Buffer {
     inner: termcolor::Buffer,
-    has_test_target: bool,
+    has_uncolored_target: bool,
 }
 
 impl BufferWriter {
     pub(in crate::fmt::writer) fn stderr(is_test: bool, write_style: WriteStyle) -> Self {
         BufferWriter {
             inner: termcolor::BufferWriter::stderr(write_style.into_color_choice()),
-            test_target: if is_test {
+            uncolored_target: if is_test {
                 Some(WritableTarget::Stderr)
             } else {
                 None
@@ -94,7 +94,7 @@ impl BufferWriter {
     pub(in crate::fmt::writer) fn stdout(is_test: bool, write_style: WriteStyle) -> Self {
         BufferWriter {
             inner: termcolor::BufferWriter::stdout(write_style.into_color_choice()),
-            test_target: if is_test {
+            uncolored_target: if is_test {
                 Some(WritableTarget::Stdout)
             } else {
                 None
@@ -103,30 +103,25 @@ impl BufferWriter {
     }
 
     pub(in crate::fmt::writer) fn pipe(
-        is_test: bool,
         write_style: WriteStyle,
         pipe: Box<Mutex<dyn io::Write + Send + 'static>>,
     ) -> Self {
         BufferWriter {
             // The inner Buffer is never printed from, but it is still needed to handle coloring and other formating
             inner: termcolor::BufferWriter::stderr(write_style.into_color_choice()),
-            test_target: if is_test {
-                Some(WritableTarget::Pipe(pipe))
-            } else {
-                None
-            },
+            uncolored_target: Some(WritableTarget::Pipe(pipe)),
         }
     }
 
     pub(in crate::fmt::writer) fn buffer(&self) -> Buffer {
         Buffer {
             inner: self.inner.buffer(),
-            has_test_target: self.test_target.is_some(),
+            has_uncolored_target: self.uncolored_target.is_some(),
         }
     }
 
     pub(in crate::fmt::writer) fn print(&self, buf: &Buffer) -> io::Result<()> {
-        if let Some(target) = &self.test_target {
+        if let Some(target) = &self.uncolored_target {
             // This impl uses the `eprint` and `print` macros
             // instead of `termcolor`'s buffer.
             // This is so their output can be captured by `cargo test`
@@ -164,7 +159,7 @@ impl Buffer {
 
     fn set_color(&mut self, spec: &ColorSpec) -> io::Result<()> {
         // Ignore styles for test captured logs because they can't be printed
-        if !self.has_test_target {
+        if !self.has_uncolored_target {
             self.inner.set_color(spec)
         } else {
             Ok(())
@@ -173,7 +168,7 @@ impl Buffer {
 
     fn reset(&mut self) -> io::Result<()> {
         // Ignore styles for test captured logs because they can't be printed
-        if !self.has_test_target {
+        if !self.has_uncolored_target {
             self.inner.reset()
         } else {
             Ok(())
@@ -339,6 +334,33 @@ impl Style {
         self
     }
 
+    /// Set whether the text is dimmed.
+    ///
+    /// If `yes` is true then text will be written in a dimmer color.
+    /// If `yes` is false then text will be written in the default color.
+    ///
+    /// # Examples
+    ///
+    /// Create a style with dimmed text:
+    ///
+    /// ```
+    /// use std::io::Write;
+    ///
+    /// let mut builder = env_logger::Builder::new();
+    ///
+    /// builder.format(|buf, record| {
+    ///     let mut style = buf.style();
+    ///
+    ///     style.set_dimmed(true);
+    ///
+    ///     writeln!(buf, "{}", style.value(record.args()))
+    /// });
+    /// ```
+    pub fn set_dimmed(&mut self, yes: bool) -> &mut Style {
+        self.spec.set_dimmed(yes);
+        self
+    }
+
     /// Set the background color.
     ///
     /// # Examples
@@ -453,7 +475,7 @@ impl_styled_value_fmt!(
     fmt::LowerExp
 );
 
-// The `Color` type is copied from https://github.com/BurntSushi/ripgrep/tree/master/termcolor
+// The `Color` type is copied from https://github.com/BurntSushi/termcolor
 
 /// The set of available colors for the terminal foreground/background.
 ///