function Platform::isTty
Parameters
?resource $fd Open file descriptor or null to default to STDOUT:
2 calls to Platform::isTty()
- Application::doRun in vendor/
composer/ composer/ src/ Composer/ Console/ Application.php - Runs the current application.
- ProcessExecutor::executeTty in vendor/
composer/ composer/ src/ Composer/ Util/ ProcessExecutor.php - runs a process on the commandline in TTY mode
File
-
vendor/
composer/ composer/ src/ Composer/ Util/ Platform.php, line 248
Class
- Platform
- Platform helper for uniform platform-specific tests.
Namespace
Composer\UtilCode
public static function isTty($fd = null) : bool {
if ($fd === null) {
$fd = defined('STDOUT') ? STDOUT : fopen('php://stdout', 'w');
if ($fd === false) {
return false;
}
}
// detect msysgit/mingw and assume this is a tty because detection
// does not work correctly, see https://github.com/composer/composer/issues/9690
if (in_array(strtoupper((string) self::getEnv('MSYSTEM')), [
'MINGW32',
'MINGW64',
], true)) {
return true;
}
// modern cross-platform function, includes the fstat
// fallback so if it is present we trust it
if (function_exists('stream_isatty')) {
return stream_isatty($fd);
}
// only trusting this if it is positive, otherwise prefer fstat fallback
if (function_exists('posix_isatty') && posix_isatty($fd)) {
return true;
}
$stat = @fstat($fd);
if ($stat === false) {
return false;
}
// Check if formatted mode is S_IFCHR
return 020000 === ($stat['mode'] & 0170000);
}