Skip to content

Commit

Permalink
bug #52941 [Console] Fix xterm detection (theofidry)
Browse files Browse the repository at this point in the history
This PR was merged into the 5.4 branch.

Discussion
----------

[Console] Fix xterm detection

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | None reported
| License       | MIT

Currently `StreamOutput::hasColorSupport()` returns `true` if `TERM=xterm`. However xterm may have different values such as `xterm-256color`.

Technically I think it would be more correct to check `xterm` or starts with `xterm-`, but I am not convinced there is a need to do so and one may prefer the (tiny) performance advantage? This can easily be changed though.

Commits
-------

109c088 fix xterm detection
  • Loading branch information
fabpot committed Dec 8, 2023
2 parents 4496b59 + 109c088 commit 57f60d0
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/Symfony/Component/Console/Output/StreamOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ public function getStream()
return $this->stream;
}

/**
* {@inheritdoc}
*/
protected function doWrite(string $message, bool $newline)
{
if ($newline) {
Expand Down Expand Up @@ -103,7 +100,7 @@ protected function hasColorSupport()
&& @sapi_windows_vt100_support($this->stream))
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| 'xterm' === getenv('TERM');
|| str_starts_with((string) getenv('TERM'), 'xterm');
}

return 'Hyper' === getenv('TERM_PROGRAM')
Expand Down

0 comments on commit 57f60d0

Please sign in to comment.