Skip to content

Commit

Permalink
fix: Correctly check color support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
theofidry committed Dec 8, 2023
1 parent a314b65 commit d82e498
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Symfony/Component/Console/Output/StreamOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,17 @@ protected function hasColorSupport(): bool
return false;
}

if ('Hyper' === getenv('TERM_PROGRAM')) {
if (\DIRECTORY_SEPARATOR === '\\'
&& \function_exists('sapi_windows_vt100_support'
&& @sapi_windows_vt100_support($this->stream)
) {
return true;

Check failure on line 104 in src/Symfony/Component/Console/Output/StreamOutput.php

View workflow job for this annotation

GitHub Actions / Psalm

ParseError

src/Symfony/Component/Console/Output/StreamOutput.php:104:13: ParseError: Syntax error, unexpected T_RETURN on line 104 (see https://psalm.dev/173)

Check failure on line 104 in src/Symfony/Component/Console/Output/StreamOutput.php

View workflow job for this annotation

GitHub Actions / Psalm

ParseError

src/Symfony/Component/Console/Output/StreamOutput.php:104:13: ParseError: Syntax error, unexpected T_RETURN on line 104 (see https://psalm.dev/173)
}

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

return stream_isatty($this->stream);
return 'Hyper' === getenv('TERM_PROGRAM')

Check failure on line 107 in src/Symfony/Component/Console/Output/StreamOutput.php

View workflow job for this annotation

GitHub Actions / Psalm

ParseError

src/Symfony/Component/Console/Output/StreamOutput.php:107:9: ParseError: Syntax error, unexpected T_RETURN on line 107 (see https://psalm.dev/173)

Check failure on line 107 in src/Symfony/Component/Console/Output/StreamOutput.php

View workflow job for this annotation

GitHub Actions / Psalm

ParseError

src/Symfony/Component/Console/Output/StreamOutput.php:107:9: ParseError: Syntax error, unexpected T_RETURN on line 107 (see https://psalm.dev/173)
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| 'xterm' === getenv('TERM')
|| stream_isatty($this->stream);
}
}

0 comments on commit d82e498

Please sign in to comment.