@@ -96,11 +96,15 @@ impl Shell {
96
96
/// Creates a new shell (color choice and verbosity), defaulting to 'auto' color and verbose
97
97
/// output.
98
98
pub fn new ( ) -> Shell {
99
- let auto = ColorChoice :: CargoAuto . to_termcolor_color_choice ( ) ;
99
+ let auto_clr = ColorChoice :: CargoAuto ;
100
100
Shell {
101
101
output : ShellOut :: Stream {
102
- stdout : StandardStream :: stdout ( auto) ,
103
- stderr : StandardStream :: stderr ( auto) ,
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
+ ) ,
104
108
color_choice : ColorChoice :: CargoAuto ,
105
109
stderr_tty : atty:: is ( atty:: Stream :: Stderr ) ,
106
110
} ,
@@ -297,9 +301,8 @@ impl Shell {
297
301
) ,
298
302
} ;
299
303
* color_choice = cfg;
300
- let choice = cfg. to_termcolor_color_choice ( ) ;
301
- * stdout = StandardStream :: stdout ( choice) ;
302
- * stderr = StandardStream :: stderr ( choice) ;
304
+ * stdout = StandardStream :: stdout ( cfg. to_termcolor_color_choice ( atty:: Stream :: Stdout ) ) ;
305
+ * stderr = StandardStream :: stderr ( cfg. to_termcolor_color_choice ( atty:: Stream :: Stderr ) ) ;
303
306
}
304
307
Ok ( ( ) )
305
308
}
@@ -323,6 +326,13 @@ impl Shell {
323
326
}
324
327
}
325
328
329
+ pub fn out_supports_color ( & self ) -> bool {
330
+ match & self . output {
331
+ ShellOut :: Write ( _) => false ,
332
+ ShellOut :: Stream { stdout, .. } => stdout. supports_color ( ) ,
333
+ }
334
+ }
335
+
326
336
/// Prints a message to stderr and translates ANSI escape code into console colors.
327
337
pub fn print_ansi_stderr ( & mut self , message : & [ u8 ] ) -> CargoResult < ( ) > {
328
338
if self . needs_clear {
@@ -432,12 +442,12 @@ impl ShellOut {
432
442
433
443
impl ColorChoice {
434
444
/// Converts our color choice to termcolor's version.
435
- fn to_termcolor_color_choice ( self ) -> termcolor:: ColorChoice {
445
+ fn to_termcolor_color_choice ( self , stream : atty :: Stream ) -> termcolor:: ColorChoice {
436
446
match self {
437
447
ColorChoice :: Always => termcolor:: ColorChoice :: Always ,
438
448
ColorChoice :: Never => termcolor:: ColorChoice :: Never ,
439
449
ColorChoice :: CargoAuto => {
440
- if atty:: is ( atty :: Stream :: Stderr ) {
450
+ if atty:: is ( stream ) {
441
451
termcolor:: ColorChoice :: Auto
442
452
} else {
443
453
termcolor:: ColorChoice :: Never
0 commit comments