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
-------
5d93b61278
[Console] Fix QuestionHelper::disableStty()
This commit is contained in:
commit
8e40814164
@ -32,7 +32,7 @@ class QuestionHelper extends Helper
|
||||
{
|
||||
private $inputStream;
|
||||
private static $shell;
|
||||
private static $stty;
|
||||
private static $stty = true;
|
||||
|
||||
/**
|
||||
* Asks a question to the user.
|
||||
@ -158,7 +158,7 @@ class QuestionHelper extends Helper
|
||||
$inputStream = $this->inputStream ?: STDIN;
|
||||
$autocomplete = $question->getAutocompleterValues();
|
||||
|
||||
if (null === $autocomplete || !Terminal::hasSttyAvailable()) {
|
||||
if (null === $autocomplete || !self::$stty || !Terminal::hasSttyAvailable()) {
|
||||
$ret = false;
|
||||
if ($question->isHidden()) {
|
||||
try {
|
||||
@ -424,7 +424,7 @@ class QuestionHelper extends Helper
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (Terminal::hasSttyAvailable()) {
|
||||
if (self::$stty && Terminal::hasSttyAvailable()) {
|
||||
$sttyMode = shell_exec('stty -g');
|
||||
|
||||
shell_exec('stty -echo');
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
@ -1013,6 +1014,35 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
||||
$this->assertEquals('FooBundle', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||
}
|
||||
|
||||
public function testDisableSttby()
|
||||
{
|
||||
if (!Terminal::hasSttyAvailable()) {
|
||||
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||
}
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('invalid');
|
||||
|
||||
QuestionHelper::disableStty();
|
||||
$dialog = new QuestionHelper();
|
||||
$dialog->setHelperSet(new HelperSet([new FormatterHelper()]));
|
||||
|
||||
$question = new ChoiceQuestion('Please select a bundle', [1 => 'AcmeDemoBundle', 4 => 'AsseticBundle']);
|
||||
$question->setMaxAttempts(1);
|
||||
|
||||
// <UP ARROW><UP ARROW><NEWLINE><DOWN ARROW><DOWN ARROW><NEWLINE>
|
||||
// Gives `AcmeDemoBundle` with stty
|
||||
$inputStream = $this->getInputStream("\033[A\033[A\n\033[B\033[B\n");
|
||||
|
||||
try {
|
||||
$dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question);
|
||||
} finally {
|
||||
$reflection = new \ReflectionProperty(QuestionHelper::class, 'stty');
|
||||
$reflection->setAccessible(true);
|
||||
$reflection->setValue(null, true);
|
||||
}
|
||||
}
|
||||
|
||||
public function testTraversableMultiselectAutocomplete()
|
||||
{
|
||||
// <NEWLINE>
|
||||
|
Reference in New Issue
Block a user