1+ import * as chalk from 'chalk' ;
2+ import { Banner , Spinner , Sparkline , Progress , Line , LineBuffer } from './src/index'
3+ require ( 'draftlog' ) . into ( console ) ;
4+
5+
6+
7+ const reqsPerSec = [ 10 , 12 , 3 , 7 , 12 , 9 , 23 , 10 , 9 , 19 , 16 , 18 , 12 , 12 ] ;
8+
9+ console . log ( new Sparkline ( reqsPerSec , 'reqs/sec' ) . toString ( ) ) ;
10+
11+ /********************/
12+
13+ const thisProgressBar = new Progress ( 20 ) ;
14+ console . log ( thisProgressBar . update ( 40 , 100 ) ) ;
15+
16+ /********************/
17+
18+
19+ const headers = new Line ( )
20+ . padding ( 2 )
21+ . column ( 'Column One' , 20 , [ chalk . cyan ] )
22+ . column ( 'Column Two' , 20 , [ chalk . cyan ] )
23+ . column ( 'Column Three' , 20 , [ chalk . cyan ] )
24+ . column ( 'Column Four' , 20 , [ chalk . cyan ] )
25+ . fill ( )
26+ . output ( ) ;
27+
28+ const body = new Line ( )
29+ . padding ( 2 )
30+ . column ( ( Math . random ( ) * 100 ) . toFixed ( 3 ) , 20 )
31+ . column ( ( Math . random ( ) * 100 ) . toFixed ( 3 ) , 20 )
32+ . column ( ( Math . random ( ) * 100 ) . toFixed ( 3 ) , 20 )
33+ . column ( ( Math . random ( ) * 100 ) . toFixed ( 3 ) , 20 )
34+ . fill ( )
35+ . output ( ) ;
36+
37+
38+
39+ /********************/
40+
41+
42+ const outputBuffer = new LineBuffer ( {
43+ x : 0 ,
44+ y : 0 ,
45+ width : 'console' ,
46+ height : 'console'
47+ } ) ;
48+
49+ const message = new Line ( outputBuffer )
50+ . column ( 'Title Placehole' , 20 , [ chalk . green ] )
51+ . fill ( )
52+ . store ( ) ;
53+
54+ const blankLine = new Line ( outputBuffer )
55+ . fill ( )
56+ . store ( ) ;
57+
58+ const header = new Line ( outputBuffer )
59+ . column ( 'Suscipit' , 20 , [ chalk . cyan ] )
60+ . column ( 'Voluptatem' , 20 , [ chalk . cyan ] )
61+ . column ( 'Nesciunt' , 20 , [ chalk . cyan ] )
62+ . column ( 'Laudantium' , 11 , [ chalk . cyan ] )
63+ . fill ( )
64+ . store ( ) ;
65+
66+ let line ;
67+ for ( var l = 0 ; l < 20 ; l ++ )
68+ {
69+ line = new Line ( outputBuffer )
70+ . column ( ( Math . random ( ) * 100 ) . toFixed ( 3 ) , 20 )
71+ . column ( ( Math . random ( ) * 100 ) . toFixed ( 3 ) , 20 )
72+ . column ( ( Math . random ( ) * 100 ) . toFixed ( 3 ) , 20 )
73+ . column ( ( Math . random ( ) * 100 ) . toFixed ( 3 ) , 11 )
74+ . fill ( )
75+ . store ( ) ;
76+ }
77+
78+ outputBuffer . output ( ) ;
79+
80+
81+ /********************/
82+
83+ const countdown = new Spinner ( 'Exiting in 10 seconds... ' ) ;
84+
85+ countdown . start ( chalk . bgYellow . blue ) ;
86+
87+ let number = 10 ;
88+ setInterval ( function ( ) {
89+ number -- ;
90+ countdown . message = 'Exiting in ' + number + ' seconds... ' ;
91+ if ( number === 0 ) {
92+ process . stdout . write ( '\n' ) ;
93+ process . exit ( 0 ) ;
94+ }
95+ } , 1000 ) ;
96+
97+
98+ /********************/
99+
100+ const banner = new Banner ( ' Node UI is Awesome! See what you can build with this module ' ) ;
101+
102+ /********************/
103+
104+
105+ function startDownload ( ) {
106+ let progress = 0
107+ // let myProgress = new Progress();
108+ // let myProgress = new Progress(50, chalk.green('Finished download!'), chalk.red('|'), '-');
109+ let myProgress = new Progress ( 50 , chalk . green ( 'Finished download!' ) ) ;
110+ let interval = setInterval ( ( ) => {
111+ progress += Math . round ( Math . random ( ) * 5 )
112+ if ( progress > 100 ) {
113+ myProgress . update ( 100 , 100 )
114+ clearInterval ( interval )
115+ } else {
116+ myProgress . update ( progress , 100 )
117+ }
118+ } , 50 )
119+ }
120+
121+ ( async ( ) => {
122+ console . log ( 'Starting downloads...' )
123+ for ( let i = 0 ; i < 10 ; i ++ ) {
124+ startDownload ( )
125+ // await sleep(100)
126+ }
127+ } ) ( ) ;
128+
129+ /********************/
0 commit comments