Fix/normalize tty handling
parent
4b4a3937ea
commit
cc536c7f45
|
@ -129,12 +129,7 @@ class Application extends BaseApplication
|
|||
{
|
||||
$this->disablePluginsByDefault = $input->hasParameterOption('--no-plugins');
|
||||
|
||||
if (
|
||||
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))
|
||||
) {
|
||||
if (getenv('COMPOSER_NO_INTERACTION') || !Platform::isTty(STDIN)) {
|
||||
$input->setInteractive(false);
|
||||
}
|
||||
|
||||
|
|
|
@ -89,4 +89,26 @@ class Platform
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,15 +77,11 @@ class ProcessExecutor
|
|||
*/
|
||||
public function executeTty($command, $cwd = null)
|
||||
{
|
||||
if (
|
||||
/* @see \Composer\Console\Application::doRun - tty test */
|
||||
(function_exists('stream_isatty') && !stream_isatty(STDOUT))
|
||||
|| (function_exists('posix_isatty') && !posix_isatty(STDOUT))
|
||||
) {
|
||||
return $this->doExecute($command, $cwd, false);
|
||||
if (Platform::isTty()) {
|
||||
return $this->doExecute($command, $cwd, true);
|
||||
}
|
||||
|
||||
return $this->doExecute($command, $cwd, true);
|
||||
return $this->doExecute($command, $cwd, false);
|
||||
}
|
||||
|
||||
private function doExecute($command, $cwd, $tty, &$output = null)
|
||||
|
|
Loading…
Reference in New Issue