Merge remote-tracking branch 'kostiklv/console-overwrite-fix'
commit
89f69256f8
|
@ -84,8 +84,6 @@ class FileDownloader implements DownloaderInterface
|
||||||
if ($checksum && hash_file('sha1', $fileName) !== $checksum) {
|
if ($checksum && hash_file('sha1', $fileName) !== $checksum) {
|
||||||
throw new \UnexpectedValueException('The checksum verification of the file failed (downloaded from '.$url.')');
|
throw new \UnexpectedValueException('The checksum verification of the file failed (downloaded from '.$url.')');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->io->write('');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,6 +31,7 @@ class ConsoleIO implements IOInterface
|
||||||
protected $authorizations = array();
|
protected $authorizations = array();
|
||||||
protected $lastUsername;
|
protected $lastUsername;
|
||||||
protected $lastPassword;
|
protected $lastPassword;
|
||||||
|
protected $lastMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -60,31 +61,40 @@ class ConsoleIO implements IOInterface
|
||||||
public function write($messages, $newline = true)
|
public function write($messages, $newline = true)
|
||||||
{
|
{
|
||||||
$this->output->write($messages, $newline);
|
$this->output->write($messages, $newline);
|
||||||
|
$this->lastMessage = join($newline ? "\n" : '', (array) $messages);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public function overwrite($messages, $newline = true, $size = 80)
|
public function overwrite($messages, $newline = true, $size = null)
|
||||||
{
|
{
|
||||||
for ($place = $size; $place > 0; $place--) {
|
// messages can be an array, let's convert it to string anyway
|
||||||
$this->write("\x08", false);
|
$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);
|
$this->write($messages, false);
|
||||||
|
|
||||||
for ($place = ($size - strlen($messages)); $place > 0; $place--) {
|
$fill = $size - strlen(strip_tags($messages));
|
||||||
$this->write(' ', false);
|
if ($fill > 0) {
|
||||||
}
|
// whitespace whatever has left
|
||||||
|
$this->write(str_repeat(' ', $fill), false);
|
||||||
// clean up the end line
|
// move the cursor back
|
||||||
for ($place = ($size - strlen($messages)); $place > 0; $place--) {
|
$this->write(str_repeat("\x08", $fill), false);
|
||||||
$this->write("\x08", false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($newline) {
|
if ($newline) {
|
||||||
$this->write('');
|
$this->write('');
|
||||||
}
|
}
|
||||||
|
$this->lastMessage = $messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -99,7 +99,7 @@ class RemoteFilesystem
|
||||||
$ctx = StreamContextFactory::getContext($options, array('notification' => array($this, 'callbackGet')));
|
$ctx = StreamContextFactory::getContext($options, array('notification' => array($this, 'callbackGet')));
|
||||||
|
|
||||||
if ($this->progress) {
|
if ($this->progress) {
|
||||||
$this->io->overwrite(" Downloading: <comment>connection...</comment>", false);
|
$this->io->write(" Downloading: <comment>connection...</comment>", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $fileName) {
|
if (null !== $fileName) {
|
||||||
|
|
|
@ -53,35 +53,35 @@ class ConsoleIOTest extends TestCase
|
||||||
{
|
{
|
||||||
$inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface');
|
$inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface');
|
||||||
$outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
|
$outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
|
||||||
|
|
||||||
$outputMock->expects($this->at(0))
|
$outputMock->expects($this->at(0))
|
||||||
->method('write')
|
->method('write')
|
||||||
->with($this->equalTo("\x08"), $this->equalTo(false));
|
->with($this->equalTo('something (<question>strlen = 23</question>)'));
|
||||||
$outputMock->expects($this->at(19))
|
$outputMock->expects($this->at(1))
|
||||||
->method('write')
|
->method('write')
|
||||||
->with($this->equalTo("\x08"), $this->equalTo(false));
|
->with($this->equalTo(str_repeat("\x08", 23)), $this->equalTo(false));
|
||||||
$outputMock->expects($this->at(20))
|
$outputMock->expects($this->at(2))
|
||||||
->method('write')
|
->method('write')
|
||||||
->with($this->equalTo('some information'), $this->equalTo(false));
|
->with($this->equalTo('shorter (<comment>12</comment>)'), $this->equalTo(false));
|
||||||
$outputMock->expects($this->at(21))
|
$outputMock->expects($this->at(3))
|
||||||
->method('write')
|
->method('write')
|
||||||
->with($this->equalTo(' '), $this->equalTo(false));
|
->with($this->equalTo(str_repeat(' ', 11)), $this->equalTo(false));
|
||||||
$outputMock->expects($this->at(24))
|
$outputMock->expects($this->at(4))
|
||||||
->method('write')
|
->method('write')
|
||||||
->with($this->equalTo(' '), $this->equalTo(false));
|
->with($this->equalTo(str_repeat("\x08", 11)), $this->equalTo(false));
|
||||||
$outputMock->expects($this->at(25))
|
$outputMock->expects($this->at(5))
|
||||||
->method('write')
|
->method('write')
|
||||||
->with($this->equalTo("\x08"), $this->equalTo(false));
|
->with($this->equalTo(str_repeat("\x08", 12)), $this->equalTo(false));
|
||||||
$outputMock->expects($this->at(28))
|
$outputMock->expects($this->at(6))
|
||||||
->method('write')
|
->method('write')
|
||||||
->with($this->equalTo("\x08"), $this->equalTo(false));
|
->with($this->equalTo('something longer than initial (<info>34</info>)'));
|
||||||
$outputMock->expects($this->at(29))
|
|
||||||
->method('write')
|
|
||||||
->with($this->equalTo(''));
|
|
||||||
|
|
||||||
$helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet');
|
$helperMock = $this->getMock('Symfony\Component\Console\Helper\HelperSet');
|
||||||
|
|
||||||
$consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock);
|
$consoleIO = new ConsoleIO($inputMock, $outputMock, $helperMock);
|
||||||
$consoleIO->overwrite('some information', true, 20);
|
$consoleIO->write('something (<question>strlen = 23</question>)');
|
||||||
|
$consoleIO->overwrite('shorter (<comment>12</comment>)', false);
|
||||||
|
$consoleIO->overwrite('something longer than initial (<info>34</info>)');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAsk()
|
public function testAsk()
|
||||||
|
|
Loading…
Reference in New Issue