Skip to content

Commit 6542484

Browse files
johnstevensonfabpot
authored andcommitted
Use new PHP7.2 functions in hasColorSupport
1 parent 575971e commit 6542484

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

DeprecationErrorHandler.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,38 @@ public static function register($mode = false)
178178
}
179179
}
180180

181+
/**
182+
* Returns true if STDOUT is defined and supports colorization.
183+
*
184+
* Reference: Composer\XdebugHandler\Process::supportsColor
185+
* https://github.com/composer/xdebug-handler
186+
*
187+
* @return bool
188+
*/
181189
private static function hasColorSupport()
182190
{
183-
if ('\\' === DIRECTORY_SEPARATOR) {
184-
return
185-
defined('STDOUT') && function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT)
186-
|| '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD
191+
if (!defined('STDOUT')) {
192+
return false;
193+
}
194+
195+
if (DIRECTORY_SEPARATOR === '\\') {
196+
return (function_exists('sapi_windows_vt100_support')
197+
&& sapi_windows_vt100_support(STDOUT))
187198
|| false !== getenv('ANSICON')
188199
|| 'ON' === getenv('ConEmuANSI')
189200
|| 'xterm' === getenv('TERM');
190201
}
191202

192-
return defined('STDOUT') && function_exists('posix_isatty') && @posix_isatty(STDOUT);
203+
if (function_exists('stream_isatty')) {
204+
return stream_isatty(STDOUT);
205+
}
206+
207+
if (function_exists('posix_isatty')) {
208+
return posix_isatty(STDOUT);
209+
}
210+
211+
$stat = fstat(STDOUT);
212+
// Check if formatted mode is S_IFCHR
213+
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
193214
}
194215
}

0 commit comments

Comments
 (0)