@@ -51,7 +51,23 @@ impl ColorableTerminal {
5151 /// then color commands will be sent to the stream.
5252 /// Otherwise color commands are discarded.
5353 fn new ( stream : StreamSelector , process : & Process ) -> Self {
54- let is_a_tty = stream. is_a_tty ( process) ;
54+ let is_a_tty = match stream {
55+ StreamSelector :: Stdout => match process {
56+ Process :: OsProcess ( p) => p. stdout_is_a_tty ,
57+ #[ cfg( feature = "test" ) ]
58+ Process :: TestProcess ( _) => unreachable ! ( ) ,
59+ } ,
60+ StreamSelector :: Stderr => match process {
61+ Process :: OsProcess ( p) => p. stderr_is_a_tty ,
62+ #[ cfg( feature = "test" ) ]
63+ Process :: TestProcess ( _) => unreachable ! ( ) ,
64+ } ,
65+ #[ cfg( feature = "test" ) ]
66+ StreamSelector :: TestWriter ( _) => false ,
67+ #[ cfg( all( test, feature = "test" ) ) ]
68+ StreamSelector :: TestTtyWriter ( _) => true ,
69+ } ;
70+
5571 let choice = match process. var ( "RUSTUP_TERM_COLOR" ) {
5672 Ok ( s) if s. eq_ignore_ascii_case ( "always" ) => ColorChoice :: Always ,
5773 Ok ( s) if s. eq_ignore_ascii_case ( "never" ) => ColorChoice :: Never ,
@@ -304,27 +320,6 @@ pub(super) enum StreamSelector {
304320 TestTtyWriter ( TestWriter ) ,
305321}
306322
307- impl StreamSelector {
308- fn is_a_tty ( & self , process : & Process ) -> bool {
309- match self {
310- StreamSelector :: Stdout => match process {
311- Process :: OsProcess ( p) => p. stdout_is_a_tty ,
312- #[ cfg( feature = "test" ) ]
313- Process :: TestProcess ( _) => unreachable ! ( ) ,
314- } ,
315- StreamSelector :: Stderr => match process {
316- Process :: OsProcess ( p) => p. stderr_is_a_tty ,
317- #[ cfg( feature = "test" ) ]
318- Process :: TestProcess ( _) => unreachable ! ( ) ,
319- } ,
320- #[ cfg( feature = "test" ) ]
321- StreamSelector :: TestWriter ( _) => false ,
322- #[ cfg( all( test, feature = "test" ) ) ]
323- StreamSelector :: TestTtyWriter ( _) => true ,
324- }
325- }
326- }
327-
328323#[ cfg( test) ]
329324mod tests {
330325 use std:: collections:: HashMap ;
0 commit comments