diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index 07e529666..491a6b7fb 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -113,6 +113,14 @@ class ConsoleIO extends BaseIO */ public function overwrite($messages, $newline = true, $size = null) { + if (!$this->output->isDecorated()) { + if (!$messages) { + return; + } + + return $this->write($messages, count($messages) === 1 || $newline); + } + // messages can be an array, let's convert it to string anyway $messages = join($newline ? "\n" : '', (array) $messages); diff --git a/tests/Composer/Test/IO/ConsoleIOTest.php b/tests/Composer/Test/IO/ConsoleIOTest.php index 3a4313f69..6ce95b0ac 100644 --- a/tests/Composer/Test/IO/ConsoleIOTest.php +++ b/tests/Composer/Test/IO/ConsoleIOTest.php @@ -58,21 +58,27 @@ class ConsoleIOTest extends TestCase ->method('write') ->with($this->equalTo('something (strlen = 23)')); $outputMock->expects($this->at(1)) - ->method('write') - ->with($this->equalTo(str_repeat("\x08", 23)), $this->equalTo(false)); + ->method('isDecorated') + ->willReturn(true); $outputMock->expects($this->at(2)) ->method('write') - ->with($this->equalTo('shorter (12)'), $this->equalTo(false)); + ->with($this->equalTo(str_repeat("\x08", 23)), $this->equalTo(false)); $outputMock->expects($this->at(3)) ->method('write') - ->with($this->equalTo(str_repeat(' ', 11)), $this->equalTo(false)); + ->with($this->equalTo('shorter (12)'), $this->equalTo(false)); $outputMock->expects($this->at(4)) ->method('write') - ->with($this->equalTo(str_repeat("\x08", 11)), $this->equalTo(false)); + ->with($this->equalTo(str_repeat(' ', 11)), $this->equalTo(false)); $outputMock->expects($this->at(5)) ->method('write') - ->with($this->equalTo(str_repeat("\x08", 12)), $this->equalTo(false)); + ->with($this->equalTo(str_repeat("\x08", 11)), $this->equalTo(false)); $outputMock->expects($this->at(6)) + ->method('isDecorated') + ->willReturn(true); + $outputMock->expects($this->at(7)) + ->method('write') + ->with($this->equalTo(str_repeat("\x08", 12)), $this->equalTo(false)); + $outputMock->expects($this->at(8)) ->method('write') ->with($this->equalTo('something longer than initial (34)'));