anker/src/Utils/Progress.php

27 lines
566 B
PHP

<?php
namespace App\Utils;
class Progress
{
function __construct(
private string $message,
private int $total,
private int $speed = 12,
private int $i = 0,
) {}
public function tick()
{
$this->i += 1;
if ($this->i % $this->speed === 0 or $this->i === $this->total) {
printf(
"\33[2K\r% 7d/% 7d | %.2f GiB | {$this->message}",
$this->i,
$this->total,
memory_get_usage() / 1024 / 1024 / 1024
);
}
}
}