8000 jumping progress bar fix for windows & unix · symfony/symfony@ea74610 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea74610

Browse files
author
Robert Queck
committed
jumping progress bar fix for windows & unix
1 parent 6a0ee27 commit ea74610

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Symfony/Component/Console/Helper/ProgressHelper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ProgressHelper extends Helper
3636
private $format = null;
3737
private $redrawFreq = 1;
3838

39+
private $lastMessagesLength;
3940
private $barCharOriginal;
4041

4142
/**
@@ -384,8 +385,13 @@ private function humaneTime($secs)
384385
private function overwrite(OutputInterface $output, $messages)
385386
{
386387
$output->write("\x0D"); // carriage return
387-
$output->write("\x1B\x5B\x4B"); // clear line
388+
if($this->lastMessagesLength!==null){
389+
$output->write(str_repeat("\x20", $this->lastMessagesLength)); //clear the line with the length of the last message
390+
$output->write("\x0D"); // carriage return
391+
}
388392
$output->write($messages);
393+
394+
$this->lastMessagesLength=strlen($messages);
389395
}
390396

391397
/**

src/Symfony/Component/Console/Tests/Helper/ProgressHelperTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,18 @@ protected function getOutputStream()
8080
return new StreamOutput(fopen('php://memory', 'r+', false));
8181
}
8282

83+
protected $lastMessagesLength;
84+
8385
protected function generateOutput($expected)
8486
{
85-
return "\x0D\x1B\x5B\x4B".$expected;
87+
$expectedout = $expected;
88+
89+
if($this->lastMessagesLength!==null){
90+
$expectedout=str_repeat("\x20", $this->lastMessagesLength)."\x0D".$expected;
91+
}
92+
93+
$this->lastMessagesLength=strlen($expected);
94+
95+
return "\x0D".$expectedout;
8696
}
8797
}

0 commit comments

Comments
 (0)
0