Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8e40814

Browse filesBrowse files
bug #37007 [Console] Fix QuestionHelper::disableStty() (chalasr)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] Fix QuestionHelper::disableStty() | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no> | Tickets | - | License | MIT | Doc PR | - We broke it when adding `Terminal::hasSttyAvailable()`. Let's fix it on 3.4 and move it to terminal on master, as suggested in #36977 Commits ------- 5d93b61 [Console] Fix QuestionHelper::disableStty()
2 parents ca66e6c + 5d93b61 commit 8e40814
Copy full SHA for 8e40814

File tree

2 files changed

+33
-3
lines changed
Filter options

2 files changed

+33
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Helper/QuestionHelper.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class QuestionHelper extends Helper
3232
{
3333
private $inputStream;
3434
private static $shell;
35-
private static $stty;
35+
private static $stty = true;
3636

3737
/**
3838
* Asks a question to the user.
@@ -158,7 +158,7 @@ private function doAsk(OutputInterface $output, Question $question)
158158
$inputStream = $this->inputStream ?: STDIN;
159159
$autocomplete = $question->getAutocompleterValues();
160160

161-
if (null === $autocomplete || !Terminal::hasSttyAvailable()) {
161+
if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) {
162162
$ret = false;
163163
if ($question->isHidden()) {
164164
try {
@@ -424,7 +424,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream)
424424
return $value;
425425
}
426426

427-
if (Terminal::hasSttyAvailable()) {
427+
if (self::$stty && Terminal::hasSttyAvailable()) {
428428
$sttyMode = shell_exec('stty -g');
429429

430430
shell_exec('stty -echo');

‎src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/Helper/QuestionHelperTest.php
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Console\Tests\Helper;
1313

14+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1415
use Symfony\Component\Console\Formatter\OutputFormatter;
1516
use Symfony\Component\Console\Helper\FormatterHelper;
1617
use Symfony\Component\Console\Helper\HelperSet;
@@ -1013,6 +1014,35 @@ public function testTraversableAutocomplete()
10131014
$this->assertEquals('FooBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
10141015
}
10151016

1017+
public function testDisableSttby()
1018+
{
1019+
if (!Terminal::hasSttyAvailable()) {
1020+
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
1021+
}
1022+
1023+
$this->expectException(InvalidArgumentException::class);
1024+
$this->expectExceptionMessage('invalid');
1025+
1026+
QuestionHelper::disableStty();
1027+
$dialog = new QuestionHelper();
1028+
$dialog->setHelperSet(new HelperSet([new FormatterHelper()]));
1029+
1030+
$question = new ChoiceQuestion('Please select a bundle', [1 => 'AcmeDemoBundle', 4 => 'AsseticBundle']);
1031+
$question->setMaxAttempts(1);
1032+
1033+
// <UP ARROW><UP ARROW><NEWLINE><DOWN ARROW><DOWN ARROW><NEWLINE>
1034+
// Gives `AcmeDemoBundle` with stty
1035+
$inputStream = $this->getInputStream("\033[A\033[A\n\033[B\033[B\n");
1036+
1037+
try {
1038+
$dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question);
1039+
} finally {
1040+
$reflection = new \ReflectionProperty(QuestionHelper::class, 'stty');
1041+
$reflection->setAccessible(true);
1042+
$reflection->setValue(null, true);
1043+
}
1044+
}
1045+
10161046
public function testTraversableMultiselectAutocomplete()
10171047
{
10181048
// <NEWLINE>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.