diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 698ebfd46..d3e668c93 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -84,8 +84,6 @@ class FileDownloader implements DownloaderInterface if ($checksum && hash_file('sha1', $fileName) !== $checksum) { throw new \UnexpectedValueException('The checksum verification of the file failed (downloaded from '.$url.')'); } - - $this->io->write(''); } /** diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index e1d33b5d2..30c80355c 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -31,6 +31,7 @@ class ConsoleIO implements IOInterface protected $authorizations = array(); protected $lastUsername; protected $lastPassword; + protected $lastMessage; /** * Constructor. @@ -60,31 +61,40 @@ class ConsoleIO implements IOInterface public function write($messages, $newline = true) { $this->output->write($messages, $newline); + $this->lastMessage = join($newline ? "\n" : '', (array) $messages); } /** * {@inheritDoc} */ - public function overwrite($messages, $newline = true, $size = 80) + public function overwrite($messages, $newline = true, $size = null) { - for ($place = $size; $place > 0; $place--) { - $this->write("\x08", false); - } + // messages can be an array, let's convert it to string anyway + $messages = join($newline ? "\n" : '', (array) $messages); + // since overwrite is supposed to overwrite last message... + if (!isset($size)) { + // removing possible formatting of lastMessage with strip_tags + $size = strlen(strip_tags($this->lastMessage)); + } + // ...let's fill its length with backspaces + $this->write(str_repeat("\x08", $size), false); + + // write the new message $this->write($messages, false); - for ($place = ($size - strlen($messages)); $place > 0; $place--) { - $this->write(' ', false); - } - - // clean up the end line - for ($place = ($size - strlen($messages)); $place > 0; $place--) { - $this->write("\x08", false); + $fill = $size - strlen(strip_tags($messages)); + if ($fill > 0) { + // whitespace whatever has left + $this->write(str_repeat(' ', $fill), false); + // move the cursor back + $this->write(str_repeat("\x08", $fill), false); } if ($newline) { $this->write(''); } + $this->lastMessage = $messages; } /** diff --git a/src/Composer/Util/RemoteFilesystem.php b/src/Composer/Util/RemoteFilesystem.php index 80538e5c6..87d725037 100644 --- a/src/Composer/Util/RemoteFilesystem.php +++ b/src/Composer/Util/RemoteFilesystem.php @@ -99,7 +99,7 @@ class RemoteFilesystem $ctx = StreamContextFactory::getContext($options, array('notification' => array($this, 'callbackGet'))); if ($this->progress) { - $this->io->overwrite(" Downloading: connection...", false); + $this->io->write(" Downloading: connection...", false); } if (null !== $fileName) { diff --git a/tests/Composer/Test/IO/ConsoleIOTest.php b/tests/Composer/Test/IO/ConsoleIOTest.php index 78450eb53..73f0faedb 100644 --- a/tests/Composer/Test/IO/ConsoleIOTest.php +++ b/tests/Composer/Test/IO/ConsoleIOTest.php @@ -53,35 +53,35 @@ class ConsoleIOTest extends TestCase { $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); + $outputMock->expects($this->at(0)) ->method('write') - ->with($this->equalTo("\x08"), $this->equalTo(false)); - $outputMock->expects($this->at(19)) + ->with($this->equalTo('something (strlen = 23)')); + $outputMock->expects($this->at(1)) ->method('write') - ->with($this->equalTo("\x08"), $this->equalTo(false)); - $outputMock->expects($this->at(20)) + ->with($this->equalTo(str_repeat("\x08", 23)), $this->equalTo(false)); + $outputMock->expects($this->at(2)) ->method('write') - ->with($this->equalTo('some information'), $this->equalTo(false)); - $outputMock->expects($this->at(21)) + ->with($this->equalTo('shorter (12)'), $this->equalTo(false)); + $outputMock->expects($this->at(3)) ->method('write') - ->with($this->equalTo(' '), $this->equalTo(false)); - $outputMock->expects($this->at(24)) + ->with($this->equalTo(str_repeat(' ', 11)), $this->equalTo(false)); + $outputMock->expects($this->at(4)) ->method('write') - ->with($this->equalTo(' '), $this->equalTo(false)); - $outputMock->expects($this->at(25)) + ->with($this->equalTo(str_repeat("\x08", 11)), $this->equalTo(false)); + $outputMock->expects($this->at(5)) ->method('write') - ->with($this->equalTo("\x08"), $this->equalTo(false)); - $outputMock->expects($this->at(28)) + ->with($this->equalTo(str_repeat("\x08", 12)), $this->equalTo(false)); + $outputMock->expects($this->at(6)) ->method('write') - ->with($this->equalTo("\x08"), $this->equalTo(false)); - $outputMock->expects($this->at(29)) - ->method('write') - ->with($this->equalTo('')); + ->with($this->equalTo('something longer than initial (34)')); $helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet'); $consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock); - $consoleIO->overwrite('some information', true, 20); + $consoleIO->write('something (strlen = 23)'); + $consoleIO->overwrite('shorter (12)', false); + $consoleIO->overwrite('something longer than initial (34)'); } public function testAsk()