-
Notifications
You must be signed in to change notification settings - Fork 0
/
src.js
102 lines (90 loc) · 2.08 KB
/
src.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* Pomonodeoro
* Copyright (c) 2023 Michael Kolesidis
* GNU General Public License v3.0
*/
const readline = require("readline");
const notifier = require("node-notifier");
process.stdout.write("\x1b[31mPomonodeoro 🍅\nv.0.1.0 \x1b[0m\n\n");
function timer(totalTime) {
let type;
switch (totalTime) {
case 25:
type = "Pomodoro";
break;
case 20:
type = "Long Break";
break;
case 5:
type = "Short Break";
break;
}
process.stdout.write(`\n${type}\n`);
let time = totalTime * 60;
let minutes, seconds;
setInterval(() => {
minutes = Math.floor(time / 60);
if (minutes < 10) {
minutes = `0${minutes}`;
}
seconds = time - minutes * 60;
if (seconds < 10) {
seconds = `0${seconds}`;
}
process.stdout.write(`\x1b[30m\x1b[47m${minutes} : ${seconds} \x1b[0m \r`);
time -= 1;
if (time === -1) {
if (type === "Pomodoro") {
process.stdout.write("Congratulations you finished a pomodoro!\n");
notifier.notify({
title: "Pomonodeoro",
message: "Congratulations you finished a pomodoro!",
});
process.exit();
} else {
notifier.notify({
title: "Pomonodeoro",
message: "The break is over!",
});
process.stdout.write("The break is over!\n");
process.exit();
}
}
}, 1000);
}
function readInput() {
const interface = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
return new Promise((resolve) =>
interface.question(
`Please choose an option:
[P] - Start new pomodoro (25 minutes)
[S] - Start new short break (5 minutes)
[L] - Start new long break (20 minutes)
[E] - Exit\n`,
(answer) => {
interface.close();
resolve(answer);
}
)
);
}
(async () => {
let answer = await readInput();
answer = answer.toUpperCase();
switch (answer) {
case "P":
timer(25);
break;
case "S":
timer(5);
break;
case "L":
timer(20);
break;
case "E":
process.exit();
}
})();