@@ -179,6 +179,7 @@ const DEFAULT_PASSTHROUGH_ENVS: &[&str] = &[
179179 "TERM_PROGRAM" ,
180180 "DISPLAY" ,
181181 "FORCE_COLOR" ,
182+ "NO_COLOR" ,
182183 // Temporary directories
183184 "TMP" ,
184185 "TEMP" ,
@@ -275,7 +276,7 @@ impl TaskEnvs {
275276 // Automatically add FORCE_COLOR environment variable if not already set
276277 // This enables color output in subprocesses when color is supported
277278 // TODO: will remove this temporarily until we have a better solution
278- if !all_envs. contains_key ( "FORCE_COLOR" ) {
279+ if !all_envs. contains_key ( "FORCE_COLOR" ) && !all_envs . contains_key ( "NO_COLOR" ) {
279280 if let Some ( support) = on ( Stream :: Stdout ) {
280281 let force_color_value = if support. has_16m {
281282 "3" // True color (16 million colors)
@@ -528,6 +529,23 @@ mod tests {
528529 unsafe {
529530 std:: env:: remove_var ( "FORCE_COLOR" ) ;
530531 }
532+
533+ // Test when NO_COLOR is already set - should not be overridden
534+ unsafe {
535+ std:: env:: set_var ( "NO_COLOR" , "1" ) ;
536+ }
537+
538+ let result3 = TaskEnvs :: resolve ( base_dir, & resolved_task_config) . unwrap ( ) ;
539+ assert ! ( result3. all_envs. contains_key( "NO_COLOR" ) ) ;
540+ let no_color_value = result3. all_envs . get ( "NO_COLOR" ) . unwrap ( ) ;
541+ assert_eq ! ( no_color_value. to_str( ) . unwrap( ) , "1" ) ;
542+ // FORCE_COLOR should not automatically added since NO_COLOR is set
543+ assert ! ( !result3. all_envs. contains_key( "FORCE_COLOR" ) ) ;
544+
545+ // Clean up
546+ unsafe {
547+ std:: env:: remove_var ( "NO_COLOR" ) ;
548+ }
531549 }
532550
533551 #[ test]
0 commit comments