Skip to content

Commit

Permalink
Better progress bar visuals for CI environments
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 6, 2022
1 parent 11176c7 commit 0993d18
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/Command/ErrorsConsoleStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use Symfony\Component\Console\Terminal;
use function array_map;
use function strlen;
use function time;
use function wordwrap;
use const DIRECTORY_SEPARATOR;

class ErrorsConsoleStyle extends SymfonyStyle
{
Expand Down Expand Up @@ -77,7 +77,21 @@ public function table(array $headers, array $rows): void
public function createProgressBar(int $max = 0): ProgressBar
{
$this->progressBar = parent::createProgressBar($max);
$this->progressBar->setOverwrite(!$this->isCiDetected());

$ci = $this->isCiDetected();
$this->progressBar->setOverwrite(!$ci);

if ($ci) {
$this->progressBar->minSecondsBetweenRedraws(15);
$this->progressBar->maxSecondsBetweenRedraws(30);
} elseif (DIRECTORY_SEPARATOR === '\\') {
$this->progressBar->minSecondsBetweenRedraws(0.5);
$this->progressBar->maxSecondsBetweenRedraws(2);
} else {
$this->progressBar->minSecondsBetweenRedraws(0.1);
$this->progressBar->maxSecondsBetweenRedraws(0.5);
}

return $this->progressBar;
}

Expand All @@ -95,15 +109,6 @@ public function progressAdvance(int $step = 1): void
return;
}

if (!$this->isCiDetected() && $step > 0) {
$stepTime = (time() - $this->progressBar->getStartTime()) / $step;
if ($stepTime > 0 && $stepTime < 1) {
$this->progressBar->setRedrawFrequency((int) (1 / $stepTime));
} else {
$this->progressBar->setRedrawFrequency(1);
}
}

parent::progressAdvance($step);
}

Expand Down

0 comments on commit 0993d18

Please sign in to comment.