11use std:: fmt;
22use std:: io:: prelude:: * ;
33
4+ use is_terminal:: IsTerminal ;
45use termcolor:: Color :: { Cyan , Green , Red , Yellow } ;
56use termcolor:: { self , Color , ColorSpec , StandardStream , WriteColor } ;
67
@@ -99,14 +100,10 @@ impl Shell {
99100 let auto_clr = ColorChoice :: CargoAuto ;
100101 Shell {
101102 output : ShellOut :: Stream {
102- stdout : StandardStream :: stdout (
103- auto_clr. to_termcolor_color_choice ( atty:: Stream :: Stdout ) ,
104- ) ,
105- stderr : StandardStream :: stderr (
106- auto_clr. to_termcolor_color_choice ( atty:: Stream :: Stderr ) ,
107- ) ,
103+ stdout : StandardStream :: stdout ( auto_clr. to_termcolor_color_choice ( Stream :: Stdout ) ) ,
104+ stderr : StandardStream :: stderr ( auto_clr. to_termcolor_color_choice ( Stream :: Stderr ) ) ,
108105 color_choice : ColorChoice :: CargoAuto ,
109- stderr_tty : atty :: is ( atty :: Stream :: Stderr ) ,
106+ stderr_tty : std :: io :: stderr ( ) . is_terminal ( ) ,
110107 } ,
111108 verbosity : Verbosity :: Verbose ,
112109 needs_clear : false ,
@@ -301,8 +298,8 @@ impl Shell {
301298 ) ,
302299 } ;
303300 * color_choice = cfg;
304- * stdout = StandardStream :: stdout ( cfg. to_termcolor_color_choice ( atty :: Stream :: Stdout ) ) ;
305- * stderr = StandardStream :: stderr ( cfg. to_termcolor_color_choice ( atty :: Stream :: Stderr ) ) ;
301+ * stdout = StandardStream :: stdout ( cfg. to_termcolor_color_choice ( Stream :: Stdout ) ) ;
302+ * stderr = StandardStream :: stderr ( cfg. to_termcolor_color_choice ( Stream :: Stderr ) ) ;
306303 }
307304 Ok ( ( ) )
308305 }
@@ -496,12 +493,12 @@ impl ShellOut {
496493
497494impl ColorChoice {
498495 /// Converts our color choice to termcolor's version.
499- fn to_termcolor_color_choice ( self , stream : atty :: Stream ) -> termcolor:: ColorChoice {
496+ fn to_termcolor_color_choice ( self , stream : Stream ) -> termcolor:: ColorChoice {
500497 match self {
501498 ColorChoice :: Always => termcolor:: ColorChoice :: Always ,
502499 ColorChoice :: Never => termcolor:: ColorChoice :: Never ,
503500 ColorChoice :: CargoAuto => {
504- if atty :: is ( stream) {
501+ if stream. is_terminal ( ) {
505502 termcolor:: ColorChoice :: Auto
506503 } else {
507504 termcolor:: ColorChoice :: Never
@@ -511,6 +508,20 @@ impl ColorChoice {
511508 }
512509}
513510
511+ enum Stream {
512+ Stdout ,
513+ Stderr ,
514+ }
515+
516+ impl Stream {
517+ fn is_terminal ( self ) -> bool {
518+ match self {
519+ Self :: Stdout => std:: io:: stdout ( ) . is_terminal ( ) ,
520+ Self :: Stderr => std:: io:: stderr ( ) . is_terminal ( ) ,
521+ }
522+ }
523+ }
524+
514525#[ cfg( unix) ]
515526mod imp {
516527 use super :: { Shell , TtyWidth } ;
0 commit comments