Replace posix_isatty with cross-platform, always available stream_isatty

This commit is contained in:
Gabriel Ostrolucký 2019-10-06 22:23:12 +02:00
parent 8375c6be4b
commit c9b8b046a7
No known key found for this signature in database
GPG Key ID: 0B618B95BA22CEEF
3 changed files with 6 additions and 24 deletions

View File

@ -864,14 +864,16 @@ class Application implements ResetInterface
if (true === $input->hasParameterOption(['--no-interaction', '-n'], true)) {
$input->setInteractive(false);
} elseif (\function_exists('posix_isatty')) {
} else {
$inputStream = null;
if ($input instanceof StreamableInputInterface) {
$inputStream = $input->getStream();
}
if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) {
$inputStream = !$inputStream && \defined('STDIN') ? STDIN : $inputStream;
if ((!$inputStream || !stream_isatty($inputStream)) && false === getenv('SHELL_INTERACTIVE')) {
$input->setInteractive(false);
}
}

View File

@ -109,16 +109,6 @@ class StreamOutput extends Output
|| 'xterm' === getenv('TERM');
}
if (\function_exists('stream_isatty')) {
return @stream_isatty($this->stream);
}
if (\function_exists('posix_isatty')) {
return @posix_isatty($this->stream);
}
$stat = @fstat($this->stream);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
return stream_isatty($this->stream);
}
}

View File

@ -587,17 +587,7 @@ class CliDumper extends AbstractDumper
|| 'xterm' === getenv('TERM');
}
if (\function_exists('stream_isatty')) {
return @stream_isatty($stream);
}
if (\function_exists('posix_isatty')) {
return @posix_isatty($stream);
}
$stat = @fstat($stream);
// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
return stream_isatty($stream);
}
/**