Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/agracio/ts-progress
Flexible node progress bar for Windows/macOS/Linux
https://github.com/agracio/ts-progress
Last synced: about 1 month ago
JSON representation
Flexible node progress bar for Windows/macOS/Linux
- Host: GitHub
- URL: https://github.com/agracio/ts-progress
- Owner: agracio
- License: mit
- Created: 2016-09-10T09:13:27.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-17T07:38:20.000Z (6 months ago)
- Last Synced: 2024-09-19T08:08:57.178Z (2 months ago)
- Language: TypeScript
- Homepage:
- Size: 294 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ts-progress
[![Build status](https://ci.appveyor.com/api/projects/status/wbk31bj66di1qrk5?svg=true)](https://ci.appveyor.com/project/agracio/ts-progress)
[![Coverage Status](https://coveralls.io/repos/github/agracio/ts-progress/badge.svg?branch=master)](https://coveralls.io/github/agracio/ts-progress?branch=master)### Flexible node progress bar for Windows/macOS/Linux
![image](https://github.com/agracio/ts-progress/raw/master/screenshot.gif)
## Installation
```bash
npm install ts-progress
```
## Quickstart
```javascript
var Progress = require('ts-progress');var total = 50, count = 0;
var progress = Progress.create({total: total});
var iv = setInterval(function () {
count++;
progress.update();
if (count == total) {
clearInterval(iv);
}
}, 150);
```
## API### create(options)
Creates and returns new progress bar.
### update()
Updates progress.
### done()
Finishes progress regardless of progress stage. Optional.
## OptionsProgress bar accepts the following options on initialisation:
* `total: number` - Total number of items to process.
* `pattern: string` - Optional layout pattern, defaults to '*Progress: {bar} | Elapsed: {elapsed} | {percent}*'. See [Patterns](#patterns)
* `textColor: string` - Optional text color. See [Colors](#colors)
* `title: string` - Optional title to display above progress bar.
* `updateFrequency: number` - Optional update frequency limit in milliseconds. See [Update frequency](#update-frequency).```javascript
// with default options
var progress = Progress.create({total: 50});// with pattern
var progress = Progress.create({total: 50, pattern: 'Progress: {bar} | Remaining: {remaining} | {percent} '});//with pattern and text color
var progress = Progress.create({total: 50, pattern: 'Progress: {current}/{total} | Remaining: {remaining} | Elapsed: {elapsed} ', textColor: 'blue'});//with default options and title
var progress = Progress.create({total: 50, title: 'Waiting for results'});```
## Update frequency
When set limits progress bar update rate. Used to limit refresh rate for quickly running tasks.In the example below progress bar will only update every 150 milliseconds instead of updating 1000 times every millisecond. This will reduce resource allocation to progress bar.
```javascript
var Progress = require('ts-progress');var total = 1000, count = 0;
var progress = Progress.create({total: total, updateFrequency: 150});
var iv = setInterval(function () {
count++;
progress.update();
if (count == total) {
clearInterval(iv);
}
}, 1);
```
## Patterns
The following tokens are supported:* `{bar}` - progress bar.
* `{elapsed}` - elapsed time in seconds.
* `{remaining}` - estimated remaining time in seconds.
* `{percent}` - completion percentage
* `{memory}` - process memory usage in megabytes.
* `{current}` - current item.
* `{total}` - total items.### Token customisation
Tokens can be customized to define a color for each token.
Progress bar token accepts two colors for remaining/done items as well as length.Usage for all tokens except progress bar:
* `{token.color}`Usage for progress bar:
* `{bar.color.color.length}` - default is *{bar.white.green.20}*```javascript
var progress = Progress.create({total:50, pattern: 'Progress: {bar.white.red.10} | Remaining: {remaining.red} | {percent.blue}'});
```## Colors
Progress bar uses [charm](https://www.npmjs.com/package/charm) to render elements and supports charm string colors:
* `red`
* `yellow`
* `green`
* `blue`
* `cyan`
* `magenta`
* `black`
* `white`