@@ -80,6 +80,17 @@ impl TermInfo {
80
80
81
81
/// Creates a TermInfo for the named terminal.
82
82
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
+
83
94
get_dbpath_for_term ( name)
84
95
. ok_or_else ( || {
85
96
Error :: IoError ( io:: Error :: new ( io:: ErrorKind :: NotFound , "terminfo file not found" ) )
@@ -119,13 +130,22 @@ pub(crate) struct TerminfoTerminal<T> {
119
130
impl < T : Write + Send > Terminal for TerminfoTerminal < T > {
120
131
fn fg ( & mut self , color : color:: Color ) -> io:: Result < bool > {
121
132
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
+ }
122
139
if self . num_colors > color {
123
140
return self . apply_cap ( "setaf" , & [ Param :: Number ( color as i32 ) ] ) ;
124
141
}
125
142
Ok ( false )
126
143
}
127
144
128
145
fn reset ( & mut self ) -> io:: Result < bool > {
146
+ if cfg ! ( miri) {
147
+ return write ! ( self . out, "\x1B [0m" ) . and ( Ok ( true ) ) ;
148
+ }
129
149
// are there any terminals that have color/attrs and not sgr0?
130
150
// Try falling back to sgr, then op
131
151
let cmd = match [ "sgr0" , "sgr" , "op" ] . iter ( ) . find_map ( |cap| self . ti . strings . get ( * cap) ) {
0 commit comments