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

Class SingleBar

lib/single-bar.js:5–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3
4// Progress-Bar constructor
5module.exports = class SingleBar extends _GenericBar{
6
7 constructor(options, preset){
8 super(_options.parse(options, preset));
9
10 // the update timer
11 this.timer = null;
12
13 // disable synchronous updates in notty mode
14 if (this.options.noTTYOutput && this.terminal.isTTY() === false){
15 this.options.synchronousUpdate = false;
16 }
17
18 // update interval
19 this.schedulingRate = (this.terminal.isTTY() ? this.options.throttleTime : this.options.notTTYSchedule);
20
21 // callback used for gracefulExit
22 this.sigintCallback = null;
23 }
24
25 // internal render function
26 render(){
27 // stop timer
28 if (this.timer){
29 clearTimeout(this.timer);
30 this.timer = null;
31 }
32
33 // run internal rendering
34 super.render();
35
36 // add new line in notty mode!
37 if (this.options.noTTYOutput && this.terminal.isTTY() === false){
38 this.terminal.newline();
39 }
40
41 // next update
42 this.timer = setTimeout(this.render.bind(this), this.schedulingRate);
43 }
44
45 update(current, payload){
46 // timer inactive ?
47 if (!this.timer) {
48 return;
49 }
50
51 super.update(current, payload);
52
53 // trigger synchronous update ?
54 // check for throttle time
55 if (this.options.synchronousUpdate && (this.lastRedraw + this.options.throttleTime*2) < Date.now()){
56 // force update
57 this.render();
58 }
59 }
60
61 // start the progress bar
62 start(total, startValue, payload){

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…