1 | var _progress = require('./main');
|
2 |
|
3 |
|
4 | Example1(function(){
|
5 | Example2(function(){
|
6 | console.log('\nDemo finished!');
|
7 | });
|
8 | });
|
9 |
|
10 | function Example1(onComplete){
|
11 |
|
12 | console.log('\nExample 1 - Standard configuration (4s)');
|
13 |
|
14 | var b1 = new _progress.Bar();
|
15 | b1.start(200, 0);
|
16 |
|
17 |
|
18 | var value = 0;
|
19 |
|
20 |
|
21 | var timer = setInterval(function(){
|
22 |
|
23 | value++;
|
24 |
|
25 |
|
26 | b1.update(value)
|
27 |
|
28 |
|
29 | if (value >= b1.getTotal()){
|
30 |
|
31 | clearInterval(timer);
|
32 |
|
33 | b1.stop();
|
34 |
|
35 |
|
36 | onComplete.apply(this);
|
37 | }
|
38 | }, 20);
|
39 | }
|
40 |
|
41 |
|
42 | function Example2(onComplete){
|
43 |
|
44 | console.log('\nExample 2 - Custom configuration');
|
45 |
|
46 |
|
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 |
|
58 | var timer = setInterval(function(){
|
59 |
|
60 | b2.increment();
|
61 |
|
62 |
|
63 | if (b2.value >= b2.getTotal()){
|
64 |
|
65 | clearInterval(timer);
|
66 |
|
67 | b2.stop();
|
68 |
|
69 |
|
70 | onComplete.apply(this);
|
71 | }
|
72 | }, 50);
|
73 | };
|