-
Notifications
You must be signed in to change notification settings - Fork 0
/
pomodoro.ts
64 lines (58 loc) · 1.57 KB
/
pomodoro.ts
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
import { Command, flags } from "@oclif/command";
import notifier from "node-notifier";
import * as inquirer from "inquirer";
import chalk from "chalk";
import { Answers } from "inquirer";
import dayjs from "dayjs";
export default class Pomodoro extends Command {
static description = "Set a pomodoro timer.";
static flags = {
custom: flags.boolean({
char: "c",
description: "Add a custom time",
}),
};
async run() {
const { flags } = this.parse(Pomodoro);
if (flags.custom) {
const question: Answers = await inquirer.prompt([
{
type: "input",
name: "customTime",
message: "Add a custom time in minutes.",
validate: (time: string) => {
if (time.length < 1) {
return chalk.red("uh oh! you haven't added a time yet.");
}
return true;
},
},
]);
this.setTime(question.customTime);
} else {
this.setTime();
}
}
notifier = () => {
notifier.notify({
title: "My notification",
message: "Well done, you earned your break 😁!!",
sound: "Glass",
wait: true,
});
};
setTime = (timeout: string = "25") => {
// convert time to milliseconds
const time = parseInt(timeout) * 60 * 1000;
const newTime = dayjs().add(parseInt(timeout), "minute");
console.log(
chalk.yellow(
"\n",
`Setting timer for ${timeout} minutes. \n Your break finishes at ${newTime.format(
"hh:mm:ss"
)}`
)
);
setTimeout(this.notifier, time);
};
}