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.
Files changed (2) hide show
  1. package/bin/coffee-time.js +34 -5
  2. package/package.json +1 -1
@@ -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
- console.log(`☕ ${message}`);
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
- console.log(`⏳ Next break in ${formatRemaining(remaining)}`);
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
- console.log('\nStopped. Stay fresh ☕');
184
+ logLine('\nStopped. Stay fresh ☕');
156
185
  process.exit(0);
157
186
  };
158
187
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.2.0-beta.2",
6
+ "version": "1.2.0-beta.3",
7
7
  "description": "Lightweight CLI to schedule coffee breaks at a fixed interval.",
8
8
  "bin": {
9
9
  "coffee-time": "./bin/coffee-time.js"