handles multi-byte characters in autocomplete
This commit is contained in:
parent
5ad1f370b0
commit
47320a63e2
@ -308,6 +308,10 @@ class QuestionHelper extends Helper
|
|||||||
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
if ("\x80" <= $c) {
|
||||||
|
$c .= fread($inputStream, ["\xC0" => 1, "\xD0" => 1, "\xE0" => 2, "\xF0" => 3][$c & "\xF0"]);
|
||||||
|
}
|
||||||
|
|
||||||
$output->write($c);
|
$output->write($c);
|
||||||
$ret .= $c;
|
$ret .= $c;
|
||||||
++$i;
|
++$i;
|
||||||
|
@ -237,6 +237,43 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
|
|||||||
$this->assertSame('b', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
$this->assertSame('b', $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getInputs()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['$'], // 1 byte character
|
||||||
|
['¢'], // 2 bytes character
|
||||||
|
['€'], // 3 bytes character
|
||||||
|
['𐍈'], // 4 bytes character
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getInputs
|
||||||
|
*/
|
||||||
|
public function testAskWithAutocompleteWithMultiByteCharacter($character)
|
||||||
|
{
|
||||||
|
if (!$this->hasSttyAvailable()) {
|
||||||
|
$this->markTestSkipped('`stty` is required to test autocomplete functionality');
|
||||||
|
}
|
||||||
|
|
||||||
|
$inputStream = $this->getInputStream("$character\n");
|
||||||
|
|
||||||
|
$possibleChoices = [
|
||||||
|
'$' => '1 byte character',
|
||||||
|
'¢' => '2 bytes character',
|
||||||
|
'€' => '3 bytes character',
|
||||||
|
'𐍈' => '4 bytes character',
|
||||||
|
];
|
||||||
|
|
||||||
|
$dialog = new QuestionHelper();
|
||||||
|
$dialog->setHelperSet(new HelperSet([new FormatterHelper()]));
|
||||||
|
|
||||||
|
$question = new ChoiceQuestion('Please select a character', $possibleChoices);
|
||||||
|
$question->setMaxAttempts(1);
|
||||||
|
|
||||||
|
$this->assertSame($character, $dialog->ask($this->createStreamableInputInterfaceMock($inputStream), $this->createOutputInterface(), $question));
|
||||||
|
}
|
||||||
|
|
||||||
public function testAutocompleteWithTrailingBackslash()
|
public function testAutocompleteWithTrailingBackslash()
|
||||||
{
|
{
|
||||||
if (!$this->hasSttyAvailable()) {
|
if (!$this->hasSttyAvailable()) {
|
||||||
|
Reference in New Issue
Block a user