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;