Skip to content

Commit c954c57

Browse files
authored
Merge pull request #1747 from kinnison/kinnison/dumb-term-is-ok
term2: Swallow unsupported errors out of term::Error
2 parents 9c172f8 + 2c8cbbb commit c954c57

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/cli/term2.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,24 @@ impl<T: Instantiable + Isatty + io::Write> io::Write for Terminal<T> {
246246
}
247247
}
248248

249+
macro_rules! swallow_unsupported {
250+
( $call:expr ) => {{
251+
use term::Error::*;
252+
match $call {
253+
Ok(()) | Err(ColorOutOfRange) | Err(NotSupported) => Ok(()),
254+
Err(e) => Err(e),
255+
}
256+
}};
257+
}
258+
249259
impl<T: Instantiable + Isatty + io::Write> Terminal<T> {
250260
pub fn fg(&mut self, color: color::Color) -> Result<(), term::Error> {
251261
if !T::isatty() {
252262
return Ok(());
253263
}
254264

255265
if let Some(ref mut t) = self.0 {
256-
t.fg(color)
266+
swallow_unsupported!(t.fg(color))
257267
} else {
258268
Ok(())
259269
}
@@ -268,8 +278,8 @@ impl<T: Instantiable + Isatty + io::Write> Terminal<T> {
268278
if let Err(e) = t.attr(attr) {
269279
// If `attr` is not supported, try to emulate it
270280
match attr {
271-
Attr::Bold => t.fg(color::BRIGHT_WHITE),
272-
_ => Err(e),
281+
Attr::Bold => swallow_unsupported!(t.fg(color::BRIGHT_WHITE)),
282+
_ => swallow_unsupported!(Err(e)),
273283
}
274284
} else {
275285
Ok(())
@@ -285,7 +295,7 @@ impl<T: Instantiable + Isatty + io::Write> Terminal<T> {
285295
}
286296

287297
if let Some(ref mut t) = self.0 {
288-
t.reset()
298+
swallow_unsupported!(t.reset())
289299
} else {
290300
Ok(())
291301
}

0 commit comments

Comments
 (0)