Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9b6ee6e

Browse files
[Console] dont check tty on stdin, it break with "data lost during stream conversion"
1 parent 2732dda commit 9b6ee6e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/Symfony/Component/Console/Helper/QuestionHelper.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\Console\Output\ConsoleOutputInterface;
2121
use Symfony\Component\Console\Output\ConsoleSectionOutput;
2222
use Symfony\Component\Console\Output\OutputInterface;
23+
use Symfony\Component\Console\Output\StreamOutput;
2324
use Symfony\Component\Console\Question\ChoiceQuestion;
2425
use Symfony\Component\Console\Question\Question;
2526
use Symfony\Component\Console\Terminal;
@@ -462,7 +463,7 @@ private function validateAttempts(callable $interviewer, OutputInterface $output
462463
$error = null;
463464
$attempts = $question->getMaxAttempts();
464465

465-
if (null === $attempts && !$this->isTty()) {
466+
if (null === $attempts && !$this->isTty($output)) {
466467
$attempts = 1;
467468
}
468469

@@ -509,16 +510,22 @@ private function getShell()
509510
return self::$shell;
510511
}
511512

512-
private function isTty(): bool
513+
private function isTty(OutputInterface $output): bool
513514
{
514-
$inputStream = !$this->inputStream && \defined('STDIN') ? STDIN : $this->inputStream;
515+
if (!$output instanceof StreamOutput) {
516+
return true;
517+
}
518+
519+
if (\DIRECTORY_SEPARATOR === '\\' && \function_exists('sapi_windows_vt100_support')) {
520+
return @sapi_windows_vt100_support($output->getSteam());
521+
}
515522

516523
if (\function_exists('stream_isatty')) {
517-
return stream_isatty($inputStream);
524+
return stream_isatty($output->getStream());
518525
}
519526

520527
if (!\function_exists('posix_isatty')) {
521-
return posix_isatty($inputStream);
528+
return posix_isatty($output->getStream());
522529
}
523530

524531
return true;

0 commit comments

Comments
 (0)