coffee-time 1.2.0-beta.3 → 1.2.0-beta.5

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 CHANGED
@@ -47,7 +47,7 @@ coffee-time start --interval 45 --status
47
47
  * Prints a single startup line:
48
48
  `Coffee breaks scheduled every 45 minutes. Press Ctrl+C to stop.`
49
49
  * Optional status flag (`--status`) prints a countdown update every minute:
50
- `⏳ Next break in 44:00`
50
+ `⏰ Next break in 44 minutes`
51
51
  * Waits 45 minutes, then triggers a break notification.
52
52
  * After each break, countdown updates continue when `--status` is enabled.
53
53
  * Immediately schedules the next interval and repeats until you stop it (`Ctrl+C`).
@@ -97,27 +97,83 @@ function notify(intervalMinutes, logLine = console.log) {
97
97
 
98
98
  function formatRemaining(remainingMs) {
99
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')}`;
100
+ const minutes = Math.max(0, Math.ceil(totalSeconds / 60));
101
+ const unit = minutes === 1 ? 'minute' : 'minutes';
102
+ return `${minutes} ${unit}`;
103
103
  }
104
104
 
105
105
  function printCoffeeArt() {
106
- const artLines = [
107
- ' ( (',
108
- ' ) )',
109
- ' ........',
110
- ' | |]',
111
- ' \\ /',
112
- " '----'",
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
+ ],
113
143
  ];
114
- console.log(artLines.join('\n'));
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
+ };
115
170
  }
116
171
 
117
172
  function startLoop(intervalMinutes, options = {}) {
118
173
  const { showStatus = false } = options;
119
174
  let statusLength = 0;
120
175
  let statusActive = false;
176
+ let stopCoffeeArt = () => {};
121
177
 
122
178
  const logLine = (message) => {
123
179
  if (statusActive) {
@@ -129,7 +185,7 @@ function startLoop(intervalMinutes, options = {}) {
129
185
  };
130
186
 
131
187
  console.log(`Coffee breaks scheduled every ${intervalMinutes} minutes. Press Ctrl+C to stop.`);
132
- printCoffeeArt();
188
+ stopCoffeeArt = printCoffeeArt();
133
189
 
134
190
  const startedAt = Date.now();
135
191
  const intervalMs = intervalMinutes * 60 * 1000;
@@ -140,7 +196,7 @@ function startLoop(intervalMinutes, options = {}) {
140
196
 
141
197
  const logStatus = () => {
142
198
  const remaining = nextTime - Date.now();
143
- const message = `⏳ Next break in ${formatRemaining(remaining)}`;
199
+ const message = `⏰ Next break in ${formatRemaining(remaining)}`;
144
200
  const paddedMessage = message.padEnd(statusLength, ' ');
145
201
  process.stdout.write(`\r${paddedMessage}`);
146
202
  statusLength = message.length;
@@ -181,6 +237,9 @@ function startLoop(intervalMinutes, options = {}) {
181
237
  if (statusIntervalId) {
182
238
  clearInterval(statusIntervalId);
183
239
  }
240
+ if (stopCoffeeArt) {
241
+ stopCoffeeArt();
242
+ }
184
243
  logLine('\nStopped. Stay fresh ☕');
185
244
  process.exit(0);
186
245
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.2.0-beta.3",
6
+ "version": "1.2.0-beta.5",
7
7
  "description": "Lightweight CLI to schedule coffee breaks at a fixed interval.",
8
8
  "bin": {
9
9
  "coffee-time": "./bin/coffee-time.js"