diff options
Diffstat (limited to '')
-rw-r--r-- | library/test/src/term.rs | 2 | ||||
-rw-r--r-- | library/test/src/term/terminfo/mod.rs | 20 | ||||
-rw-r--r-- | library/test/src/term/win.rs | 7 |
3 files changed, 24 insertions, 5 deletions
diff --git a/library/test/src/term.rs b/library/test/src/term.rs index b256ab7b8..a14b0d4f5 100644 --- a/library/test/src/term.rs +++ b/library/test/src/term.rs @@ -39,7 +39,7 @@ pub(crate) fn stdout() -> Option<Box<StdoutTerminal>> { pub(crate) fn stdout() -> Option<Box<StdoutTerminal>> { TerminfoTerminal::new(io::stdout()) .map(|t| Box::new(t) as Box<StdoutTerminal>) - .or_else(|| WinConsole::new(io::stdout()).ok().map(|t| Box::new(t) as Box<StdoutTerminal>)) + .or_else(|| Some(Box::new(WinConsole::new(io::stdout())) as Box<StdoutTerminal>)) } /// Terminal color definitions diff --git a/library/test/src/term/terminfo/mod.rs b/library/test/src/term/terminfo/mod.rs index 694473f52..355859019 100644 --- a/library/test/src/term/terminfo/mod.rs +++ b/library/test/src/term/terminfo/mod.rs @@ -80,6 +80,17 @@ impl TermInfo { /// Creates a TermInfo for the named terminal. pub(crate) fn from_name(name: &str) -> Result<TermInfo, Error> { + if cfg!(miri) { + // Avoid all the work of parsing the terminfo (it's pretty slow under Miri), and just + // assume that the standard color codes work (like e.g. the 'colored' crate). + return Ok(TermInfo { + names: Default::default(), + bools: Default::default(), + numbers: Default::default(), + strings: Default::default(), + }); + } + get_dbpath_for_term(name) .ok_or_else(|| { Error::IoError(io::Error::new(io::ErrorKind::NotFound, "terminfo file not found")) @@ -119,6 +130,12 @@ pub(crate) struct TerminfoTerminal<T> { impl<T: Write + Send> Terminal for TerminfoTerminal<T> { fn fg(&mut self, color: color::Color) -> io::Result<bool> { let color = self.dim_if_necessary(color); + if cfg!(miri) && color < 8 { + // The Miri logic for this only works for the most basic 8 colors, which we just assume + // the terminal will support. (`num_colors` is always 0 in Miri, so higher colors will + // just fail. But libtest doesn't use any higher colors anyway.) + return write!(self.out, "\x1B[3{color}m").and(Ok(true)); + } if self.num_colors > color { return self.apply_cap("setaf", &[Param::Number(color as i32)]); } @@ -126,6 +143,9 @@ impl<T: Write + Send> Terminal for TerminfoTerminal<T> { } fn reset(&mut self) -> io::Result<bool> { + if cfg!(miri) { + return write!(self.out, "\x1B[0m").and(Ok(true)); + } // are there any terminals that have color/attrs and not sgr0? // Try falling back to sgr, then op let cmd = match ["sgr0", "sgr", "op"].iter().find_map(|cap| self.ti.strings.get(*cap)) { diff --git a/library/test/src/term/win.rs b/library/test/src/term/win.rs index 4bdbd6ee7..55020141a 100644 --- a/library/test/src/term/win.rs +++ b/library/test/src/term/win.rs @@ -113,8 +113,7 @@ impl<T: Write + Send + 'static> WinConsole<T> { } } - /// Returns `None` whenever the terminal cannot be created for some reason. - pub(crate) fn new(out: T) -> io::Result<WinConsole<T>> { + pub(crate) fn new(out: T) -> WinConsole<T> { use std::mem::MaybeUninit; let fg; @@ -132,13 +131,13 @@ impl<T: Write + Send + 'static> WinConsole<T> { bg = color::BLACK; } } - Ok(WinConsole { + WinConsole { buf: out, def_foreground: fg, def_background: bg, foreground: fg, background: bg, - }) + } } } |