alecrabbit/php-console-spinner

Colorful highly configurable spinner for php cli applications


README

Logo

Spinner - your task is running

🏵️ PHP Console Spinner

PHP Version Build Status Appveyor Status Scrutinizer Code Quality Code Coverage Total Downloads

Latest Stable Version Packagist Pre Release Version Latest Unstable Version

License Average time to resolve an issue Percentage of issues still open

advanced

⚠️ Compatibility issues

Update 2019-Nov-01: As of version 0.53 compatibility issues should be resolved, but it needs to be tested.

This project is still in its active development phase. It turned out that some of its indirect dependencies are causing compatibility issues. New release is expected to be ready in mid-november 2019. For now, as a solution, you can use lightweight spinner alecrabbit/php-cli-snake.

Feature comparision

Feature php-console-spinner php-cli-snake
Lightweight ❌ ️ ✔️
Has zero dependencies ❌ ️ ✔️
Highly configurable ✔️ ️
Contains various spinner classes ✔️ ️
Progress indicator ✔️ ️
Messages indicator ✔️ ️
Color settings for spinner ✔️ ️
Color settings for messages ✔️ ️
Color settings for progress indicator ✔️ ️
Has disable() method ✔️ ️
Has enable() method ✔️ ️
Can show final message ✔️ ️
Cursor hide can be disabled ✔️ ️
Can use optional custom output ✔️ ️
Has erase() method ✔️ ️ ✔️ ️
Hides cursor with $spinner->begin() ✔️ ️ ✔️ ️
Shows cursor with $spinner->end() ✔️ ️ ✔️ ️
Supports piping ✔️ ️ ✔️ ️
Supports redirect ✔️ ️ ✔️ ️
Supports no color mode ✔️ ️ ✔️ ️
Supports 16 color mode ✔️ ️ ✔️ ️
Supports 256 color mode ✔️ ️ ✔️ ️

Features

  • progress indication during spin $spinner->progress(0.5)50%
  • messages during spin $spinner->message('message')
  • separated color settings for spinner, messages and progress indicator
  • has disable() and enable() methods
  • hides cursor on $spinner->begin(), shows on $spinner->end()
  • cursor hide can be disabled $settings->setHideCursor(false)
  • has erase() method
  • final message $spinner->end('final message')
  • supports unix pipe | and redirect > output
  • supplied with SymfonyOutputAdapter::class

Quickstart

Simple

See simple.php

require_once __DIR__ . '/vendor/autoload.php';

use AlecRabbit\Spinner\SnakeSpinner;

const ITERATIONS = 50;

$spinner = new SnakeSpinner();

$spinner->begin();
for ($i = 0; $i <= ITERATIONS; $i++) {
    usleep(80000); // Simulating work
    $spinner->spin();
}
$spinner->end();

Advanced (ReactPHP)

See advanced.php, async.demo.php

require_once __DIR__ . '/../vendor/autoload.php';

use AlecRabbit\Spinner\BlockSpinner;
use React\EventLoop\Factory;

$s = new BlockSpinner();

$loop = Factory::create();

$loop->addPeriodicTimer($s->interval(), static function () use ($s) {
    $s->spin();
});

$s->begin();

$loop->run();

Installation

composer require alecrabbit/php-console-spinner

Usage

Spinners

Here you can find a list of all spinners with demos

Operating Systems

  • Developed and tested on Ubuntu 18.04 (xterm terminal)

  • On Windows it should work in any VT100 terminal, e.g. minTTY.

Links