Skip to content

Commit

Permalink
[Console] dont check tty on stdin, it break with "data lost during st…
Browse files Browse the repository at this point in the history
…ream conversion"
  • Loading branch information
nicolas-grekas committed May 5, 2020
1 parent 2732dda commit 9b6ee6e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Symfony/Component/Console/Helper/QuestionHelper.php
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Terminal;
Expand Down Expand Up @@ -462,7 +463,7 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
$error = null;
$attempts = $question->getMaxAttempts();

if (null === $attempts && !$this->isTty()) {
if (null === $attempts && !$this->isTty($output)) {
$attempts = 1;
}

Expand Down Expand Up @@ -509,16 +510,22 @@ private function getShell()
return self::$shell;
}

private function isTty(): bool
private function isTty(OutputInterface $output): bool
{
$inputStream = !$this->inputStream && \defined('STDIN') ? STDIN : $this->inputStream;
if (!$output instanceof StreamOutput) {
return true;
}

if (\DIRECTORY_SEPARATOR === '\\' && \function_exists('sapi_windows_vt100_support')) {
return @sapi_windows_vt100_support($output->getSteam());
}

if (\function_exists('stream_isatty')) {
return stream_isatty($inputStream);
return stream_isatty($output->getStream());
}

if (!\function_exists('posix_isatty')) {
return posix_isatty($inputStream);
return posix_isatty($output->getStream());
}

return true;
Expand Down

0 comments on commit 9b6ee6e

Please sign in to comment.