diff --git a/src/cli/term2.rs b/src/cli/term2.rs index 3e63844563..ea7aebee00 100644 --- a/src/cli/term2.rs +++ b/src/cli/term2.rs @@ -246,6 +246,16 @@ impl io::Write for Terminal { } } +macro_rules! swallow_unsupported { + ( $call:expr ) => {{ + use term::Error::*; + match $call { + Ok(()) | Err(ColorOutOfRange) | Err(NotSupported) => Ok(()), + Err(e) => Err(e), + } + }}; +} + impl Terminal { pub fn fg(&mut self, color: color::Color) -> Result<(), term::Error> { if !T::isatty() { @@ -253,7 +263,7 @@ impl Terminal { } if let Some(ref mut t) = self.0 { - t.fg(color) + swallow_unsupported!(t.fg(color)) } else { Ok(()) } @@ -268,8 +278,8 @@ impl Terminal { if let Err(e) = t.attr(attr) { // If `attr` is not supported, try to emulate it match attr { - Attr::Bold => t.fg(color::BRIGHT_WHITE), - _ => Err(e), + Attr::Bold => swallow_unsupported!(t.fg(color::BRIGHT_WHITE)), + _ => swallow_unsupported!(Err(e)), } } else { Ok(()) @@ -285,7 +295,7 @@ impl Terminal { } if let Some(ref mut t) = self.0 { - t.reset() + swallow_unsupported!(t.reset()) } else { Ok(()) }