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

Function Example6

examples/example.js:171–207  ·  view source on GitHub ↗
(onComplete)

Source from the content-addressed store, hash-verified

169
170
171function Example6(onComplete){
172 // EXAMPLE 1 ---------------------------------------------
173 console.log('\nExample 6 - Set dynamically the total progress');
174 // create new progress bar using default values
175 const b1 = new _progress.Bar({}, _progress.Presets.shades_grey);
176 b1.start(200, 0);
177
178 // the bar value - will be linear incremented
179 let value = 0;
180
181 // 50ms update rate
182 const timer = setInterval(function(){
183 // increment value
184 value++;
185
186 // update the bar value
187 b1.update(value)
188
189 // change the total value
190 if (value > 1500){
191 b1.setTotal(3000);
192 }else if (value > 150){
193 b1.setTotal(2000);
194 }
195
196 // limit reached ?
197 if (value >= b1.getTotal()){
198 // stop timer
199 clearInterval(timer);
200
201 b1.stop();
202
203 // run complete callback
204 onComplete.apply(this);
205 }
206 }, 15);
207}

Callers 1

example.jsFile · 0.85

Calls 6

logMethod · 0.80
setTotalMethod · 0.80
getTotalMethod · 0.80
startMethod · 0.45
updateMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…