coffee-time 1.2.0-beta.2 → 1.2.0-beta.3
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 +34 -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,34 @@ 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 artLines = [
|
|
107
|
+
' ( (',
|
|
108
|
+
' ) )',
|
|
109
|
+
' ........',
|
|
110
|
+
' | |]',
|
|
111
|
+
' \\ /',
|
|
112
|
+
" '----'",
|
|
113
|
+
];
|
|
114
|
+
console.log(artLines.join('\n'));
|
|
115
|
+
}
|
|
116
|
+
|
|
105
117
|
function startLoop(intervalMinutes, options = {}) {
|
|
106
118
|
const { showStatus = false } = options;
|
|
119
|
+
let statusLength = 0;
|
|
120
|
+
let statusActive = false;
|
|
121
|
+
|
|
122
|
+
const logLine = (message) => {
|
|
123
|
+
if (statusActive) {
|
|
124
|
+
process.stdout.write('\n');
|
|
125
|
+
statusActive = false;
|
|
126
|
+
statusLength = 0;
|
|
127
|
+
}
|
|
128
|
+
console.log(message);
|
|
129
|
+
};
|
|
130
|
+
|
|
107
131
|
console.log(`Coffee breaks scheduled every ${intervalMinutes} minutes. Press Ctrl+C to stop.`);
|
|
132
|
+
printCoffeeArt();
|
|
108
133
|
|
|
109
134
|
const startedAt = Date.now();
|
|
110
135
|
const intervalMs = intervalMinutes * 60 * 1000;
|
|
@@ -115,13 +140,17 @@ function startLoop(intervalMinutes, options = {}) {
|
|
|
115
140
|
|
|
116
141
|
const logStatus = () => {
|
|
117
142
|
const remaining = nextTime - Date.now();
|
|
118
|
-
|
|
143
|
+
const message = `⏳ Next break in ${formatRemaining(remaining)}`;
|
|
144
|
+
const paddedMessage = message.padEnd(statusLength, ' ');
|
|
145
|
+
process.stdout.write(`\r${paddedMessage}`);
|
|
146
|
+
statusLength = message.length;
|
|
147
|
+
statusActive = true;
|
|
119
148
|
};
|
|
120
149
|
|
|
121
150
|
function scheduleNext() {
|
|
122
151
|
const delay = Math.max(0, nextTime - Date.now());
|
|
123
152
|
timeoutId = setTimeout(() => {
|
|
124
|
-
notify(intervalMinutes);
|
|
153
|
+
notify(intervalMinutes, logLine);
|
|
125
154
|
nextTime += intervalMs;
|
|
126
155
|
if (showStatus) {
|
|
127
156
|
logStatus();
|
|
@@ -152,7 +181,7 @@ function startLoop(intervalMinutes, options = {}) {
|
|
|
152
181
|
if (statusIntervalId) {
|
|
153
182
|
clearInterval(statusIntervalId);
|
|
154
183
|
}
|
|
155
|
-
|
|
184
|
+
logLine('\nStopped. Stay fresh ☕');
|
|
156
185
|
process.exit(0);
|
|
157
186
|
};
|
|
158
187
|
|