[Console] fixed progress bar jumping for windows & unix env #6266

Merged
merged 2 commits into from Dec 11, 2012
Jump to file or symbol
Failed to load files and symbols.
+19 −12
Diff settings

Always

Just for now

@@ -36,6 +36,7 @@ class ProgressHelper extends Helper
private $format = null;
private $redrawFreq = 1;
+ private $lastMessagesLength;
private $barCharOriginal;
/**
@@ -380,21 +381,17 @@ private function humaneTime($secs)
*
* @param OutputInterface $output An Output instance
* @param string|array $messages The message as an array of lines or a single string
- * @param Boolean $newline Whether to add a newline or not
- * @param integer $size The size of line
*/
- private function overwrite(OutputInterface $output, $messages, $newline = false, $size = 80)
+ private function overwrite(OutputInterface $output, $messages)
{
- $output->write(str_repeat("\x08", $size));
+ $output->write("\x0D"); // carriage return
+ if($this->lastMessagesLength!==null){
+ $output->write(str_repeat("\x20", $this->lastMessagesLength)); //clear the line with the length of the last message
+ $output->write("\x0D"); // carriage return
+ }
$output->write($messages);
- $output->write(str_repeat(' ', $size - strlen($messages)));
-
- // clean up the end line
- $output->write(str_repeat("\x08", $size - strlen($messages)));
- if ($newline) {
- $output->writeln('');
- }
+ $this->lastMessagesLength=strlen($messages);
}
/**
@@ -80,8 +80,18 @@ protected function getOutputStream()
return new StreamOutput(fopen('php://memory', 'r+', false));
}
+ protected $lastMessagesLength;
+
protected function generateOutput($expected)
{
- return str_repeat("\x08", 80).$expected.str_repeat(' ', 80 - strlen($expected)).str_repeat("\x08", 80 - strlen($expected));
+ $expectedout = $expected;
+
+ if($this->lastMessagesLength!==null){
+ $expectedout=str_repeat("\x20", $this->lastMessagesLength)."\x0D".$expected;
+ }
+
+ $this->lastMessagesLength=strlen($expected);
+
+ return "\x0D".$expectedout;
}
}