Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pointybeard/helpers-cli-progressbar
Utility for rendering a progress bar to the command-line in PHP
https://github.com/pointybeard/helpers-cli-progressbar
Last synced: 9 days ago
JSON representation
Utility for rendering a progress bar to the command-line in PHP
- Host: GitHub
- URL: https://github.com/pointybeard/helpers-cli-progressbar
- Owner: pointybeard
- License: other
- Created: 2019-05-05T06:52:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-23T00:16:27.000Z (over 4 years ago)
- Last Synced: 2024-10-12T06:21:06.273Z (about 1 month ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# PHP Helpers: Command-line Progress Bar
- Version: v1.1.0
- Date: May 23 2019
- [Release notes](https://github.com/pointybeard/helpers-cli-progressbar/blob/master/CHANGELOG.md)
- [GitHub repository](https://github.com/pointybeard/helpers-cli-progressbar)A simple, yet powerful, class for rendering progress bars to the command-line.
## Installation
This library is installed via [Composer](http://getcomposer.org/). To install, use `composer require pointybeard/helpers-cli-progressbar` or add `"pointybeard/helpers-cli-progressbar": "~1.0"` to your `composer.json` file.
And run composer to update your dependencies:
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update### Requirements
This library makes use of the [PHP Helpers: Sliding Average](https://github.com/pointybeard/helpers-statistics-slidingaverage) (`pointybeard/helpers-statistics-slidingaverage`), [PHP Helpers: Command-line Colours](https://github.com/pointybeard/helpers-cli-colour) (`pointybeard/helpers-cli-colour`), and [PHP Helpers: Time Functions](https://github.com/pointybeard/helpers-functions-time) (`pointybeard/helpers-functions-time`) packages. They are installed automatically via composer.
To include all the [PHP Helpers](https://github.com/pointybeard/helpers) packages on your project, use `composer require pointybeard/helpers` or add `"pointybeard/helpers": "~1.0"` to your composer file.
## Usage
Include this library in your PHP files with `use pointybeard\Helpers\Cli\ProgressBar` and instanciate the `ProgressBar\ProgressBar` class like so:
```php
length(30)
->foreground(Colour\Colour::FG_GREEN)
->background(Colour\Colour::BG_DEFAULT)
->format('{{PROGRESS_BAR}} {{PERCENTAGE}}% {{COMPLETED}}/{{TOTAL}} ({{REMAINING_TIME}} remaining)')
;// Optional. Seeds the start time of the progress bar. time() is used
// if omitted.
$progress->start();do {
// This moves the progress forward (default is 1 unit) and redraws it
$progress->advance();// Slow the script down so we can see what's happening
usleep(rand(5000, 20000));
} while ($progress->remaining() > 0);echo PHP_EOL.'Work complete!'.PHP_EOL;
```
### Placeholders
The format of the progress bar can be modified using the `format` method. The default format is `{{PROGRESS_BAR}} {{PERCENTAGE}}% {{COMPLETED}}/{{TOTAL}} ({{ELAPSED_TIME}} elapsed, approx. {{REMAINING_TIME}} remaining)`.
Placeholders available are:
- PROGRESS_BAR
- PERCENTAGE
- COMPLETED
- TOTAL
- ELAPSED_TIME
- REMAINING_TIME## Support
If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/pointybeard/helpers-cli-progressbar/issues),
or better yet, fork the library and submit a pull request.## Contributing
We encourage you to contribute to this project. Please check out the [Contributing documentation](https://github.com/pointybeard/helpers-cli-progressbar/blob/master/CONTRIBUTING.md) for guidelines about how to get involved.
## License
"PHP Helpers: Command-line Progress Bar" is released under the [MIT License](http://www.opensource.org/licenses/MIT).