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
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
}
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`
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(())
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(())
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
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.
///