feature #34252 [Console] Add support for NO_COLOR env var (Seldaek)

This PR was merged into the 4.4 branch.

Discussion
----------

[Console] Add support for NO_COLOR env var

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| License       | MIT
| Doc PR        |

Adds support for https://no-color.org/ - ideally this would be considered a bugfix and added to older releases IMO, but submitting as new feature for now.

cc @johnstevenson

Commits
-------

c1b0a8e956 Add support for NO_COLOR env var
This commit is contained in:
Nicolas Grekas 2019-11-08 17:06:42 +01:00
commit 97577aea66
5 changed files with 17 additions and 0 deletions

View File

@ -357,6 +357,11 @@ class DeprecationErrorHandler
return false;
}
// Follow https://no-color.org/
if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) {
return false;
}
if ('Hyper' === getenv('TERM_PROGRAM')) {
return true;
}

View File

@ -13,6 +13,7 @@ CHANGELOG
* deprecated returning `null` from `Command::execute()`, return `0` instead
* Deprecated the `Application::renderException()` and `Application::doRenderException()` methods,
use `renderThrowable()` and `doRenderThrowable()` instead.
* added support for the `NO_COLOR` env var (https://no-color.org/)
4.3.0
-----

View File

@ -97,6 +97,11 @@ class StreamOutput extends Output
*/
protected function hasColorSupport()
{
// Follow https://no-color.org/
if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) {
return false;
}
if ('Hyper' === getenv('TERM_PROGRAM')) {
return true;
}

View File

@ -10,6 +10,7 @@ CHANGELOG
* added the stamps of a message after it is dispatched in `TraceableMessageBus` and `MessengerDataCollector` collected data
* added `UuidCaster`
* made all casters final
* added support for the `NO_COLOR` env var (https://no-color.org/)
4.3.0
-----

View File

@ -582,6 +582,11 @@ class CliDumper extends AbstractDumper
return false;
}
// Follow https://no-color.org/
if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) {
return false;
}
if ('Hyper' === getenv('TERM_PROGRAM')) {
return true;
}