Skip to content

Commit

Permalink
bug #52940 [Console] Fix color support check on non-Windows platforms…
Browse files Browse the repository at this point in the history
… (theofidry)

This PR was merged into the 5.4 branch.

Discussion
----------

[Console] Fix color support check on non-Windows platforms

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #45917
| License       | MIT

Currently checking the color support based on `ANSICON`, `ConEmuANSI=ON` or `TERM=xTerm` is done only for Widows. I could not find any reason as to why and it does not make much sense as it is. Especially if we consider that `TERM=xTerm` is a term check and we do another one (not Widows specific) which is `TERM_PROGRAM=Hyper`.

This potentially fixes #45917.

This also looks more in line with the intent (based on the title) of #27831 and #27794.

Commits
-------

285518d detect colors on not windows
  • Loading branch information
fabpot committed Dec 8, 2023
2 parents 8c56020 + 285518d commit 7121397
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Symfony/Component/Console/Output/StreamOutput.php
Expand Up @@ -95,15 +95,17 @@ protected function hasColorSupport()
return false;
}

if (\DIRECTORY_SEPARATOR === '\\') {
return (\function_exists('sapi_windows_vt100_support')
&& @sapi_windows_vt100_support($this->stream))
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| str_starts_with((string) getenv('TERM'), 'xterm');
if (\DIRECTORY_SEPARATOR === '\\'
&& \function_exists('sapi_windows_vt100_support')
&& @sapi_windows_vt100_support($this->stream)
) {
return true;
}

return 'Hyper' === getenv('TERM_PROGRAM')
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| str_starts_with((string) getenv('TERM'), 'xterm')
|| stream_isatty($this->stream);
}
}

0 comments on commit 7121397

Please sign in to comment.