-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
progressbar.jsx
62 lines (54 loc) · 1.41 KB
/
progressbar.jsx
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
import React, {Component} from 'react';
import blessed from 'blessed';
import {render} from '../src';
class ProgressBox extends Component {
constructor(props) {
super(props);
this.state = {
position: 0,
toRight: true
};
setInterval(() => {
const {position, toRight} = this.state,
newDirection = position === (toRight ? 90 : 0) ? !toRight : toRight,
newPosition = newDirection ? position + 1 : position - 1;
this.setState({
position: newPosition,
toRight: newDirection
});
}, 30);
}
render() {
const position = `${this.state.position}%`;
return (
<box
top="center"
left="0"
width="10%"
height="20%"
border={{type: 'line'}}
style={{bg: 'cyan', border: {fg: 'blue'}}}>
<progressbar
orientation="horizontal"
filled={this.state.position}
top="80%"
left="center"
height="15%"
width="100%"
label="progress"
border={{type: 'line'}}
style={{border: {fg: 'red'}, bar: {bg: 'red'}}}
/>
</box>
);
}
}
const screen = blessed.screen({
autoPadding: true,
smartCSR: true,
title: 'react-blessed box animation'
});
screen.key(['escape', 'q', 'C-c'], function (ch, key) {
return process.exit(0);
});
render(<ProgressBox />, screen, inst => console.log('Rendered ProgressBox!'));