Skip to content

Commit ec17108

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: [Console] Fix color support
2 parents 86386d4 + 3da1077 commit ec17108

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Output/StreamOutput.php

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

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

117129
/**

0 commit comments

Comments
 (0)