coffee-time 1.0.1 → 1.2.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/bin/coffee-time.js +43 -5
- package/package.json +19 -4
package/README.md
CHANGED
|
@@ -34,13 +34,22 @@ Start a continuous break loop with a required interval (minutes):
|
|
|
34
34
|
coffee-time start --interval 45
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
Add a lightweight countdown ping every minute:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
coffee-time start --interval 45 --status
|
|
41
|
+
```
|
|
42
|
+
|
|
37
43
|
---
|
|
38
44
|
|
|
39
45
|
## What happens
|
|
40
46
|
|
|
41
47
|
* Prints a single startup line:
|
|
42
48
|
`Coffee breaks scheduled every 45 minutes. Press Ctrl+C to stop.`
|
|
49
|
+
* Optional status flag (`--status`) prints a countdown update every minute:
|
|
50
|
+
`⏳ Next break in 44:00`
|
|
43
51
|
* Waits 45 minutes, then triggers a break notification.
|
|
52
|
+
* After each break, countdown updates continue when `--status` is enabled.
|
|
44
53
|
* Immediately schedules the next interval and repeats until you stop it (`Ctrl+C`).
|
|
45
54
|
|
|
46
55
|
---
|
package/bin/coffee-time.js
CHANGED
|
@@ -24,11 +24,14 @@ function parseArgs(argv) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
let intervalMinutes;
|
|
27
|
+
let showStatus = false;
|
|
27
28
|
for (let i = 0; i < rest.length; i += 1) {
|
|
28
29
|
const token = rest[i];
|
|
29
30
|
if (token === '--interval') {
|
|
30
31
|
intervalMinutes = rest[i + 1];
|
|
31
32
|
i += 1;
|
|
33
|
+
} else if (token === '--status') {
|
|
34
|
+
showStatus = true;
|
|
32
35
|
} else {
|
|
33
36
|
console.error(`Unknown option: ${token}`);
|
|
34
37
|
printUsage();
|
|
@@ -48,7 +51,7 @@ function parseArgs(argv) {
|
|
|
48
51
|
process.exit(USAGE_ERROR);
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
return parsedInterval;
|
|
54
|
+
return { intervalMinutes: parsedInterval, showStatus };
|
|
52
55
|
}
|
|
53
56
|
|
|
54
57
|
function sendDesktopNotification(message) {
|
|
@@ -92,28 +95,63 @@ function notify(intervalMinutes) {
|
|
|
92
95
|
sendDesktopNotification(message).catch(() => {});
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
function
|
|
98
|
+
function formatRemaining(remainingMs) {
|
|
99
|
+
const totalSeconds = Math.max(0, Math.ceil(remainingMs / 1000));
|
|
100
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
101
|
+
const seconds = totalSeconds % 60;
|
|
102
|
+
return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function startLoop(intervalMinutes, options = {}) {
|
|
106
|
+
const { showStatus = false } = options;
|
|
96
107
|
console.log(`Coffee breaks scheduled every ${intervalMinutes} minutes. Press Ctrl+C to stop.`);
|
|
97
108
|
|
|
109
|
+
const startedAt = Date.now();
|
|
98
110
|
const intervalMs = intervalMinutes * 60 * 1000;
|
|
99
|
-
let nextTime =
|
|
111
|
+
let nextTime = startedAt + intervalMs;
|
|
100
112
|
let timeoutId = null;
|
|
113
|
+
let statusIntervalId = null;
|
|
114
|
+
let statusTimeoutId = null;
|
|
115
|
+
|
|
116
|
+
const logStatus = () => {
|
|
117
|
+
const remaining = nextTime - Date.now();
|
|
118
|
+
console.log(`⏳ Next break in ${formatRemaining(remaining)}`);
|
|
119
|
+
};
|
|
101
120
|
|
|
102
121
|
function scheduleNext() {
|
|
103
122
|
const delay = Math.max(0, nextTime - Date.now());
|
|
104
123
|
timeoutId = setTimeout(() => {
|
|
105
124
|
notify(intervalMinutes);
|
|
106
125
|
nextTime += intervalMs;
|
|
126
|
+
if (showStatus) {
|
|
127
|
+
logStatus();
|
|
128
|
+
}
|
|
107
129
|
scheduleNext();
|
|
108
130
|
}, delay);
|
|
109
131
|
}
|
|
110
132
|
|
|
111
133
|
scheduleNext();
|
|
112
134
|
|
|
135
|
+
if (showStatus) {
|
|
136
|
+
const elapsed = Date.now() - startedAt;
|
|
137
|
+
const firstDelay = Math.max(0, 60 * 1000 - (elapsed % (60 * 1000)));
|
|
138
|
+
|
|
139
|
+
statusTimeoutId = setTimeout(() => {
|
|
140
|
+
logStatus();
|
|
141
|
+
statusIntervalId = setInterval(logStatus, 60 * 1000);
|
|
142
|
+
}, firstDelay);
|
|
143
|
+
}
|
|
144
|
+
|
|
113
145
|
const handleExit = () => {
|
|
114
146
|
if (timeoutId) {
|
|
115
147
|
clearTimeout(timeoutId);
|
|
116
148
|
}
|
|
149
|
+
if (statusTimeoutId) {
|
|
150
|
+
clearTimeout(statusTimeoutId);
|
|
151
|
+
}
|
|
152
|
+
if (statusIntervalId) {
|
|
153
|
+
clearInterval(statusIntervalId);
|
|
154
|
+
}
|
|
117
155
|
console.log('\nStopped. Stay fresh ☕');
|
|
118
156
|
process.exit(0);
|
|
119
157
|
};
|
|
@@ -124,8 +162,8 @@ function startLoop(intervalMinutes) {
|
|
|
124
162
|
|
|
125
163
|
function main() {
|
|
126
164
|
try {
|
|
127
|
-
const intervalMinutes = parseArgs(process.argv);
|
|
128
|
-
startLoop(intervalMinutes);
|
|
165
|
+
const { intervalMinutes, showStatus } = parseArgs(process.argv);
|
|
166
|
+
startLoop(intervalMinutes, { showStatus });
|
|
129
167
|
} catch (error) {
|
|
130
168
|
console.error('Unexpected error:', error.message);
|
|
131
169
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.2.0-beta.2",
|
|
7
7
|
"description": "Lightweight CLI to schedule coffee breaks at a fixed interval.",
|
|
8
8
|
"bin": {
|
|
9
9
|
"coffee-time": "./bin/coffee-time.js"
|
|
@@ -13,7 +13,22 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"start": "node ./bin/coffee-time.js"
|
|
15
15
|
},
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/tborges/coffee-time"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"Coffee Time",
|
|
22
|
+
"Coffee-time",
|
|
23
|
+
"coffee-break",
|
|
24
|
+
"coffee break",
|
|
25
|
+
"Template",
|
|
26
|
+
"coffee",
|
|
27
|
+
"break",
|
|
28
|
+
"productivity",
|
|
29
|
+
"cli",
|
|
30
|
+
"developer",
|
|
31
|
+
"timer",
|
|
32
|
+
"reminder"
|
|
33
|
+
]
|
|
19
34
|
}
|