8000 [Console] ProgressBar clears too many lines on update · symfony/symfony@2aa3df0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2aa3df0

Browse files
danepowellnicolas-grekas
authored andcommitted
[Console] ProgressBar clears too many lines on update
1 parent bbf786c commit 2aa3df0

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ private function overwrite(string $message): void
441441
if ($this->overwrite) {
442442
if (null !== $this->previousMessage) {
443443
if ($this->output instanceof ConsoleSectionOutput) {
444-
$lines = floor(Helper::strlen($message) / $this->terminal->getWidth()) + $this->formatLineCount + 1;
444+
$lines = floor(Helper::strlenWithoutDecoration($this->output->getFormatter(), $message) / $this->terminal->getWidth()) + $this->formatLineCount + 1;
445445
$this->output->clear($lines);
446446
} else {
< 8000 /td>
447447
// Erase previous lines

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,31 @@ public function testOverwriteWithSectionOutput()
343343
);
344344
}
345345

346+
public function testOverwriteWithAnsiSectionOutput()
347+
{
348+
// output has 43 visible characters plus 2 invisible ANSI characters
349+
putenv('COLUMNS=43');
350+
$sections = [];
351+
$stream = $this->getOutputStream(true);
352+
$output = new ConsoleSectionOutput($stream->getStream(), $sections, $stream->getVerbosity(), $stream->isDecorated(), new OutputFormatter());
353+
354+
$bar = new ProgressBar($output, 50, 0);
355+
$bar->setFormat(" \033[44;37m%current%/%max%\033[0m [%bar%] %percent:3s%%");
356+
$bar->start();
357+
$bar->display();
358+
$bar->advance();
359+
$bar->advance();
360+
361+
rewind($output->getStream());
362+
$this->assertSame(
363+
" \033[44;37m 0/50\033[0m [>---------------------------] 0%".\PHP_EOL.
364+
"\x1b[1A\x1b[0J"." \033[44;37m 1/50\033[0m [>---------------------------] 2%".\PHP_EOL.
365+
"\x1b[1A\x1b[0J"." \033[44;37m 2/50\033[0m [=>--------------------------] 4%".\PHP_EOL,
366+
stream_get_contents($output->getStream())
367+
);
368+
putenv('COLUMNS=120');
369+
}
370+
346371
public function testOverwriteMultipleProgressBarsWithSectionOutputs()
347372
{
348373
$sections = [];

0 commit comments

Comments
 (0)
0