Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74edb04

Browse files
committed
[Console] Fix color support
1 parent e111a54 commit 74edb04

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Symfony/Component/Console/Output/StreamOutput.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Console\Exception\InvalidArgumentException;
1515
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
16+
use function preg_match;
1617

1718
/**
1819
* StreamOutput writes the output to a given stream.
@@ -106,10 +107,22 @@ protected function hasColorSupport()
106107
return true;
107108
}
108109

109-
return 'Hyper' === getenv('TERM_PROGRAM')
110+
if ('Hyper' === getenv('TERM_PROGRAM')
111+
|| false !== getenv('COLORTERM')
110112
|| false !== getenv('ANSICON')
111113
|| 'ON' === getenv('ConEmuANSI')
112-
|| str_starts_with((string) getenv('TERM'), 'xterm');
114+
) {
115+
return true;
116+
}
117+
118+
$term = (string) getenv('TERM');
119+
120+
if ('dumb' === $term) {
121+
return false;
122+
}
123+
124+
// See https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js#L157
125+
return 1 === @preg_match('/^((xterm|screen|putty|rxvt|linux).*)|(.*-256color(-bce)?)$/', $term);
113126
}
114127

115128
/**

src/Symfony/Component/Console/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=7.2.5",
20+
"ext-pcre": "*",
2021
"symfony/deprecation-contracts": "^2.1|^3",
2122
"symfony/polyfill-mbstring": "~1.0",
2223
"symfony/polyfill-php73": "^1.9",

0 commit comments

Comments
 (0)