-
Notifications
You must be signed in to change notification settings - Fork 10
/
basic.js
53 lines (43 loc) · 1.01 KB
/
basic.js
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
import React from 'react';
import {render, Text, Color} from 'ink';
import ProgressBar from '../src';
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
const TASKS = 30;
class ProgressApp extends React.Component {
constructor() {
super();
this.state = {
done: 0
};
}
render() {
const text = 'Running ';
return (
<>
<Text green>
{text}
</Text>
<Color red>
<ProgressBar
left={text.length}
percent={this.state.done / TASKS}
/>
</Color>
</>
);
}
componentDidMount() {
const promises = Array.from({length: TASKS}, () => {
return delay(Math.floor(Math.random() * 1500))
.then(() => {
this.setState(state => ({
done: state.done + 1
}));
});
});
Promise.all(promises)
.then(() => delay(50))
.then(() => process.exit(0)); // eslint-disable-line unicorn/no-process-exit
}
}
render(<ProgressApp/>);