1+ require ( 'core-js/es7/symbol.js' ) ;
12import * as chalk from 'chalk' ;
23import * as os from 'os' ;
34import { Banner , Gauge , Spinner , Sparkline , Progress , Line , LineBuffer } from './src/index'
45require ( 'draftlog' ) . into ( console ) ;
56
7+ export function sleep ( ms ) {
8+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
9+ }
610
711/********************/
812
9- var total = os . totalmem ( ) ;
10- var free = os . freemem ( ) ;
11- var used = total - free ;
12- var human = Math . ceil ( used / 1000000 ) + ' MB' ;
13+ const total = os . totalmem ( ) ;
14+ const free = os . freemem ( ) ;
15+ const used = total - free ;
16+ const human = Math . ceil ( used / 1000000 ) + ' MB' ;
1317console . log ( '' + new Gauge ( used , total , 20 , total * 0.8 , chalk . bold . grey ( human ) ) ) ;
1418
1519/********************/
@@ -74,7 +78,7 @@ const header = new Line(outputBuffer)
7478 . store ( ) ;
7579
7680let line ;
77- for ( var l = 0 ; l < 20 ; l ++ )
81+ for ( let l = 0 ; l < 20 ; l ++ )
7882{
7983 line = new Line ( outputBuffer )
8084 . column ( ( Math . random ( ) * 100 ) . toFixed ( 3 ) , 20 )
@@ -87,53 +91,60 @@ for(var l = 0; l < 20; l++)
8791
8892outputBuffer . output ( ) ;
8993
90-
91- /********************/
92-
93- const countdown = new Spinner ( 'Exiting in 10 seconds... ' ) ;
94-
95- countdown . start ( chalk . bgYellow . blue ) ;
96-
97- let number = 10 ;
98- setInterval ( function ( ) {
99- number -- ;
100- countdown . message = 'Exiting in ' + number + ' seconds... ' ;
101- if ( number === 0 ) {
102- process . stdout . write ( '\n' ) ;
103- process . exit ( 0 ) ;
104- }
105- } , 1000 ) ;
106-
107-
10894/********************/
10995
11096const banner = new Banner ( ' Node UI is Awesome! See what you can build with this module ' ) ;
11197
11298/********************/
11399
100+ async function * getProgressSlowly ( ) {
101+ let progress = 0 ;
114102
115- function startDownload ( ) {
116- let progress = 0
103+ while ( progress <= 100 ) {
104+ await sleep ( 50 ) ;
105+ progress += Math . round ( Math . random ( ) * 5 ) ;
106+ if ( progress >= 100 ) {
107+ yield 100 ;
108+ } else {
109+ yield progress ;
110+ }
111+ }
112+ }
113+
114+ async function startDownload ( ) {
115+ // let progress = 0;
117116 // let myProgress = new Progress();
118117 // let myProgress = new Progress(50, chalk.green('Finished download!'), chalk.red('|'), '-');
119118 let myProgress = new Progress ( 50 , chalk . green ( 'Finished download!' ) ) ;
120- let interval = setInterval ( ( ) => {
121- progress += Math . round ( Math . random ( ) * 5 )
122- if ( progress > 100 ) {
123- myProgress . update ( 100 , 100 )
124- clearInterval ( interval )
125- } else {
126- myProgress . update ( progress , 100 )
127- }
128- } , 50 )
119+
120+ for await ( let progress of getProgressSlowly ( ) ) {
121+ myProgress . update ( progress , 100 )
122+ }
129123}
130124
131125( async ( ) => {
132- console . log ( 'Starting downloads...' )
126+ console . log ( 'Starting downloads...' ) ;
133127 for ( let i = 0 ; i < 10 ; i ++ ) {
134128 startDownload ( )
135129 // await sleep(100)
136130 }
137131} ) ( ) ;
138132
133+
134+ /********************/
135+
136+ const countdown = new Spinner ( 'Exiting in 10 seconds... ' ) ;
137+
138+ countdown . start ( chalk . bgYellow . blue ) ;
139+
140+ let number = 20 ;
141+ setInterval ( function ( ) {
142+ number -- ;
143+ countdown . message = 'Exiting in ' + number + ' seconds... ' ;
144+ if ( number === 0 ) {
145+ process . stdout . write ( '\n' ) ;
146+ process . exit ( 0 ) ;
147+ }
148+ } , 1000 ) ;
149+
139150/********************/
0 commit comments