An event-driven progressbar stream that can be added to other streams to show its current progress.
Table of Contents
This stream can be integrate like any other ReactPHP Stream
$loop = Factory::create();
$progressBarStream = new ProgressbarStream();
$input = new React\Stream\WritableResourceStream(STDOUT, $loop);
$output = new React\Stream\ReadableResourceStream(STDIN, $loop);
$output->pipe($progressBarStream);
$progressBarStream->on('error', function ($errorMessage) {
echo $errorMessage;
});
$progressBarStream->on('data', function ($progressBarString) use ($input) {
$input->write($progressBarString . PHP_EOL);
});
$loop->addPeriodicTimer(1, function () use ($output) {
$output->emit('data', array(1));
});
$loop->addPeriodicTimer(3, function () use ($output) {
$output->emit('data', array(10));
});
$loop->run();
This example will update the progressbar every 1 second by 1 unit/percent and every 3 seconds by 10 units/percent. This example can be found in the examples folder.
The progressbar stream will never overflow the maximum value. The stream will end if the current value reaches or goes beyond the maximum value.
The data
event contains the visualization of the progress bar.
The data emitted by this event is a string.
This event will be emitted if the progressbar is updated.
The currentValue
event contains the integer value of the current progressbar.
This event will be emitted if the progressbar is updated.
The maximumValue
event contains the integer value of the maximum reachable value
of the progressbar.
This event will be emitted if the progressbar is updated.
The recommended way to install this library is through Composer. New to Composer?
This will install the latest supported version:
$ composer require legionth/progressbar:^1.0