-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (57 loc) · 1.43 KB
/
index.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
#!/usr/bin/env node
const blessed = require("blessed");
const calculateScreenSize = require("./utils/calculateScreenSize");
const ConfigError = require("./exceptions/ConfigError");
const configChecker = require("./utils/configChecker");
const configReader = require("./utils/configReader");
const contrib = require("blessed-contrib");
const program = require("commander");
const TailLib = require("tail").Tail;
const widgetFactory = require("./utils/widgetFactory");
program
.option(
"-c, --config [path]",
"Path to the config file to use",
"./config.json"
)
.parse(process.argv);
const config = configReader(program.config);
try {
configChecker(config);
} catch (e) {
if (e instanceof ConfigError) {
console.error(e.message);
process.exit(1);
}
}
const screen = blessed.screen({
smartCSR: true,
autoPadding: true
});
const grid = new contrib.grid({
...calculateScreenSize(config),
screen: screen
});
const widgets = widgetFactory(grid, config);
const tail = new TailLib(config.source);
tail.on("line", function(line) {
line = line.trim();
if (!line.length) {
return;
}
widgets.forEach(widget => {
widget.newLine(line);
});
});
tail.on("error", function(error) {
console.log("ERROR: ", error);
});
screen.key(["escape", "q", "C-c"], function(ch, key) {
return process.exit(0);
});
screen.key(["r"], function(ch, key) {
widgets.forEach(widget => {
widget.reset();
});
});
screen.render();