Skip to content

Commit 7b0db54

Browse files
committed
Add README
1 parent 2ed03eb commit 7b0db54

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# ProgressbarStream
2+
3+
An event-driven progressbar stream that can be added to other streams
4+
to show its current progress.
5+
6+
**Table of Contents**
7+
* [Usage](#usage)
8+
* [data-Event](#data-event)
9+
* [currentValue-Event](#currentvalue-event)
10+
* [maximumValue-Event](#maximumvalue-event)
11+
* [Installation](#installation)
12+
13+
## Usage
14+
15+
This stream can be integrate like any other
16+
[ReactPHP Stream](https://github.com/reactphp/stream/)
17+
18+
```php
19+
$loop = Factory::create();
20+
21+
$progressBarStream = new ProgressbarStream();
22+
23+
$input = new React\Stream\WritableResourceStream(STDOUT, $loop);
24+
$output = new React\Stream\ReadableResourceStream(STDIN, $loop);
25+
26+
$output->pipe($progressBarStream);
27+
28+
$progressBarStream->on('error', function ($errorMessage) {
29+
echo $errorMessage;
30+
});
31+
32+
$progressBarStream->on('data', function ($progressBarString) use ($input) {
33+
$input->write($progressBarString . PHP_EOL);
34+
});
35+
36+
$loop->addPeriodicTimer(1, function () use ($output) {
37+
$output->emit('data', array(1));
38+
});
39+
40+
$loop->addPeriodicTimer(3, function () use ($output) {
41+
$output->emit('data', array(10));
42+
});
43+
44+
$loop->run();
45+
```
46+
47+
This example will update the progressbar every 1 second by 1 unit/percent and
48+
every 3 seconds by 10 units/percent.
49+
This example can be found in the [examples folder](/examples).
50+
51+
The progressbar stream will never overflow the maximum value.
52+
The stream will end if the current value reaches or goes beyond the maximum
53+
value.
54+
55+
### data-Event
56+
57+
The `data` event contains the visualization of the progress bar.
58+
The data emitted by this event is a string.
59+
This event will be emitted if the progressbar is updated.
60+
61+
### currentValue-Event
62+
63+
The `currentValue` event contains the integer value of the current progressbar.
64+
This event will be emitted if the progressbar is updated.
65+
66+
### maximumValue-Event
67+
68+
The `maximumValue` event contains the integer value of the maximum reachable value
69+
of the progressbar.
70+
This event will be emitted if the progressbar is updated.
71+
72+
### Customize
73+
74+
The constructor
75+
76+
## Installation
77+
78+
The recommended way to install this library is [through Composer](https://getcomposer.org).
79+
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
80+
81+
This will install the latest supported version:
82+
83+
```bash
84+
$ composer require legionth/progressbar:^1.0
85+
```

0 commit comments

Comments
 (0)