diff --git a/examples/progress.php b/examples/progress.php deleted file mode 100644 index b1dab2b..0000000 --- a/examples/progress.php +++ /dev/null @@ -1,27 +0,0 @@ -writeln('Will print (fake) progress and then exit'); - -$progress = new ProgressBar($stdio); -$progress->setMaximum(mt_rand(20, 200)); - -$loop->addPeriodicTimer(0.1, function ($timer) use ($stdio, $progress) { - $progress->advance(); - - if ($progress->isComplete()) { - $stdio->overwrite("Finished processing nothing!" . PHP_EOL); - - $stdio->end(); - $timer->cancel(); - } -}); - -$loop->run(); diff --git a/examples/spinner.php b/examples/spinner.php deleted file mode 100644 index 24691af..0000000 --- a/examples/spinner.php +++ /dev/null @@ -1,28 +0,0 @@ -getReadline()->setPrompt('> '); - -$stdio->writeln('Will print a spinner until you enter something'); - -$stdio->write(' Processing...'); - -$spinner = new Spinner($loop, $stdio); - -$stdio->on('line', function ($line) use ($stdio, &$tid, $loop, $spinner) { - $stdio->overwrite('Processing... DONE'); - - $stdio->end(); - $spinner->pause(); -}); - -$loop->run(); diff --git a/src/Helper/ProgressBar.php b/src/Helper/ProgressBar.php deleted file mode 100644 index 570a37e..0000000 --- a/src/Helper/ProgressBar.php +++ /dev/null @@ -1,99 +0,0 @@ -stdio = $stdio; - } - - public function advance($by = 1) - { - $this->current += $by; - if ($this->current > $this->maximum) { - $this->current = $this->maximum; - } elseif ($this->current < 0) { - $this->current = 0; - } - - $this->redraw(); - } - - public function complete() - { - $this->current = $this->maximum; - - $this->redraw(); - } - - public function isComplete() - { - return ($this->current >= $this->maximum); - } - - public function setMaximum($maximum) - { - $this->maximum = $maximum; - - $this->redraw(); - } - - public function getCurrent() - { - return $this->current; - } - - public function getMaximm() - { - return $this->maximum; - } - - public function getPercent() - { - return ($this->current * 100 / $this->maximum); - } - - public function redraw() - { - $this->clear(); - $this->write(); - } - - public function clear() - { - $this->stdio->write("\r"); - } - - public function write() - { - $bar = '['; - - $length = round(($this->length - 3) * ($this->current / $this->maximum)); - - $bar .= str_repeat('=', $length); - $bar .= '>'; - - $remaining = $this->length - 3 - $length; - if ($remaining > 0) { - $bar .= str_repeat(' ', $remaining); - } - - $bar .= ']'; - - if (true) { - $bar .= sprintf(' %1.1f', $this->getPercent()) . '%'; - } - - $this->stdio->overwrite($bar); - } -} diff --git a/src/Helper/Spinner.php b/src/Helper/Spinner.php deleted file mode 100644 index 0835a6a..0000000 --- a/src/Helper/Spinner.php +++ /dev/null @@ -1,110 +0,0 @@ -loop = $loop; - $this->stdio = $stdio; - - $this->setSequence(self::SEQUENCE_ASCII); - $this->resume(); - } - - public function setInterval($interval) - { - $this->interval = $interval; - - if ($this->tid !== null) { - $this->pause(); - $this->resume(); - } - } - - public function setSequence($sequence) - { - if (!is_array($sequence)) { - $sequence = $this->split($sequence); - } - - $this->length = count($sequence); - - if ($this->length === 0) { - throw new InvalidArgumentException('Empty sequence passed'); - } - - $this->sequence = $sequence; - $this->position = 0; - - if ($this->tid !== null) { - $this->pause(); - $this->resume(); - } - } - - public function pause() - { - if ($this->tid !== null) { - $this->loop->cancelTimer($this->tid); - $this->tid = null; - } - } - - public function resume() - { - if ($this->tid === null) { - $this->tid = $this->loop->addPeriodicTimer($this->interval, array($this, 'tick')); - } - } - - public function tick() - { - $this->clear(); - $this->write(); - - } - - public function clear() - { - $this->stdio->write("\x08 \x08"); - } - - public function write() - { - $this->stdio->write($this->sequence[$this->position]); - $this->position = ($this->position + 1) % $this->length; - } - - private function split($sequence) - { - $ret = array(); - for ($i = 0, $l = mb_strlen($sequence, 'UTF-8'); $i < $l; ++$i) { - $ret[] = mb_substr($sequence, $i, 1, 'UTF-8'); - } - - return $ret; - } -}