@@ -63,19 +63,12 @@ impl ColorableTerminal {
6363 /// then color commands will be sent to the stream.
6464 /// Otherwise color commands are discarded.
6565 fn new ( stream : StreamSelector , is_a_tty : bool , process : & Process ) -> Self {
66- let choice = match process. var ( "RUSTUP_TERM_COLOR" ) {
67- Ok ( s) if s. eq_ignore_ascii_case ( "always" ) => ColorChoice :: Always ,
68- Ok ( s) if s. eq_ignore_ascii_case ( "never" ) => ColorChoice :: Never ,
69- _ if is_a_tty => ColorChoice :: Auto ,
70- _ => ColorChoice :: Never ,
71- } ;
66+ let choice = process. color_choice ( is_a_tty) ;
7267 let inner = match stream {
7368 StreamSelector :: Stdout => TerminalInner :: Stdout ( AutoStream :: new ( io:: stdout ( ) , choice) ) ,
7469 StreamSelector :: Stderr => TerminalInner :: Stderr ( AutoStream :: new ( io:: stderr ( ) , choice) ) ,
7570 #[ cfg( feature = "test" ) ]
76- StreamSelector :: TestWriter ( w) => TerminalInner :: TestWriter ( w, choice) ,
77- #[ cfg( all( test, feature = "test" ) ) ]
78- StreamSelector :: TestTtyWriter ( w) => TerminalInner :: TestWriter ( w, choice) ,
71+ StreamSelector :: TestWriter ( w) => TerminalInner :: TestWriter ( w) ,
7972 } ;
8073 let width = process
8174 . var ( "RUSTUP_TERM_WIDTH" )
@@ -114,7 +107,7 @@ impl ColorableTerminal {
114107 TerminalInnerLocked :: Stderr ( AutoStream :: new ( locked, self . color_choice ) )
115108 }
116109 #[ cfg( feature = "test" ) ]
117- TerminalInner :: TestWriter ( w, _ ) => {
110+ TerminalInner :: TestWriter ( w) => {
118111 TerminalInnerLocked :: TestWriter ( StripStream :: new ( Box :: new ( w. clone ( ) ) ) )
119112 }
120113 } ) ;
@@ -290,8 +283,7 @@ enum TerminalInner {
290283 Stdout ( AutoStream < io:: Stdout > ) ,
291284 Stderr ( AutoStream < io:: Stderr > ) ,
292285 #[ cfg( feature = "test" ) ]
293- #[ allow( dead_code) ] // ColorChoice only read in test code
294- TestWriter ( TestWriter , ColorChoice ) ,
286+ TestWriter ( TestWriter ) ,
295287}
296288
297289impl TerminalInner {
@@ -300,7 +292,7 @@ impl TerminalInner {
300292 TerminalInner :: Stdout ( s) => s,
301293 TerminalInner :: Stderr ( s) => s,
302294 #[ cfg( feature = "test" ) ]
303- TerminalInner :: TestWriter ( w, _ ) => w,
295+ TerminalInner :: TestWriter ( w) => w,
304296 }
305297 }
306298}
@@ -311,63 +303,4 @@ pub(super) enum StreamSelector {
311303 Stderr ,
312304 #[ cfg( feature = "test" ) ]
313305 TestWriter ( TestWriter ) ,
314- #[ cfg( all( test, feature = "test" ) ) ]
315- TestTtyWriter ( TestWriter ) ,
316- }
317-
318- #[ cfg( test) ]
319- mod tests {
320- use std:: collections:: HashMap ;
321-
322- use super :: * ;
323- use crate :: process:: TestProcess ;
324- use crate :: test:: Env ;
325-
326- #[ test]
327- fn term_color_choice ( ) {
328- fn assert_color_choice (
329- env_val : & str ,
330- stream : StreamSelector ,
331- is_a_tty : bool ,
332- color_choice : ColorChoice ,
333- ) {
334- let mut vars = HashMap :: new ( ) ;
335- vars. env ( "RUSTUP_TERM_COLOR" , env_val) ;
336- let tp = TestProcess :: with_vars ( vars) ;
337-
338- let term = ColorableTerminal :: new ( stream, is_a_tty, & tp. process ) ;
339- let inner = term. inner . lock ( ) . unwrap ( ) ;
340- assert ! ( matches!(
341- & * inner,
342- & TerminalInner :: TestWriter ( _, choice) if choice == color_choice
343- ) ) ;
344- }
345-
346- assert_color_choice (
347- "aLWayS" ,
348- StreamSelector :: TestWriter ( Default :: default ( ) ) ,
349- false ,
350- ColorChoice :: Always ,
351- ) ;
352- assert_color_choice (
353- "neVer" ,
354- StreamSelector :: TestWriter ( Default :: default ( ) ) ,
355- false ,
356- ColorChoice :: Never ,
357- ) ;
358- // tty + `auto` enables the colors.
359- assert_color_choice (
360- "AutO" ,
361- StreamSelector :: TestTtyWriter ( Default :: default ( ) ) ,
362- true ,
363- ColorChoice :: Auto ,
364- ) ;
365- // non-tty + `auto` does not enable the colors.
366- assert_color_choice (
367- "aUTo" ,
368- StreamSelector :: TestWriter ( Default :: default ( ) ) ,
369- false ,
370- ColorChoice :: Never ,
371- ) ;
372- }
373306}
0 commit comments