8000 Add new tests and fix problem with the second option being chosen on … · symfony/symfony@2b73975 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2b73975

Browse files
committed
Add new tests and fix problem with the second option being chosen on down arrow
1 parent 8a0bcfb commit 2b73975

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function ask(OutputInterface $output, $question, $default = null, array $
9191
$i = 0;
9292
$matches = array();
9393
$numMatches = 0;
94-
$ofs = 0;
94+
$ofs = -1;
9595

9696
// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
9797
shell_exec('stty -icanon -echo');
@@ -109,6 +109,10 @@ public function ask(OutputInterface $output, $question, $default = null, array $
109109
$output->write("\033[1D");
110110
}
111111

112+
if ($i === 0) {
113+
$ofs = -1;
114+
}
115+
112116
// Erase characters from cursor to end of line
113117
$output->write("\033[K");
114118
$ret = substr($ret, 0, $i);
@@ -126,6 +130,10 @@ public function ask(OutputInterface $output, $question, $default = null, array $
126130
if (0 === $i) {
127131
$matches = $autocomplete;
128132
$numMatches = count($matches);
133+
134+
if ('A' === $c[2] && -1 === $ofs) {
135+
$ofs = 0;
136+
}
129137
}
130138

131139
if (0 === $numMatches) {

src/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,24 @@ public function testAsk()
5555
rewind($output->getStream());
5656
$this->assertEquals('What time is it?', stream_get_contents($output->getStream()));
5757

58-
$bundles = array('AcmeDemoBundle', 'AsseticBundle');
58+
$bundles = array('AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle');
5959

6060
// Acm<NEWLINE>
6161
// Ac<BACKSPACE><BACKSPACE>s<TAB>Test<NEWLINE>
6262
// <NEWLINE>
63-
$inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n");
63+
// <UP ARROW><UP ARROW><NEWLINE>
64+
// <UP ARROW><UP ARROW><UP ARROW><UP ARROW><UP ARROW><TAB><NEWLINE>
65+
// <DOWN ARROW><NEWLINE>
66+
$inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n\033[A\033[A\n\033[A\033[A\033[A\033[A\033[A\tTest\n\033[B\n");
6467
$dialog->setInputStream($inputStream);
6568

6669
if ($this->hasSttyAvailable()) {
6770
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
6871
$this->assertEquals('AsseticBundleTest', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
6972
$this->assertEquals('FrameworkBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
73+
$this->assertEquals('SecurityBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
74+
$this->assertEquals('FooBundleTest', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
75+
$this->assertEquals('AcmeDemoBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles));
7076
} else {
7177
$this->markTestSkipped();
7278
}

0 commit comments

Comments
 (0)
0