@@ -9,9 +9,10 @@ use std::{
9
9
pub ( crate ) use termcolor:: Color ;
10
10
use termcolor:: { ColorChoice , ColorSpec , StandardStream , StandardStreamLock , WriteColor } ;
11
11
12
+ use super :: { process, varsource:: VarSource } ;
13
+
12
14
#[ cfg( feature = "test" ) ]
13
15
use super :: filesource:: { TestWriter , TestWriterLock } ;
14
- use super :: process;
15
16
16
17
/// Select what stream to make a terminal on
17
18
pub ( super ) enum StreamSelector {
@@ -73,14 +74,17 @@ enum TerminalInnerLocked {
73
74
}
74
75
75
76
impl ColorableTerminal {
76
- /// Construct a terminal for the selected stream. Colors written to the
77
- /// terminal will be discarded if the stream is not a tty.
77
+ /// Construct a terminal for the selected stream.
78
+ /// Colors written to the terminal will be discarded if the stream is not a tty,
79
+ /// unless the `RUSTUP_TERM_COLOR` override environment variable is set.
78
80
pub ( super ) fn new ( stream : StreamSelector ) -> Self {
79
- let is_a_tty = stream. is_a_tty ( ) ;
80
- let choice = if is_a_tty {
81
- ColorChoice :: Auto
82
- } else {
83
- ColorChoice :: Never
81
+ let env_override = process ( ) . var ( "RUSTUP_TERM_COLOR" ) . ok ( ) ;
82
+ let choice = match env_override. as_deref ( ) {
83
+ Some ( "always" ) => ColorChoice :: Always ,
84
+ Some ( "auto" ) => ColorChoice :: Auto ,
85
+ Some ( "never" ) => ColorChoice :: Never ,
86
+ _ if stream. is_a_tty ( ) => ColorChoice :: Auto ,
87
+ _ => ColorChoice :: Never ,
84
88
} ;
85
89
let inner = match stream {
86
90
StreamSelector :: Stdout => {
0 commit comments