8000 [Console] Fix color support · symfony/symfony@50b0051 · GitHub
[go: up one dir, main page]

Skip to content

Commit 50b0051

Browse files
committed
[Console] Fix color support
1 parent e111a54 commit 50b0051

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,22 @@ protected function hasColorSupport()
106106
return true;
107107
}
108108

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

115127
/**

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)
0