diff options
author | Andrew Gallant <jamslam@gmail.com> | 2016-11-21 20:33:15 -0500 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2016-11-21 20:33:15 -0500 |
commit | ae592b11e3b5d77a5cd1de02e01b4e370e5d72d6 (patch) | |
tree | 162c3ee368c135adf0aeab3bef16715b40f0569f | |
parent | a5e7f176f18bf61ae2117091de1d323be598c79d (diff) |
Only emit bold ANSI code if bold is true.
This was a simple logic error. Also, avoid emitting ANSI escape codes
if there are no color settings.
Fixes #242
-rw-r--r-- | src/printer.rs | 2 | ||||
-rw-r--r-- | termcolor/src/lib.rs | 7 |
2 files changed, 7 insertions, 2 deletions
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<W: WriteColor> Printer<W> { } 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<W: io::Write> WriteColor for Ansi<W> { 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; |