-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·73 lines (59 loc) · 1.68 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
69
70
71
72
73
#!/usr/bin/env node
/**
* hocus
* CLI Based Pomodoro Timer
*
* @author emrahburak <github.com/emrahburak>
*
*
*/
const { soundPlayer } = require('./lib/player');
const Service = require('./lib/service');
const Cons = require('./lib/constants');
const Event = require('./lib/event');
const Print = require('one-line-print');
const keypress = require('keypress');
const init = require('./utils/init');
const cli = require('./utils/cli');
const log = require('./utils/log');
const input = cli.input;
const flags = cli.flags;
const { clear, debug } = flags;
//We enable production or development mode in the code below.
process.env.NODE_ENV = Cons.mode.PROD;
const isDev = process.env.NODE_ENV !== Cons.mode.PROD;
// The service layer; validates the input,
// counts down teh time entered by the user,
// returns wtih sound ,
// exits the script
(async () => {
init({ clear });
input.includes(`help`) && cli.showHelp(0);
const options = {
duration: flags.time,
path: flags.path
};
await Service.run(options)
.then(res => soundPlayer(res))
.then(() => Print.newLine(`Done, ${Cons.topic.DONE}`))
.then(() => process.exit());
debug && log(flags);
})();
//In the code below , we pause or quit the script according
// to the keyboard inputs at runtime
keypress(process.stdin);
!isDev ? process.stdin.setRawMode(true) : console.log(process.env.NODE_ENV);
let isPaused = false;
process.stdin.on('keypress', function (ch, key) {
if (key) {
if (key.ctrl && key.name === 'c') {
Print.newLine('quitting...');
process.exit();
}
if (key.name === 'space') {
isPaused = !isPaused;
Event.publisher(Cons.commands.EMIT_COUNTER);
isPaused && Print.newLine('\t--paused--');
}
}
});