Skip to content

Commit

Permalink
Keep original progressbar formats based on verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed Dec 14, 2022
1 parent d0ce5da commit 2bfe7ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/Command/ErrorsConsoleStyle.php
Expand Up @@ -118,7 +118,11 @@ private function wrap(array $rows, int $terminalWidth, int $maxHeaderWidth): arr
public function createProgressBar(int $max = 0): ProgressBar
{
$this->progressBar = parent::createProgressBar($max);
$this->progressBar->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%');

$format = $this->getProgressBarFormat();
if ($format !== null) {
$this->progressBar->setFormat($format);
}

$ci = $this->isCiDetected();
$this->progressBar->setOverwrite(!$ci);
Expand All @@ -137,6 +141,22 @@ public function createProgressBar(int $max = 0): ProgressBar
return $this->progressBar;
}

private function getProgressBarFormat(): ?string
{
$formatName = match ($this->getVerbosity()) {
OutputInterface::VERBOSITY_NORMAL => ProgressBar::FORMAT_NORMAL,
OutputInterface::VERBOSITY_VERBOSE => ProgressBar::FORMAT_VERBOSE,
OutputInterface::VERBOSITY_VERY_VERBOSE,
OutputInterface::VERBOSITY_DEBUG => ProgressBar::FORMAT_VERY_VERBOSE, // FORMAT_DEBUG shows invalid memory, avoid that
default => null,
};
if ($formatName === null) {
return null;
}

return ProgressBar::getFormatDefinition($formatName);
}

public function progressStart(int $max = 0): void
{
if (!$this->showProgress) {
Expand Down
Expand Up @@ -228,7 +228,7 @@ public function testEditorUrlWithCustomTitle(): void
{
$formatter = $this->createErrorFormatter('editor://any', '%relFile%:%line%');
$error = new Error('Test', 'Foo.php', 12, true, self::DIRECTORY_PATH . '/rel/Foo.php');
$formatter->formatErrors(new AnalysisResult([$error], [], [], [], [], false, null, true), $this->getOutput(true));
$formatter->formatErrors(new AnalysisResult([$error], [], [], [], [], false, null, true, 0), $this->getOutput(true));

$this->assertStringContainsString('rel/Foo.php:12', $this->getOutputContent(true));
}
Expand Down

0 comments on commit 2bfe7ed

Please sign in to comment.