@@ -80,6 +80,17 @@ impl TermInfo {
8080
8181 /// Creates a TermInfo for the named terminal.
8282 pub ( crate ) fn from_name ( name : & str ) -> Result < TermInfo , Error > {
83+ if cfg ! ( miri) {
84+ // Avoid all the work of parsing the terminfo (it's pretty slow under Miri), and just
85+ // assume that the standard color codes work (like e.g. the 'colored' crate).
86+ return Ok ( TermInfo {
87+ names : Default :: default ( ) ,
88+ bools : Default :: default ( ) ,
89+ numbers : Default :: default ( ) ,
90+ strings : Default :: default ( ) ,
91+ } ) ;
92+ }
93+
8394 get_dbpath_for_term ( name)
8495 . ok_or_else ( || {
8596 Error :: IoError ( io:: Error :: new ( io:: ErrorKind :: NotFound , "terminfo file not found" ) )
@@ -119,13 +130,22 @@ pub(crate) struct TerminfoTerminal<T> {
119130impl < T : Write + Send > Terminal for TerminfoTerminal < T > {
120131 fn fg ( & mut self , color : color:: Color ) -> io:: Result < bool > {
121132 let color = self . dim_if_necessary ( color) ;
133+ if cfg ! ( miri) && color < 8 {
134+ // The Miri logic for this only works for the most basic 8 colors, which we just assume
135+ // the terminal will support. (`num_colors` is always 0 in Miri, so higher colors will
136+ // just fail. But libtest doesn't use any higher colors anyway.)
137+ return write ! ( self . out, "\x1B [3{color}m" ) . and ( Ok ( true ) ) ;
138+ }
122139 if self . num_colors > color {
123140 return self . apply_cap ( "setaf" , & [ Param :: Number ( color as i32 ) ] ) ;
124141 }
125142 Ok ( false )
126143 }
127144
128145 fn reset ( & mut self ) -> io:: Result < bool > {
146+ if cfg ! ( miri) {
147+ return write ! ( self . out, "\x1B [0m" ) . and ( Ok ( true ) ) ;
148+ }
129149 // are there any terminals that have color/attrs and not sgr0?
130150 // Try falling back to sgr, then op
131151 let cmd = match [ "sgr0" , "sgr" , "op" ] . iter ( ) . find_map ( |cap| self . ti . strings . get ( * cap) ) {
0 commit comments