-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexamples.ts
More file actions
150 lines (114 loc) · 3.5 KB
/
examples.ts
File metadata and controls
150 lines (114 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
require('core-js/es7/symbol.js');
import * as chalk from 'chalk';
import * as os from 'os';
import {Banner, Gauge, Spinner, Sparkline, Progress, Line, LineBuffer} from './src/index'
require('draftlog').into(console);
export function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
/********************/
const total = os.totalmem();
const free = os.freemem();
const used = total - free;
const human = Math.ceil(used / 1000000) + ' MB';
console.log('' + new Gauge(used, total, 20, total * 0.8, chalk.bold.grey(human)));
/********************/
const reqsPerSec = [10,12,3,7,12,9,23,10,9,19,16,18,12,12];
console.log(new Sparkline(reqsPerSec, 'reqs/sec').toString());
/********************/
const thisProgressBar = new Progress(20);
console.log(thisProgressBar.update(40, 100));
/********************/
const headers = new Line()
.padding(2)
.column('Column One', 20, [chalk.cyan])
.column('Column Two', 20, [chalk.cyan])
.column('Column Three', 20, [chalk.cyan])
.column('Column Four', 20, [chalk.cyan])
.fill()
.output();
const body = new Line()
.padding(2)
.column((Math.random()*100).toFixed(3), 20)
.column((Math.random()*100).toFixed(3), 20)
.column((Math.random()*100).toFixed(3), 20)
.column((Math.random()*100).toFixed(3), 20)
.fill()
.output();
/********************/
const outputBuffer = new LineBuffer({
x: 0,
y: 0,
width: 'console',
height: 'console'
});
const message = new Line(outputBuffer)
.column('Title Placehole', 20, [chalk.green])
.fill()
.store();
const blankLine = new Line(outputBuffer)
.fill()
.store();
const header = new Line(outputBuffer)
.column('Suscipit', 20, [chalk.cyan])
.column('Voluptatem', 20, [chalk.cyan])
.column('Nesciunt', 20, [chalk.cyan])
.column('Laudantium', 11, [chalk.cyan])
.fill()
.store();
let line;
for(let l = 0; l < 20; l++)
{
line = new Line(outputBuffer)
.column((Math.random()*100).toFixed(3), 20)
.column((Math.random()*100).toFixed(3), 20)
.column((Math.random()*100).toFixed(3), 20)
.column((Math.random()*100).toFixed(3), 11)
.fill()
.store();
}
outputBuffer.output();
/********************/
const banner = new Banner(' Node UI is Awesome! See what you can build with this module ');
/********************/
async function* getProgressSlowly() {
let progress = 0;
while (progress <= 100) {
await sleep(50);
progress += Math.round(Math.random() * 5);
if (progress >= 100) {
yield 100;
} else {
yield progress;
}
}
}
async function startDownload() {
// let progress = 0;
// let myProgress = new Progress();
// let myProgress = new Progress(50, chalk.green('Finished download!'), chalk.red('|'), '-');
let myProgress = new Progress(50, chalk.green('Finished download!'));
for await (let progress of getProgressSlowly()) {
myProgress.update(progress, 100)
}
}
(async () => {
console.log('Starting downloads...');
for (let i = 0; i < 10; i ++) {
startDownload()
// await sleep(100)
}
})();
/********************/
const countdown = new Spinner('Exiting in 10 seconds... ');
countdown.start(chalk.bgYellow.blue);
let number = 20;
setInterval(function () {
number--;
countdown.message = 'Exiting in ' + number + ' seconds... ';
if (number === 0) {
process.stdout.write('\n');
process.exit(0);
}
}, 1000);
/********************/