Skip to content

Commit 0993d18

Browse files
committed
Better progress bar visuals for CI environments
1 parent 11176c7 commit 0993d18

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/Command/ErrorsConsoleStyle.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use Symfony\Component\Console\Terminal;
1111
use function array_map;
1212
use function strlen;
13-
use function time;
1413
use function wordwrap;
14+
use const DIRECTORY_SEPARATOR;
1515

1616
class ErrorsConsoleStyle extends SymfonyStyle
1717
{
@@ -77,7 +77,21 @@ public function table(array $headers, array $rows): void
7777
public function createProgressBar(int $max = 0): ProgressBar
7878
{
7979
$this->progressBar = parent::createProgressBar($max);
80-
$this->progressBar->setOverwrite(!$this->isCiDetected());
80+
81+
$ci = $this->isCiDetected();
82+
$this->progressBar->setOverwrite(!$ci);
83+
84+
if ($ci) {
85+
$this->progressBar->minSecondsBetweenRedraws(15);
86+
$this->progressBar->maxSecondsBetweenRedraws(30);
87+
} elseif (DIRECTORY_SEPARATOR === '\\') {
88+
$this->progressBar->minSecondsBetweenRedraws(0.5);
89+
$this->progressBar->maxSecondsBetweenRedraws(2);
90+
} else {
91+
$this->progressBar->minSecondsBetweenRedraws(0.1);
92+
$this->progressBar->maxSecondsBetweenRedraws(0.5);
93+
}
94+
8195
return $this->progressBar;
8296
}
8397

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

98-
if (!$this->isCiDetected() && $step > 0) {
99-
$stepTime = (time() - $this->progressBar->getStartTime()) / $step;
100-
if ($stepTime > 0 && $stepTime < 1) {
101-
$this->progressBar->setRedrawFrequency((int) (1 / $stepTime));
102-
} else {
103-
$this->progressBar->setRedrawFrequency(1);
104-
}
105-
}
106-
107112
parent::progressAdvance($step);
108113
}
109114

0 commit comments

Comments
 (0)