- Usage with event loop (Asynchronous mode)
- Usage without event loop (Synchronous mode)
- Custom palettes
use AlecRabbit\Spinner\Factory\Factory;
require_once __DIR__ . '/../bootstrap.php';
$spinner = Factory::createSpinner();
In synchronous mode usage is a bit more complicated. Simply speaking, you need to periodically call render()
method of IDriver
implementation.
$driver = \AlecRabbit\Spinner\Facade::getDriver();
while (true) {
$driver->render();
// do some work
}
There are four palettes supplied with the package:
- Rainbow (style)
- NoStylePalette
- Snake (characters)
- NoCharPalette
class Dots extends ACharPalette {
protected function createFrame(string $element): ICharFrame
{
return new CharFrame($element, 3); // note the width is 3
}
/** @inheritDoc */
protected function sequence(): Traversable
{
// note the width of each element
yield from [' ', '. ', '.. ', '...', ' ..', ' .', ' '];
}
}
class Greeny extends AStylePalette {
protected function ansi4StyleFrames(): Traversable
{
yield from [
$this->createFrame("\e[92m%s\e[39m"), // note the ANSI codes
];
}
protected function ansi8StyleFrames(): Traversable
{
return $this->ansi4StyleFrames();
}
protected function ansi24StyleFrames(): Traversable
{
return $this->ansi4StyleFrames();
}
protected function getInterval(StylingMethodMode $stylingMode): ?int
{
return null; // due to single style frame
}
}