Browse Source

Add support for NO_COLOR environment variable.

Based on the recommendations on https://no-color.org/

Refs #14147
Mark Story 6 years ago
parent
commit
6885023407
2 changed files with 12 additions and 0 deletions
  1. 3 0
      src/Console/ConsoleOutput.php
  2. 9 0
      tests/TestCase/Console/ConsoleOutputTest.php

+ 3 - 0
src/Console/ConsoleOutput.php

@@ -175,6 +175,9 @@ class ConsoleOutput
             (
                 function_exists('posix_isatty') &&
                 !posix_isatty($this->_output)
+            ) ||
+            (
+                env('NO_COLOR') !== null
             )
         ) {
             $this->_outputAs = self::PLAIN;

+ 9 - 0
tests/TestCase/Console/ConsoleOutputTest.php

@@ -56,6 +56,15 @@ class ConsoleOutputTest extends TestCase
         unset($this->output);
     }
 
+    public function testNoColorEnvironmentVariable()
+    {
+        $_SERVER['NO_COLOR'] = '1';
+        $output = new ConsoleOutput();
+        $this->assertSame(ConsoleOutput::PLAIN, $output->getOutputAs());
+
+        unset($_SERVER['NO_COLOR']);
+    }
+
     /**
      * test writing with no new line
      *