MCPcopy Create free account
hub / github.com/npkgz/cli-progress / GenericBar

Class GenericBar

lib/generic-bar.js:7–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5
6// Progress-Bar constructor
7module.exports = class GenericBar extends _EventEmitter{
8
9 constructor(options){
10 super();
11
12 // store options
13 this.options = options;
14
15 // store terminal instance
16 this.terminal = (this.options.terminal) ? this.options.terminal : new _Terminal(this.options.stream);
17
18 // the current bar value
19 this.value = 0;
20
21 // bar start value (used for progress calculation)
22 this.startValue = 0;
23
24 // the end value of the bar
25 this.total = 100;
26
27 // last drawn string - only render on change!
28 this.lastDrawnString = null;
29
30 // start time (used for eta calculation)
31 this.startTime = null;
32
33 // stop time (used for duration calculation)
34 this.stopTime = null;
35
36 // last update time
37 this.lastRedraw = Date.now();
38
39 // default eta calculator (will be re-create on start)
40 this.eta = new _ETA(this.options.etaBufferLength, 0, 0);
41
42 // payload data
43 this.payload = {};
44
45 // progress bar active ?
46 this.isActive = false;
47
48 // use default formatter or custom one ?
49 this.formatter = (typeof this.options.format === 'function') ? this.options.format : _formatter;
50 }
51
52 // internal render function
53 render(forceRendering=false){
54
55 // formatter params
56 const params = {
57 progress: this.getProgress(),
58 eta: this.eta.getTime(),
59 startTime: this.startTime,
60 stopTime: this.stopTime,
61 total: this.total,
62 value: this.value,
63 maxWidth: this.terminal.getWidth()
64 };

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…