File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ const readline = require ( 'readline' ) ;
2
+ var config = { "text" :"Progress: " , "indicator" :"=" , "pLength" :100 } ;
3
+ function setProgress ( progress ) {
4
+ let r1 = readline . createInterface ( {
5
+ input : process . stdin ,
6
+ output : process . stdout
7
+ } ) ;
8
+ let cursorPosition = readline . getCursorPos ;
9
+ let step = ( config . pLength * progress ) / 100 ; //pLength:100=x:progress
10
+ let text = config . text ;
11
+ let indicator = config . indicator ;
12
+ readline . cursorTo ( process . stdout , 0 , cursorPosition ) ;
13
+ readline . clearLine ( process . stdout , 0 ) ;
14
+ readline . cursorTo ( process . stdout , 0 , cursorPosition ) ;
15
+ r1 . write ( text + " |" ) ;
16
+ for ( let i = 0 ; i < config . pLength ; i ++ ) {
17
+ if ( i >= Math . round ( step ) ) {
18
+ r1 . write ( " " ) ;
19
+ } else {
20
+ r1 . write ( indicator ) ;
21
+ }
22
+ }
23
+ r1 . write ( "| " + progress + "%" ) ;
24
+ r1 . close ( ) ;
25
+ }
26
+ function setConfig ( ) {
27
+ for ( let i = 0 ; i < arguments . length ; i ++ ) {
28
+ let splitted = arguments [ i ] . split ( ":" ) ;
29
+ if ( i == 3 ) {
30
+ config [ splitted [ 0 ] ] = parseInt ( splitted [ 1 ] )
31
+ } else {
32
+ config [ splitted [ 0 ] ] = splitted [ 1 ] ;
33
+ }
34
+ } ;
35
+ }
36
+ module . exports = { setProgress, setConfig} ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " ascii-progressbar" ,
3
+ "version" : " 1.0.1" ,
4
+ "description" : " A simple ascii progressbar" ,
5
+ "main" : " main.js" ,
6
+ "scripts" : {
7
+ "test" : " echo \" Error: no test specified\" && exit 1"
8
+ },
9
+ "repository" : {
10
+ "type" : " git" ,
11
+ "url" : " git+https://github.com/MatteoBax/ascii-progressbar.git"
12
+ },
13
+ "author" : " matteobax" ,
14
+ "license" : " ISC" ,
15
+ "bugs" : {
16
+ "url" : " https://github.com/MatteoBax/ascii-progressbar/issues"
17
+ },
18
+ "homepage" : " https://github.com/MatteoBax/ascii-progressbar#readme"
19
+ }
You can’t perform that action at this time.
0 commit comments