@@ -11,7 +11,7 @@ use termcolor::{ColorChoice, ColorSpec, StandardStream, StandardStreamLock, Writ
11
11
12
12
#[ cfg( feature = "test" ) ]
13
13
use super :: filesource:: { TestWriter , TestWriterLock } ;
14
- use super :: process;
14
+ use super :: { process, varsource :: VarSource } ;
15
15
16
16
/// Select what stream to make a terminal on
17
17
pub ( super ) enum StreamSelector {
@@ -73,14 +73,18 @@ enum TerminalInnerLocked {
73
73
}
74
74
75
75
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.
76
+ /// A terminal that supports colorisation of a stream.
77
+ /// If `RUSTUP_TERM_COLOR` is set to `always`, or if the stream is a tty and
78
+ /// `RUSTUP_TERM_COLOR` either unset or set to `auto`,
79
+ /// then color commands will be sent to the stream.
80
+ /// Otherwise color commands are discarded.
78
81
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
82
+ let env_override = process ( ) . var ( "RUSTUP_TERM_COLOR" ) ;
83
+ let choice = match env_override. as_deref ( ) {
84
+ Ok ( "always" ) => ColorChoice :: Always ,
85
+ Ok ( "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