-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard.js
82 lines (73 loc) · 1.89 KB
/
dashboard.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
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
import blessed from 'blessed';
import contrib from 'blessed-contrib';
import { getBannerText } from './banner.js';
export function createDashboard() {
const screen = blessed.screen({
smartCSR: true,
title: 'Stork Network BOT Dashboard'
});
const grid = new contrib.grid({ rows: 12, cols: 12, screen: screen });
const bannerBox = grid.set(0, 0, 3, 12, blessed.box, {
label: 'BANNER',
content: getBannerText(),
tags: false,
align: 'center',
valign: 'middle',
style: {
fg: 'white',
bg: 'black'
},
border: {
type: 'line'
}
});
const statsTable = grid.set(3, 0, 3, 12, contrib.table, {
keys: true,
fg: 'white',
label: 'STATS',
columnSpacing: 2,
columnWidth: [30, 15, 15, 30]
});
const logBox = grid.set(6, 0, 6, 12, contrib.log, {
label: 'LOGS',
fg: 'green',
selectedFg: 'green',
scrollbar: {
ch: ' ',
track: { bg: 'grey' },
style: { inverse: true }
}
});
screen.key(['escape', 'q', 'C-c'], function () {
process.exit(0);
});
screen.render();
return { screen, statsTable, logBox };
}
/**
* @param {Object} statsTable
* @param {Object} data
*/
export function updateStats(statsTable, data) {
const tableData = {
headers: ['User', 'Valid', 'Invalid', 'Last Verified'],
data: [
[
data.user || 'N/A',
data.valid || 0,
data.invalid || 0,
data.lastVerified || 'Never'
]
]
};
statsTable.setData(tableData);
statsTable.screen.render();
}
/**
* @param {Object} logBox
* @param {String} msg
*/
export function logMessage(logBox, msg) {
logBox.log(msg);
logBox.screen.render();
}