BlueGit

blue-star danique-bot

Files

danique-bot / node_modules / progress / Readme.md

Readme.md

Import template
timfa Tim · pushed by timfa · 4 years ago
c788ad20 History
Readme.md 2.3 KiB Download Raw

Flexible ascii progress bar.

Installation

$ npm install progress

Usage

First we create a ProgressBar, giving it a format string as well as the total, telling the progress bar when it will be considered complete. After that all we need to do is tick() appropriately.

var ProgressBar = require('progress');

var bar = new ProgressBar(':bar', { total: 10 });
var timer = setInterval(function () {
  bar.tick();
  if (bar.complete) {
    console.log('\ncomplete\n');
    clearInterval(timer);
  }
}, 100);

Options

These are keys in the options object you can pass to the progress bar along with total as seen in the example above.

  • total total number of ticks to complete
  • width the displayed width of the progress bar defaulting to total
  • stream the output stream defaulting to stderr
  • complete completion character defaulting to "="
  • incomplete incomplete character defaulting to "-"
  • clear option to clear the bar on completion defaulting to false
  • callback optional function to call when the progress bar completes

Tokens

These are tokens you can use in the format of your progress bar.

  • :bar the progress bar itself
  • :current current tick number
  • :total total ticks
  • :elapsed time elapsed in seconds
  • :percent completion percentage
  • :eta estimated completion time in seconds

Examples

Download

In our download example each tick has a variable influence, so we pass the chunk length which adjusts the progress bar appropriately relative to the total length.

var ProgressBar = require('../');
var https = require('https');

var req = https.request({
  host: 'download.github.com',
  port: 443,
  path: '/visionmedia-node-jscoverage-0d4608a.zip'
});

req.on('response', function(res){
  var len = parseInt(res.headers['content-length'], 10);

  console.log();
  var bar = new ProgressBar('  downloading [:bar] :percent :etas', {
    complete: '=',
    incomplete: ' ',
    width: 20,
    total: len
  });

  res.on('data', function (chunk) {
    bar.tick(chunk.length);
  });

  res.on('end', function () {
    console.log('\n');
  });
});

req.end();

The above example result in a progress bar like the one below.

downloading [=====             ] 29% 3.7s

You can see more examples in the examples folder.

License

MIT

Source
1Flexible ascii progress bar.
2
3## Installation
4
5```bash
6$ npm install progress
7```
8
9## Usage
10
11First we create a `ProgressBar`, giving it a format string
12as well as the `total`, telling the progress bar when it will
13be considered complete. After that all we need to do is `tick()` appropriately.
14
15```javascript
16var ProgressBar = require('progress');
17
18var bar = new ProgressBar(':bar', { total: 10 });
19var timer = setInterval(function () {
20 bar.tick();
21 if (bar.complete) {
22 console.log('\ncomplete\n');
23 clearInterval(timer);
24 }
25}, 100);
26```
27
28### Options
29
30These are keys in the options object you can pass to the progress bar along with
31`total` as seen in the example above.
32
33- `total` total number of ticks to complete
34- `width` the displayed width of the progress bar defaulting to total
35- `stream` the output stream defaulting to stderr
36- `complete` completion character defaulting to "="
37- `incomplete` incomplete character defaulting to "-"
38- `clear` option to clear the bar on completion defaulting to false
39- `callback` optional function to call when the progress bar completes
40
41### Tokens
42
43These are tokens you can use in the format of your progress bar.
44
45- `:bar` the progress bar itself
46- `:current` current tick number
47- `:total` total ticks
48- `:elapsed` time elapsed in seconds
49- `:percent` completion percentage
50- `:eta` estimated completion time in seconds
51
52## Examples
53
54### Download
55
56In our download example each tick has a variable influence, so we pass the chunk
57length which adjusts the progress bar appropriately relative to the total
58length.
59
60```javascript
61var ProgressBar = require('../');
62var https = require('https');
63
64var req = https.request({
65 host: 'download.github.com',
66 port: 443,
67 path: '/visionmedia-node-jscoverage-0d4608a.zip'
68});
69
70req.on('response', function(res){
71 var len = parseInt(res.headers['content-length'], 10);
72
73 console.log();
74 var bar = new ProgressBar(' downloading [:bar] :percent :etas', {
75 complete: '=',
76 incomplete: ' ',
77 width: 20,
78 total: len
79 });
80
81 res.on('data', function (chunk) {
82 bar.tick(chunk.length);
83 });
84
85 res.on('end', function () {
86 console.log('\n');
87 });
88});
89
90req.end();
91```
92
93The above example result in a progress bar like the one below.
94
95```
96downloading [===== ] 29% 3.7s
97```
98
99You can see more examples in the `examples` folder.
100
101## License
102
103MIT