Skip to content

Simple PHP library for displaying spinners in the terminal while running a callback function.

Notifications You must be signed in to change notification settings

pjotrvdh/php-cli-spinners

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-cli-spinners

Simple PHP library for displaying spinners in the terminal while running a callback function.

You will need to have the pcntl extension installed.

The library uses this collection of spinners:

The spinners can be seen in action here

If you don't have the pcntl extension installed, you can still use the library, but you will not see the spinner.

On windows use WSL. There may be some trouble using UTF-8 characters in the terminal on WSL.

In this case you can use the simpleDots or simpleDotsScrolling spinner.

How it works

The library will run a callback function in a separate process which displays the spinner. The main process will run the callback function and return the result.

Installation

composer require diversen/php-cli-spinners

Usage

<?php

require_once "vendor/autoload.php";

use Diversen\Spinner;

$spinner = new Spinner(spinner: 'dots');
$res = $spinner->callback(function () {
    // Do something important
    sleep(2);
    return 42;
});

echo $res . "\n";

Examples

Clone:

git clone https://github.com/diversen/php-cli-spinners.git

See examples folder. E.g. run php examples/simple.php

License

MIT © Dennis Iversen

About

Simple PHP library for displaying spinners in the terminal while running a callback function.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 98.8%
  • Shell 1.2%