8000 merged branch robqu/patch-progressbar (PR #6266) · symfony/symfony@8bbc64d · GitHub
[go: up one dir, main page]

Skip to content

Commit 8bbc64d

Browse files
committed
merged branch robqu/patch-progressbar (PR #6266)
This PR was merged into the master branch. Commits ------- ea74610 jumping progress bar fix for windows & unix 6a0ee27 [Console] fixed progress bar jumping Discussion ---------- [Console] fixed progress bar jumping for windows & unix env Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes Fixes the following tickets: - Todo: - License of the code: MIT Documentation PR: - --------------------------------------------------------------------------- by pborreli at 2012-12-11T13:58:25Z Good implementation but could you please check http://symfony.com/doc/current/contributing/code/standards.html
2 parents 51bcb6e + ea74610 commit 8bbc64d

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

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

Lines changed: 8 additions & 11 deletions
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
/**
@@ -380,21 +381,17 @@ private function humaneTime($secs)
380381
*
381382
* @param OutputInterface $output An Output instance
382383
* @param string|array $messages The message as an array of lines or a single string
383-
* @param Boolean $newline Whether to add a newline or not
384-
* @param integer $size The size of line
385384
*/
386-
private function overwrite(OutputInterface $output, $messages, $newline = false, $size = 80)
385+
private function overwrite(OutputInterface $output, $messages)
387386
{
388-
$output->write(str_repeat("\x08", $size));
387+
$output->write("\x0D"); // carriage return
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+
}
389392
$output->write($messages);
390-
$output->write(str_repeat(' ', $size - strlen($messages)));
391-
392-
// clean up the end line
393-
$output->write(str_repeat("\x08", $size - strlen($messages)));
394393

395-
if ($newline) {
396-
$output->writeln('');
397-
}
394+
$this->lastMessagesLength=strlen($messages);
398395
}
399396

400397
/**

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

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

82+
protected $lastMessagesLength;
83+
8284
protected function generateOutput($expected)
8385
{
84-
return str_repeat("\x08", 80).$expected.str_repeat(' ', 80 - strlen($expected)).str_repeat("\x08", 80 - strlen($expected));
86+
$expectedout = $expected;
87+
88+
if($this->lastMessagesLength!==null){
89+
$expectedout=str_repeat("\x20", $this->lastMessagesLength)."\x0D".$expected;
90+
}
91+
92+
$this->lastMessagesLength=strlen($expected);
93+
94+
return "\x0D".$expectedout;
8595
}
8696
}

0 commit comments

Comments
 (0)
0