From 2b73975023b6f0a64296ca4641942672d6626374 Mon Sep 17 00:00:00 2001 From: Lee McDermott Date: Sun, 6 Jan 2013 04:05:03 +0000 Subject: [PATCH] Add new tests and fix problem with the second option being chosen on down arrow --- src/Symfony/Component/Console/Helper/DialogHelper.php | 10 +++++++++- .../Console/Tests/Helper/DialogHelperTest.php | 10 ++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Console/Helper/DialogHelper.php b/src/Symfony/Component/Console/Helper/DialogHelper.php index 902fab9cb9..87c9026a31 100644 --- a/src/Symfony/Component/Console/Helper/DialogHelper.php +++ b/src/Symfony/Component/Console/Helper/DialogHelper.php @@ -91,7 +91,7 @@ class DialogHelper extends Helper $i = 0; $matches = array(); $numMatches = 0; - $ofs = 0; + $ofs = -1; // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead) shell_exec('stty -icanon -echo'); @@ -109,6 +109,10 @@ class DialogHelper extends Helper $output->write("\033[1D"); } + if ($i === 0) { + $ofs = -1; + } + // Erase characters from cursor to end of line $output->write("\033[K"); $ret = substr($ret, 0, $i); @@ -126,6 +130,10 @@ class DialogHelper extends Helper if (0 === $i) { $matches = $autocomplete; $numMatches = count($matches); + + if ('A' === $c[2] && -1 === $ofs) { + $ofs = 0; + } } if (0 === $numMatches) { diff --git a/src/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php b/src/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php index 87b47cdfe1..7f91f2225d 100644 --- a/src/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php +++ b/src/Symfony/Component/Console/Tests/Helper/DialogHelperTest.php @@ -55,18 +55,24 @@ class DialogHelperTest extends \PHPUnit_Framework_TestCase rewind($output->getStream()); $this->assertEquals('What time is it?', stream_get_contents($output->getStream())); - $bundles = array('AcmeDemoBundle', 'AsseticBundle'); + $bundles = array('AcmeDemoBundle', 'AsseticBundle', 'SecurityBundle', 'FooBundle'); // Acm // AcsTest // - $inputStream = $this->getInputStream("Acm\nAc\177\177s\tTest\n\n"); + // + // + // + $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"); $dialog->setInputStream($inputStream); if ($this->hasSttyAvailable()) { $this->assertEquals('AcmeDemoBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); $this->assertEquals('AsseticBundleTest', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); $this->assertEquals('FrameworkBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); + $this->assertEquals('SecurityBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); + $this->assertEquals('FooBundleTest', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); + $this->assertEquals('AcmeDemoBundle', $dialog->ask($this->getOutputStream(), 'Please select a bundle', 'FrameworkBundle', $bundles)); } else { $this->markTestSkipped(); }