diff --git a/src/printer.rs b/src/printer.rs index 4c04c0ee..0a75f949 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -260,7 +260,7 @@ impl Printer { } fn write_matched_line(&mut self, re: &Regex, buf: &[u8]) { - if !self.wtr.supports_color() { + if !self.wtr.supports_color() || self.colors.matched().is_none() { self.write(buf); return; } diff --git a/termcolor/src/lib.rs b/termcolor/src/lib.rs index efaffbd2..fb93fa49 100644 --- a/termcolor/src/lib.rs +++ b/termcolor/src/lib.rs @@ -764,7 +764,7 @@ impl WriteColor for Ansi { if let Some(ref c) = spec.bg_color { try!(self.write_color(false, c, spec.bold)); } - if spec.fg_color.is_none() && spec.bg_color.is_none() { + if spec.bold && spec.fg_color.is_none() && spec.bg_color.is_none() { try!(self.write_str("\x1B[1m")); } Ok(()) @@ -969,6 +969,11 @@ impl ColorSpec { self } + /// Returns true if this color specification has no colors or styles. + pub fn is_none(&self) -> bool { + self.fg_color.is_none() && self.bg_color.is_none() && !self.bold + } + /// Clears this color specification so that it has no color/style settings. pub fn clear(&mut self) { self.fg_color = None;