coffee-time 1.2.0-beta.3 → 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.
Files changed (2) hide show
  1. package/bin/coffee-time.js +69 -10
  2. package/package.json +1 -1
@@ -103,21 +103,77 @@ function formatRemaining(remainingMs) {
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.4",
7
7
  "description": "Lightweight CLI to schedule coffee breaks at a fixed interval.",
8
8
  "bin": {
9
9
  "coffee-time": "./bin/coffee-time.js"