From 2ba118a36d40744042409074f85a0a7f5fc1571f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 5 May 2020 11:01:49 +0200 Subject: [PATCH] [Console] don't check tty on stdin, it breaks with "data lost during stream conversion" --- .../Component/Console/Helper/QuestionHelper.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/QuestionHelper.php b/src/Symfony/Component/Console/Helper/QuestionHelper.php index 4e0afeae78a0d..4bdb16871fe64 100644 --- a/src/Symfony/Component/Console/Helper/QuestionHelper.php +++ b/src/Symfony/Component/Console/Helper/QuestionHelper.php @@ -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; @@ -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; } @@ -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;