coffee-time 1.2.0-beta.2 → 1.2.0-beta.4
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/bin/coffee-time.js +93 -5
- package/package.json +1 -1
package/bin/coffee-time.js
CHANGED
|
@@ -89,9 +89,9 @@ function attemptNotification(command, args) {
|
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
function notify(intervalMinutes) {
|
|
92
|
+
function notify(intervalMinutes, logLine = console.log) {
|
|
93
93
|
const message = `Time for a coffee break! (${intervalMinutes} min interval)`;
|
|
94
|
-
|
|
94
|
+
logLine(`☕ ${message}`);
|
|
95
95
|
sendDesktopNotification(message).catch(() => {});
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -102,9 +102,90 @@ function formatRemaining(remainingMs) {
|
|
|
102
102
|
return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
function printCoffeeArt() {
|
|
106
|
+
const frames = [
|
|
107
|
+
[
|
|
108
|
+
' ( ( ',
|
|
109
|
+
' ) ) ',
|
|
110
|
+
' (((( ',
|
|
111
|
+
' ........',
|
|
112
|
+
' | |]',
|
|
113
|
+
' \\ /',
|
|
114
|
+
" '----'",
|
|
115
|
+
],
|
|
116
|
+
[
|
|
117
|
+
' ( ',
|
|
118
|
+
' ( ) ',
|
|
119
|
+
' ) )) ',
|
|
120
|
+
' ........',
|
|
121
|
+
' | |]',
|
|
122
|
+
' \\ /',
|
|
123
|
+
" '----'",
|
|
124
|
+
],
|
|
125
|
+
[
|
|
126
|
+
' ) ) ',
|
|
127
|
+
' ( ( ',
|
|
128
|
+
' (( ',
|
|
129
|
+
' ........',
|
|
130
|
+
' | |]',
|
|
131
|
+
' \\ /',
|
|
132
|
+
" '----'",
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
' ( ',
|
|
136
|
+
' ) ) ',
|
|
137
|
+
' ) ) ',
|
|
138
|
+
' ........',
|
|
139
|
+
' | |]',
|
|
140
|
+
' \\ /',
|
|
141
|
+
" '----'",
|
|
142
|
+
],
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const maxWidth = frames.reduce((width, frame) => (
|
|
146
|
+
Math.max(width, ...frame.map((line) => line.length))
|
|
147
|
+
), 0);
|
|
148
|
+
const normalizedFrames = frames.map((frame) => frame.map((line) => line.padEnd(maxWidth, ' ')));
|
|
149
|
+
const artHeight = normalizedFrames[0].length;
|
|
150
|
+
let frameIndex = 0;
|
|
151
|
+
|
|
152
|
+
const renderFrame = (isFirstFrame = false) => {
|
|
153
|
+
if (!isFirstFrame) {
|
|
154
|
+
process.stdout.write(`\u001B[${artHeight}A`);
|
|
155
|
+
}
|
|
156
|
+
process.stdout.write(`${normalizedFrames[frameIndex].join('\n')}\n`);
|
|
157
|
+
frameIndex = (frameIndex + 1) % normalizedFrames.length;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
renderFrame(true);
|
|
161
|
+
const intervalId = setInterval(() => renderFrame(), 200);
|
|
162
|
+
const timeoutId = setTimeout(() => {
|
|
163
|
+
clearInterval(intervalId);
|
|
164
|
+
}, 4000);
|
|
165
|
+
|
|
166
|
+
return () => {
|
|
167
|
+
clearInterval(intervalId);
|
|
168
|
+
clearTimeout(timeoutId);
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
105
172
|
function startLoop(intervalMinutes, options = {}) {
|
|
106
173
|
const { showStatus = false } = options;
|
|
174
|
+
let statusLength = 0;
|
|
175
|
+
let statusActive = false;
|
|
176
|
+
let stopCoffeeArt = () => {};
|
|
177
|
+
|
|
178
|
+
const logLine = (message) => {
|
|
179
|
+
if (statusActive) {
|
|
180
|
+
process.stdout.write('\n');
|
|
181
|
+
statusActive = false;
|
|
182
|
+
statusLength = 0;
|
|
183
|
+
}
|
|
184
|
+
console.log(message);
|
|
185
|
+
};
|
|
186
|
+
|
|
107
187
|
console.log(`Coffee breaks scheduled every ${intervalMinutes} minutes. Press Ctrl+C to stop.`);
|
|
188
|
+
stopCoffeeArt = printCoffeeArt();
|
|
108
189
|
|
|
109
190
|
const startedAt = Date.now();
|
|
110
191
|
const intervalMs = intervalMinutes * 60 * 1000;
|
|
@@ -115,13 +196,17 @@ function startLoop(intervalMinutes, options = {}) {
|
|
|
115
196
|
|
|
116
197
|
const logStatus = () => {
|
|
117
198
|
const remaining = nextTime - Date.now();
|
|
118
|
-
|
|
199
|
+
const message = `⏰ Next break in ${formatRemaining(remaining)}`;
|
|
200
|
+
const paddedMessage = message.padEnd(statusLength, ' ');
|
|
201
|
+
process.stdout.write(`\r${paddedMessage}`);
|
|
202
|
+
statusLength = message.length;
|
|
203
|
+
statusActive = true;
|
|
119
204
|
};
|
|
120
205
|
|
|
121
206
|
function scheduleNext() {
|
|
122
207
|
const delay = Math.max(0, nextTime - Date.now());
|
|
123
208
|
timeoutId = setTimeout(() => {
|
|
124
|
-
notify(intervalMinutes);
|
|
209
|
+
notify(intervalMinutes, logLine);
|
|
125
210
|
nextTime += intervalMs;
|
|
126
211
|
if (showStatus) {
|
|
127
212
|
logStatus();
|
|
@@ -152,7 +237,10 @@ function startLoop(intervalMinutes, options = {}) {
|
|
|
152
237
|
if (statusIntervalId) {
|
|
153
238
|
clearInterval(statusIntervalId);
|
|
154
239
|
}
|
|
155
|
-
|
|
240
|
+
if (stopCoffeeArt) {
|
|
241
|
+
stopCoffeeArt();
|
|
242
|
+
}
|
|
243
|
+
logLine('\nStopped. Stay fresh ☕');
|
|
156
244
|
process.exit(0);
|
|
157
245
|
};
|
|
158
246
|
|