1
1
use std:: fmt;
2
2
use std:: io:: prelude:: * ;
3
3
4
+ use is_terminal:: IsTerminal ;
4
5
use termcolor:: Color :: { Cyan , Green , Red , Yellow } ;
5
6
use termcolor:: { self , Color , ColorSpec , StandardStream , WriteColor } ;
6
7
@@ -99,14 +100,10 @@ impl Shell {
99
100
let auto_clr = ColorChoice :: CargoAuto ;
100
101
Shell {
101
102
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 ) ) ,
108
105
color_choice : ColorChoice :: CargoAuto ,
109
- stderr_tty : atty :: is ( atty :: Stream :: Stderr ) ,
106
+ stderr_tty : std :: io :: stderr ( ) . is_terminal ( ) ,
110
107
} ,
111
108
verbosity : Verbosity :: Verbose ,
112
109
needs_clear : false ,
@@ -301,8 +298,8 @@ impl Shell {
301
298
) ,
302
299
} ;
303
300
* 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 ) ) ;
306
303
}
307
304
Ok ( ( ) )
308
305
}
@@ -496,12 +493,12 @@ impl ShellOut {
496
493
497
494
impl ColorChoice {
498
495
/// 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 {
500
497
match self {
501
498
ColorChoice :: Always => termcolor:: ColorChoice :: Always ,
502
499
ColorChoice :: Never => termcolor:: ColorChoice :: Never ,
503
500
ColorChoice :: CargoAuto => {
504
- if atty :: is ( stream) {
501
+ if stream. is_terminal ( ) {
505
502
termcolor:: ColorChoice :: Auto
506
503
} else {
507
504
termcolor:: ColorChoice :: Never
@@ -511,6 +508,20 @@ impl ColorChoice {
511
508
}
512
509
}
513
510
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
+
514
525
#[ cfg( unix) ]
515
526
mod imp {
516
527
use super :: { Shell , TtyWidth } ;
0 commit comments