mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Use Phan’s progress bar for large file counts, because it’s good
This commit is contained in:
parent
34b0310594
commit
e40aed53d4
@ -10,22 +10,57 @@ class DefaultProgress extends LongProgress
|
||||
if ($this->number_of_tasks > self::TOO_MANY_FILES) {
|
||||
++$this->progress;
|
||||
|
||||
$expected_bars = round(($this->progress / $this->number_of_tasks) * self::NUMBER_OF_COLUMNS);
|
||||
$inner_progress = self::renderInnerProgressBar(
|
||||
self::NUMBER_OF_COLUMNS,
|
||||
$this->progress / $this->number_of_tasks
|
||||
);
|
||||
|
||||
$inner_progress = str_repeat(self::doesTerminalSupportUtf8() ? '░' : 'X', $expected_bars);
|
||||
|
||||
if ($expected_bars !== self::NUMBER_OF_COLUMNS) {
|
||||
$expected_bars--;
|
||||
}
|
||||
|
||||
$progress_bar = $inner_progress . str_repeat(' ', self::NUMBER_OF_COLUMNS - $expected_bars);
|
||||
|
||||
$this->write($progress_bar . ' ' . $this->getOverview() . "\r");
|
||||
$this->write($inner_progress . ' ' . $this->getOverview() . "\r");
|
||||
} else {
|
||||
parent::taskDone($successful);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fully stolen from
|
||||
* https://github.com/phan/phan/blob/d61a624b1384ea220f39927d53fd656a65a75fac/src/Phan/CLI.php
|
||||
* Renders a unicode progress bar that goes from light (left) to dark (right)
|
||||
* The length in the console is the positive integer $length
|
||||
* @see https://en.wikipedia.org/wiki/Block_Elements
|
||||
*/
|
||||
private static function renderInnerProgressBar(int $length, float $p) : string
|
||||
{
|
||||
$current_float = $p * $length;
|
||||
$current = (int)$current_float;
|
||||
$rest = \max($length - $current, 0);
|
||||
|
||||
if (!self::doesTerminalSupportUtf8()) {
|
||||
// Show a progress bar of "XXXX>------" in Windows when utf-8 is unsupported.
|
||||
$progress_bar = str_repeat("X", $current);
|
||||
$delta = $current_float - $current;
|
||||
if ($delta > 0.5) {
|
||||
$progress_bar .= ">" . str_repeat("-", $rest - 1);
|
||||
} else {
|
||||
$progress_bar .= str_repeat("-", $rest);
|
||||
}
|
||||
return $progress_bar;
|
||||
}
|
||||
|
||||
// The left-most characters are "Light shade"
|
||||
$progress_bar = str_repeat("\u{2588}", $current);
|
||||
$delta = $current_float - $current;
|
||||
if ($delta > 1.0 / 3) {
|
||||
// The between character is "Full block" or "Medium shade" or "solid shade".
|
||||
// The remaining characters on the right are "Full block" (darkest)
|
||||
$first = $delta > 2.0 / 3 ? "\u{2593}" : "\u{2592}";
|
||||
$progress_bar .= $first . str_repeat("\u{2591}", $rest - 1);
|
||||
} else {
|
||||
$progress_bar .= str_repeat("\u{2591}", $rest);
|
||||
}
|
||||
|
||||
return $progress_bar;
|
||||
}
|
||||
|
||||
public function finish(): void
|
||||
{
|
||||
if ($this->number_of_tasks > self::TOO_MANY_FILES) {
|
||||
|
Loading…
Reference in New Issue
Block a user