Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 84ae858

Browse filesBrowse files
committed
bug #53707 [Console] Fix color support for TTY output (theofidry)
This PR was merged into the 5.4 branch. Discussion ---------- [Console] Fix color support for TTY output | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix #53693 | License | MIT Prior to #53576, the output being a TTY was sufficient to consider the output as supporting colors. This is not enough but as a result, we are missing some additional checks. This PR: - Adds a check for the `COLORTERM` environment variable. From what I've found it does not look this variable is ever set if there is no color support. - Adds a check for the `screen-*` `TERM` values. Similar to the check we already for `xterm`, you have `screen-256color`, `screen-256color-bce`, `screen.xterm-256color` or more. Commits ------- 22efcd0 [Console] Fix color support
2 parents f7f83bc + 22efcd0 commit 84ae858
Copy full SHA for 84ae858

File tree

1 file changed

+14
-2
lines changed
Filter options

1 file changed

+14
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Output/StreamOutput.php
+14-2Lines 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
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.