2019-05-30 16:30:41 +02:00
|
|
|
<?php
|
|
|
|
namespace Psalm\Progress;
|
|
|
|
|
2019-05-31 00:37:01 +02:00
|
|
|
class DefaultProgress extends LongProgress
|
2019-05-30 16:30:41 +02:00
|
|
|
{
|
2019-05-31 00:37:01 +02:00
|
|
|
const TOO_MANY_FILES = 1500;
|
2019-05-30 16:30:41 +02:00
|
|
|
|
2019-05-31 00:37:01 +02:00
|
|
|
public function taskDone(bool $successful): void
|
2019-05-30 16:30:41 +02:00
|
|
|
{
|
2019-05-31 00:37:01 +02:00
|
|
|
if ($this->number_of_tasks > self::TOO_MANY_FILES) {
|
|
|
|
++$this->progress;
|
2019-05-30 16:30:41 +02:00
|
|
|
|
2019-05-31 00:37:01 +02:00
|
|
|
$expected_bars = round(($this->progress / $this->number_of_tasks) * self::NUMBER_OF_COLUMNS);
|
2019-05-30 16:30:41 +02:00
|
|
|
|
2019-05-31 00:37:01 +02:00
|
|
|
$inner_progress = str_repeat(self::doesTerminalSupportUtf8() ? '░' : 'X', $expected_bars);
|
2019-05-30 16:30:41 +02:00
|
|
|
|
2019-05-31 00:37:01 +02:00
|
|
|
if ($expected_bars !== self::NUMBER_OF_COLUMNS) {
|
|
|
|
$expected_bars--;
|
|
|
|
}
|
2019-05-30 16:30:41 +02:00
|
|
|
|
2019-05-31 00:37:01 +02:00
|
|
|
$progress_bar = $inner_progress . str_repeat(' ', self::NUMBER_OF_COLUMNS - $expected_bars);
|
2019-05-30 16:30:41 +02:00
|
|
|
|
2019-05-31 00:37:01 +02:00
|
|
|
$this->write($progress_bar . ' ' . $this->getOverview() . "\r");
|
|
|
|
} else {
|
|
|
|
parent::taskDone($successful);
|
2019-05-30 16:30:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function finish(): void
|
|
|
|
{
|
2019-05-31 00:37:01 +02:00
|
|
|
if ($this->number_of_tasks > self::TOO_MANY_FILES) {
|
|
|
|
$this->write(str_repeat(' ', self::NUMBER_OF_COLUMNS + strlen($this->getOverview()) + 1) . "\r");
|
|
|
|
} else {
|
|
|
|
parent::finish();
|
2019-05-30 16:30:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|