* Initialize a `ProgressBar` with the given `fmt` string and `options` or * `total`. * * Options: * * - `curr` current completed index * - `total` total number of ticks to complete * - `width` the displayed width of the progress bar defaulting to total * - `stream` the output stream
(fmt, options)
| 43 | */ |
| 44 | |
| 45 | function ProgressBar(fmt, options) { |
| 46 | this.stream = options.stream || process.stderr; |
| 47 | |
| 48 | if (typeof(options) == 'number') { |
| 49 | var total = options; |
| 50 | options = {}; |
| 51 | options.total = total; |
| 52 | } else { |
| 53 | options = options || {}; |
| 54 | if ('string' != typeof fmt) throw new Error('format required'); |
| 55 | if ('number' != typeof options.total) throw new Error('total required'); |
| 56 | } |
| 57 | |
| 58 | this.fmt = fmt; |
| 59 | this.curr = options.curr || 0; |
| 60 | this.total = options.total; |
| 61 | this.width = options.width || this.total; |
| 62 | this.clear = options.clear |
| 63 | this.chars = { |
| 64 | complete : options.complete || '=', |
| 65 | incomplete : options.incomplete || '-', |
| 66 | head : options.head || (options.complete || '=') |
| 67 | }; |
| 68 | this.renderThrottle = options.renderThrottle !== 0 ? (options.renderThrottle || 16) : 0; |
| 69 | this.callback = options.callback || function () {}; |
| 70 | this.tokens = {}; |
| 71 | this.lastDraw = ''; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * "tick" the progress bar with optional `len` and optional `tokens`. |
nothing calls this directly
no outgoing calls
no test coverage detected