Skip to content

Commit a3528eb

Browse files
Merge branch '4.4' into 5.2
* 4.4: [Console] ProgressBar clears too many lines on update [FrameworkBundle] Exclude unreadable files when executing About command [Bridge\Twig] Add 'form-control-range' for range input type Be explicit about transparent background color of links in toolbar [Translation] fix test case name [Cache] Fix wrong namespace in test [DependencyInjection] Fix return type
2 parents 0aae190 + eaa700f commit a3528eb

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Helper/ProgressBar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ private function overwrite(string $message): void
462462
if ($this->overwrite) {
463463
if (null !== $this->previousMessage) {
464464
if ($this->output instanceof ConsoleSectionOutput) {
465-
$lines = floor(Helper::strlen($message) / $this->terminal->getWidth()) + $this->formatLineCount + 1;
465+
$lines = floor(Helper::strlenWithoutDecoration($this->output->getFormatter(), $message) / $this->terminal->getWidth()) + $this->formatLineCount + 1;
466466
$this->output->clear($lines);
467467
} else {
468468
if ($this->formatLineCount > 0) {

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)