UNPKG

1.81 kBJavaScriptView Raw
1var _progress = require('./main');
2
3// run the example sequentially! otherwise both will write to stdout/stderr simultaneous !
4Example1(function(){
5 Example2(function(){
6 console.log('\nDemo finished!');
7 });
8});
9
10function Example1(onComplete){
11 // EXAMPLE 1 ---------------------------------------------
12 console.log('\nExample 1 - Standard configuration (4s)');
13 // create new progress bar using default values
14 var b1 = new _progress.Bar();
15 b1.start(200, 0);
16
17 // the bar value - will be linear incremented
18 var value = 0;
19
20 // 20ms update rate
21 var timer = setInterval(function(){
22 // increment value
23 value++;
24
25 // update the bar value
26 b1.update(value)
27
28 // set limit
29 if (value >= b1.getTotal()){
30 // stop timer
31 clearInterval(timer);
32
33 b1.stop();
34
35 // run complete callback
36 onComplete.apply(this);
37 }
38 }, 20);
39}
40
41
42function Example2(onComplete){
43 // EXAMPLE 2 ---------------------------------------------
44 console.log('\nExample 2 - Custom configuration');
45
46 // create new progress bar using default values
47 var b2 = new _progress.Bar({
48 barCompleteChar: '#',
49 barIncompleteChar: '_',
50 format: ' |- Current Upload Progress: {percentage}%' + ' - ' + '||{bar}||',
51 fps: 5,
52 stream: process.stdout,
53 barsize: 30
54 });
55 b2.start(100, 0);
56
57 // 50ms update rate
58 var timer = setInterval(function(){
59 // increment value
60 b2.increment();
61
62 // set limit
63 if (b2.value >= b2.getTotal()){
64 // stop timer
65 clearInterval(timer);
66
67 b2.stop();
68
69 // run complete callback
70 onComplete.apply(this);
71 }
72 }, 50);
73};