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

Class MultiBar

lib/multi-bar.js:7–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5
6// Progress-Bar constructor
7module.exports = class MultiBar extends _EventEmitter{
8
9 constructor(options, preset){
10 super();
11
12 // list of bars
13 this.bars = [];
14
15 // parse+store options
16 this.options = _options.parse(options, preset);
17
18 // disable synchronous updates
19 this.options.synchronousUpdate = false;
20
21 // store terminal instance
22 this.terminal = (this.options.terminal) ? this.options.terminal : new _Terminal(this.options.stream);
23
24 // the update timer
25 this.timer = null;
26
27 // progress bar active ?
28 this.isActive = false;
29
30 // update interval
31 this.schedulingRate = (this.terminal.isTTY() ? this.options.throttleTime : this.options.notTTYSchedule);
32
33 // logging output buffer
34 this.loggingBuffer = [];
35
36 // callback used for gracefulExit
37 this.sigintCallback = null;
38 }
39
40 // add a new bar to the stack
41 create(total, startValue, payload, barOptions={}){
42 // create new bar element
43 const bar = new _BarElement(Object.assign({}, this.options, barOptions));
44
45 // store bar
46 this.bars.push(bar);
47
48 // progress updates are only visible in TTY mode!
49 if (this.options.noTTYOutput === false && this.terminal.isTTY() === false){
50 return bar;
51 }
52
53 // add handler to restore cursor settings (stop the bar) on SIGINT/SIGTERM ?
54 if (this.sigintCallback === null && this.options.gracefulExit){
55 this.sigintCallback = this.stop.bind(this);
56 process.once('SIGINT', this.sigintCallback);
57 process.once('SIGTERM', this.sigintCallback);
58 }
59
60 // multiprogress already active ?
61 if (!this.isActive){
62 // hide the cursor ?
63 if (this.options.hideCursor === true){
64 this.terminal.cursor(false);

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…