-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·55 lines (43 loc) · 1.12 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
#!/usr/bin/env node
const scanner = require('./src/scanner')
, viewer = require('./src/viewer')
, history = scanner.history
, pages = viewer.pages
, kbEvents = viewer.keyboardEvents;
let scanStarted = false;
const gracefulExit = () => {
viewer.shutdown();
process.exit(0);
};
scanner.on('updated', () => {
return viewer.updateContent(history.current());
})
kbEvents.on('go_to_next', () => {
return viewer.updateContent(history.previous());
})
kbEvents.on('go_to_previous', () => {
return viewer.updateContent(history.next());;
})
kbEvents.on('go_to_first', () => {
return viewer.updateContent(history.first());
})
kbEvents.on('go_to_last', () => {
return viewer.updateContent(history.last());;
})
kbEvents.on('toggle_scan', () => {
if(scanStarted) {
return scanner.pause();
}
return scanner.start();
})
kbEvents.on('exit', () => {
viewer.loadPage(pages.exit, gracefulExit);
})
process.on('SIGINT', function() {
viewer.loadPage(pages.exit, gracefulExit);
})
process.on('SIGTERM', function() {
viewer.loadPage(pages.exit, gracefulExit);
})
viewer.loadPage(pages.welcome);
setTimeout(scanner.start, 1250);