Skip to content

Commit

Permalink
[Console] Fix color support
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Feb 2, 2024
1 parent e111a54 commit 50b0051
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Symfony/Component/Console/Output/StreamOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,22 @@ protected function hasColorSupport()
return true;
}

return 'Hyper' === getenv('TERM_PROGRAM')
if ('Hyper' === getenv('TERM_PROGRAM')
|| false !== getenv('COLORTERM')
|| false !== getenv('ANSICON')
|| 'ON' === getenv('ConEmuANSI')
|| str_starts_with((string) getenv('TERM'), 'xterm');
) {
return true;
}

$term = (string) getenv('TERM');

if ('dumb' === $term) {
return false;
}

// See https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js#L157
return 1 === @preg_match('/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/', $term);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Console/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": ">=7.2.5",
"ext-pcre": "*",
"symfony/deprecation-contracts": "^2.1|^3",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php73": "^1.9",
Expand Down

0 comments on commit 50b0051

Please sign in to comment.