1 |
|
2 | /*
|
3 | Terminal Kit
|
4 |
|
5 | Copyright (c) 2009 - 2020 Cédric Ronvel
|
6 |
|
7 | The MIT License (MIT)
|
8 |
|
9 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
10 | of this software and associated documentation files (the "Software"), to deal
|
11 | in the Software without restriction, including without limitation the rights
|
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13 | copies of the Software, and to permit persons to whom the Software is
|
14 | furnished to do so, subject to the following conditions:
|
15 |
|
16 | The above copyright notice and this permission notice shall be included in all
|
17 | copies or substantial portions of the Software.
|
18 |
|
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
25 | SOFTWARE.
|
26 | */
|
27 |
|
28 | ;
|
29 |
|
30 |
|
31 |
|
32 | /* jshint unused:false */
|
33 |
|
34 |
|
35 |
|
36 | var fs = require( 'fs' ) ;
|
37 | var term = require( '..' ).terminal ;
|
38 |
|
39 |
|
40 | var timeFactor = 10 ;
|
41 | var progress ;
|
42 | var progressBar ;
|
43 | var queuedFiles = [] , inProgressFiles = [] ;
|
44 |
|
45 |
|
46 |
|
47 | function doProgress() {
|
48 | var file ;
|
49 |
|
50 | if ( progress === undefined ) {
|
51 | if ( Math.random() < 0.1 ) {
|
52 | progress = 0 ;
|
53 | }
|
54 |
|
55 | progressBar.update( progress ) ;
|
56 | setTimeout( doProgress , 2 * timeFactor + Math.random() * 6 * timeFactor ) ;
|
57 | }
|
58 | else {
|
59 | if ( queuedFiles.length && ( ! inProgressFiles.length || Math.random() < 0.5 ) ) {
|
60 | //console.log( '\nstartItem\n' ) ;
|
61 | file = queuedFiles.shift() ;
|
62 | progressBar.startItem( file ) ;
|
63 | inProgressFiles.push( file ) ;
|
64 | }
|
65 | else {
|
66 | //console.log( '\nitemDone\n' ) ;
|
67 | progressBar.itemDone( inProgressFiles.shift() ) ;
|
68 |
|
69 | if ( ! inProgressFiles.length && queuedFiles.length ) {
|
70 | //console.log( '\nstartItem\n' ) ;
|
71 | file = queuedFiles.shift() ;
|
72 | progressBar.startItem( file ) ;
|
73 | inProgressFiles.push( file ) ;
|
74 | }
|
75 | }
|
76 |
|
77 | if ( queuedFiles.length + inProgressFiles.length === 0 ) {
|
78 | setTimeout(
|
79 | () => { term( '\n' ) ; process.exit() ; } ,
|
80 | 20 * timeFactor
|
81 | ) ;
|
82 | }
|
83 | else {
|
84 | setTimeout( doProgress , 20 * timeFactor + Math.random() * 20 * timeFactor ) ;
|
85 | }
|
86 | }
|
87 | }
|
88 |
|
89 | //term.bold( 'Analysing files: ' ) ;
|
90 |
|
91 | progressBar = term.progressBar( {
|
92 | width: 80 ,
|
93 | percent: true ,
|
94 | eta: true ,
|
95 | title: 'Analysing files:'
|
96 | //inline: true ,
|
97 | /*
|
98 | barStyle: term.brightGreen.bold ,
|
99 | barBracketStyle: term.brightWhite ,
|
100 | percentStyle: term.brightMagenta.inverse ,
|
101 | barChar: '~' ,
|
102 | barHeadChar: '*' ,
|
103 |
|
104 | //barChar: ' ' ,
|
105 | //barHeadChar: ' ' ,
|
106 | //barStyle: term.bgCyan
|
107 | //*/
|
108 | } ) ;
|
109 |
|
110 | //setTimeout( () => progressBar.reset() , 5000 ) ;
|
111 |
|
112 | term.column( 1 ) ;
|
113 |
|
114 | fs.readdir( __dirname , ( error , files ) => {
|
115 | if ( error ) { process.exit( 1 ) ; }
|
116 | queuedFiles = files ;
|
117 | progressBar.update( { items: files.length } ) ;
|
118 | doProgress() ;
|
119 | } ) ;
|
120 |
|