1 | CLI-Progress
|
2 | ============
|
3 | Easy to use Progress-Bar for Command-Line/Terminal Applications
|
4 |
|
5 | ```bash
|
6 | $ npm install cli-progress
|
7 | ```
|
8 |
|
9 | ![Demo](https://github.com/AndiDittrich/Node.CLI-Progress/raw/master/video.gif)
|
10 |
|
11 | Features
|
12 | --------
|
13 |
|
14 | * **Simple**, **Robust** and **Easy** to use
|
15 | * Full customizable output format (various placeholders are available)
|
16 | * Custom Bar Characters
|
17 | * FPS limiter
|
18 | * ETA calculation based on elapsed time
|
19 | * Only visible in TTY environments
|
20 | * No callbacks required - designed as pure, external controlled UI widget
|
21 | * Works in Asynchronous and Synchronous tasks
|
22 |
|
23 | *Successful tested on Windows10, Debian 8.2 and Ubuntu 14 LTS*
|
24 |
|
25 | Installation
|
26 | ------------
|
27 |
|
28 | You can install cli-progress with [NPM](http://www.npmjs.com/package/cli-progress)
|
29 |
|
30 | ```bash
|
31 | $ npm install cli-progress
|
32 | ```
|
33 |
|
34 | Or manually from the [GitHub Repository](https://github.com/AndiDittrich/Node.CLI-Progress/releases/latest)
|
35 |
|
36 | ```bash
|
37 | $ wget https://github.com/AndiDittrich/Node.CLI-Progress/archive/v1.1.0.tar.gz
|
38 | ```
|
39 |
|
40 | Progress-Bar
|
41 | ------------
|
42 |
|
43 | ### Getting Started ###
|
44 |
|
45 | You can find some basic examples in [example.js](https://github.com/AndiDittrich/Node.CLI-Progress/blob/master/example.js) - just run the file with `$ node example.js`
|
46 |
|
47 | ### Usage ###
|
48 |
|
49 | ```js
|
50 | var _progress = require('cli-progress');
|
51 |
|
52 | // create a new progress bar instance
|
53 | var bar1 = new _progress.Bar();
|
54 |
|
55 | // start the progress bar with a total value of 200 and start value of 0
|
56 | bar1.start(200, 0);
|
57 |
|
58 | // update the current value in your application..
|
59 | bar1.update(100);
|
60 |
|
61 | // stop the progress bar
|
62 | bar1.stop();
|
63 | ```
|
64 |
|
65 | ### Methods/Syntax ###
|
66 |
|
67 | #### Constructor ####
|
68 |
|
69 | Initialize a new Progress bar. An instance can be used **multiple** times! it's not required to re-create it!
|
70 |
|
71 | ```js
|
72 | var <instance> = new namespace.Bar(options:object);
|
73 | ```
|
74 |
|
75 | #### start() ####
|
76 |
|
77 | Starts the progress bar and set the total and initial value
|
78 |
|
79 | ```js
|
80 | <instance>.start(totalValue:int, startValue:int);
|
81 | ```
|
82 |
|
83 | #### update() ####
|
84 |
|
85 | Sets the current progress value
|
86 |
|
87 | ```js
|
88 | <instance>.update(currentValue:int);
|
89 | ```
|
90 |
|
91 | #### increment() ####
|
92 |
|
93 | Increases the current progress value by a specified amount (default +1)
|
94 |
|
95 | ```js
|
96 | <instance>.increment(delta:int);
|
97 | ```
|
98 |
|
99 | #### stop() ####
|
100 |
|
101 | Stops the progress bar and go to next line
|
102 |
|
103 | ```js
|
104 | <instance>.stop();
|
105 | ```
|
106 |
|
107 |
|
108 | ### Bar Formatting ###
|
109 |
|
110 | The progressbar can be customized by using the following build-in placeholders. They can be combined in any order.
|
111 |
|
112 | - `{bar}` - the progress bar, customizable by the options **barsize**, **barCompleteString** and **barIncompleteString**
|
113 | - `{percentage}` - the current progress in percent (0-100)
|
114 | - `{total}` - the end value
|
115 | - `{value}` - the current value set by last `update()` call
|
116 | - `{eta}` - expected time of accomplishment in seconds
|
117 | - `{duration}` - elapsed time in seconds
|
118 | - `{eta_formatted}` - expected time of accomplishment formatted into appropriate units
|
119 | - `{duration_formatted}` - elapsed time formatted into appropriate units
|
120 |
|
121 | #### Example ####
|
122 |
|
123 | ```
|
124 | progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}
|
125 | ```
|
126 |
|
127 | is rendered as
|
128 |
|
129 | ```
|
130 | progress [========================================] 100% | ETA: 0s | 200/200
|
131 | ```
|
132 |
|
133 | ### Options ###
|
134 |
|
135 | - `format` (type:string) - progress bar output format @see format section
|
136 | - `fps` (type:float) - the maximum update rate (default: 10)
|
137 | - `stream` (type:stream) - output stream to use (default: `process.stderr`)
|
138 | - `clearOnComplete` (type:boolean) - clear the progress bar on complete / `stop()` call (default: false)
|
139 | - `barsize` (type:int) - the length of the progress bar in chars (default: 40)
|
140 | - `barCompleteString` (type:char) - character to use as "complete" indicator in the bar (default: "=")
|
141 | - `barIncompleteString` (type:char) - character to use as "incomplete" indicator in the bar (default: "-")
|
142 | - `hideCursor` (type:boolean) - hide the cursor during progress operation; restored on complete (default: false)
|
143 | - `etaBuffer` (type:int) - number of updates with which to calculate the eta; higher numbers give a more stable eta (default: 10)
|
144 |
|
145 | #### Example ####
|
146 |
|
147 | ```js
|
148 | // change the progress characters
|
149 | // set fps limit to 5
|
150 | // change the output stream and barsize
|
151 | var b2 = new _progress.Bar({
|
152 | barCompleteChar: '#',
|
153 | barIncompleteChar: '.',
|
154 | fps: 5,
|
155 | stream: process.stdout,
|
156 | barsize: 65
|
157 | });
|
158 | ```
|
159 |
|
160 | Any Questions ? Report a Bug ? Enhancements ?
|
161 | ---------------------------------------------
|
162 | Please open a new issue on [GitHub](https://github.com/AndiDittrich/Node.CLI-Progress/issues)
|
163 |
|
164 | License
|
165 | -------
|
166 | CLI-Progress is OpenSource and licensed under the Terms of [The MIT License (X11)](http://opensource.org/licenses/MIT). You're welcome to [contribute](https://github.com/AndiDittrich/Node.CLI-Progress/blob/master/CONTRIBUTE.md)! |
\ | No newline at end of file |