Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc93d5e0

Browse files
committed
fix(console): fix progress bar messing output in section when there is an EOL
1 parent0266d3c commitc93d5e0

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,13 @@ private function setRealFormat(string $format): void
475475
*/
476476
privatefunctionoverwrite(string$message):void
477477
{
478+
$newline =false;
479+
480+
if (str_ends_with($message, \PHP_EOL)) {
481+
$message =substr($message,0, -\strlen(\PHP_EOL));
482+
$newline =true;
483+
}
484+
478485
if ($this->previousMessage ===$message) {
479486
return;
480487
}
@@ -512,7 +519,7 @@ private function overwrite(string $message): void
512519
$this->previousMessage =$originalMessage;
513520
$this->lastWriteTime =microtime(true);
514521

515-
$this->output->write($message);
522+
$this->output->write($message,$newline);
516523
++$this->writeCount;
517524
}
518525

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,31 @@ public function testOverwriteWithSectionOutput()
416416
);
417417
}
418418

419+
publicfunctiontestOverwriteWithSectionOutputAndEol()
420+
{
421+
$sections = [];
422+
$stream =$this->getOutputStream(true);
423+
$output =newConsoleSectionOutput($stream->getStream(),$sections,$stream->getVerbosity(),$stream->isDecorated(),newOutputFormatter());
424+
425+
$bar =newProgressBar($output,50,0);
426+
$bar->setFormat('[%bar%] %percent:3s%%' .PHP_EOL .'%message%' .PHP_EOL);
427+
$bar->setMessage('');
428+
$bar->start();
429+
$bar->display();
430+
$bar->setMessage('Doing something...');
431+
$bar->advance();
432+
$bar->setMessage('Doing something foo...');
433+
$bar->advance();
434+
435+
rewind($output->getStream());
436+
$this->assertEquals(escapeshellcmd(
437+
'[>---------------------------] 0%'.\PHP_EOL.\PHP_EOL.
438+
"\x1b[2A\x1b[0J".'[>---------------------------] 2%'.\PHP_EOL.'Doing something...' . \PHP_EOL .
439+
"\x1b[2A\x1b[0J".'[=>--------------------------] 4%'.\PHP_EOL.'Doing something foo...' . \PHP_EOL),
440+
escapeshellcmd(stream_get_contents($output->getStream()))
441+
);
442+
}
443+
419444
publicfunctiontestOverwriteWithAnsiSectionOutput()
420445
{
421446
// output has 43 visible characters plus 2 invisible ANSI characters

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp