-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.ts
97 lines (80 loc) · 2.07 KB
/
app.ts
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
import { DataProvider } from "./src/data-provider";
import {heatMap, labelbar} from "./src/visualization";
const blessed = require('blessed');
(async function main() {
const provider = new DataProvider();
// Create a screen object.
const theScreen = blessed.screen({
smartCSR: true
});
// theScreen.title = 'my window title';
// Create a box perfectly centered horizontally and vertically.
const box = blessed.box({
top: 'center',
left: 'center',
width: '100%',
height: '100%',
content: ``,
tags: true,
border: {
type: 'bg'
},
style: {
fg: 'white',
bg: 'purple',
border: {
bg: 'black'
}
}
});
const tempSet = labelbar({
parent: box,
label: 'temp',
value: 0,
unit: 'C',
useHeatMap: true,
bottom: 0
});
const memSet = labelbar({
parent: box,
label: 'mem',
value: 0,
unit: '%',
useHeatMap: true,
bottom: 2
});
const cpuSet = labelbar({
parent: box,
label: 'cpu',
value: 0,
unit: '%',
useHeatMap: true,
bottom: 4
});
const fsSet = labelbar({
parent: box,
label: 'btrfs',
value: 0,
unit: '%',
useHeatMap: true,
bottom: 6
});
// Append our box to the screen.
theScreen.append(box);
provider.on('data', function(data) {
box.setContent(`{bold}{red-fg}${data.hostname || ''}{/}`);
cpuSet.updateValue(Math.round(data.cpu) || 0);
tempSet.updateValue(data.temp || 0);
fsSet.updateValue(data.fsUsage ? data.fsUsage.usedPercent : 0);
memSet.updateValue(data.mem || 0);
theScreen.render();
});
// Quit on Escape, q, or Control-C.
theScreen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
// Focus our element.
box.focus();
// Render the screen.
theScreen.render();
})();