1
0
Fork 0

Fix/normalize tty handling

pull/9469/head
Jordi Boggiano 2020-11-13 08:58:06 +01:00
parent 4b4a3937ea
commit cc536c7f45
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
3 changed files with 26 additions and 13 deletions

View File

@ -129,12 +129,7 @@ class Application extends BaseApplication
{ {
$this->disablePluginsByDefault = $input->hasParameterOption('--no-plugins'); $this->disablePluginsByDefault = $input->hasParameterOption('--no-plugins');
if ( if (getenv('COMPOSER_NO_INTERACTION') || !Platform::isTty(STDIN)) {
getenv('COMPOSER_NO_INTERACTION')
/* @see \Composer\Util\ProcessExecutor::executeTty - tty test */
|| (function_exists('stream_isatty') && !stream_isatty(STDOUT))
|| (function_exists('posix_isatty') && !posix_isatty(STDOUT))
) {
$input->setInteractive(false); $input->setInteractive(false);
} }

View File

@ -89,4 +89,26 @@ class Platform
return \strlen($str); return \strlen($str);
} }
public static function isTty($fd = null)
{
if ($fd === null) {
$fd = STDOUT;
}
// 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);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
}
} }

View File

@ -77,15 +77,11 @@ class ProcessExecutor
*/ */
public function executeTty($command, $cwd = null) public function executeTty($command, $cwd = null)
{ {
if ( if (Platform::isTty()) {
/* @see \Composer\Console\Application::doRun - tty test */ return $this->doExecute($command, $cwd, true);
(function_exists('stream_isatty') && !stream_isatty(STDOUT))
|| (function_exists('posix_isatty') && !posix_isatty(STDOUT))
) {
return $this->doExecute($command, $cwd, false);
} }
return $this->doExecute($command, $cwd, true); return $this->doExecute($command, $cwd, false);
} }
private function doExecute($command, $cwd, $tty, &$output = null) private function doExecute($command, $cwd, $tty, &$output = null)