@@ -11,7 +11,7 @@ use termcolor::{ColorChoice, ColorSpec, StandardStream, StandardStreamLock, Writ
1111
1212#[ cfg( feature = "test" ) ]
1313use super :: filesource:: { TestWriter , TestWriterLock } ;
14- use super :: process;
14+ use super :: { process, varsource :: VarSource } ;
1515
1616/// Select what stream to make a terminal on
1717pub ( super ) enum StreamSelector {
@@ -73,14 +73,18 @@ enum TerminalInnerLocked {
7373}
7474
7575impl 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.
7881 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 ,
8488 } ;
8589 let inner = match stream {
8690 StreamSelector :: Stdout => {
0 commit comments