culater 1.1.0 → 1.1.2
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/lib/server.js +12 -9
- package/package.json +1 -1
package/lib/server.js
CHANGED
|
@@ -375,12 +375,14 @@ function sleep(ms) {
|
|
|
375
375
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
-
function createCliSpinner(
|
|
378
|
+
function createCliSpinner(initialLabel, color = '36') {
|
|
379
379
|
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
380
380
|
const isTty = Boolean(process.stdout.isTTY);
|
|
381
381
|
let timer = null;
|
|
382
382
|
let frameIndex = 0;
|
|
383
383
|
let started = false;
|
|
384
|
+
let label = initialLabel;
|
|
385
|
+
let startTime = null;
|
|
384
386
|
|
|
385
387
|
const clearLine = () => {
|
|
386
388
|
process.stdout.write('\r\x1b[2K');
|
|
@@ -389,13 +391,16 @@ function createCliSpinner(label, color = '36') {
|
|
|
389
391
|
const render = () => {
|
|
390
392
|
const frame = frames[frameIndex % frames.length];
|
|
391
393
|
frameIndex += 1;
|
|
392
|
-
|
|
394
|
+
const elapsed = startTime ? Math.floor((Date.now() - startTime) / 1000) : 0;
|
|
395
|
+
const sec = elapsed > 0 ? ` \x1b[90m${elapsed}s\x1b[0m` : '';
|
|
396
|
+
process.stdout.write(`\r\x1b[2K\x1b[${color}m${frame}\x1b[0m ${label}${sec}`);
|
|
393
397
|
};
|
|
394
398
|
|
|
395
399
|
return {
|
|
396
400
|
start() {
|
|
397
401
|
if (started) return;
|
|
398
402
|
started = true;
|
|
403
|
+
startTime = Date.now();
|
|
399
404
|
if (!isTty) {
|
|
400
405
|
console.log(label);
|
|
401
406
|
return;
|
|
@@ -403,6 +408,9 @@ function createCliSpinner(label, color = '36') {
|
|
|
403
408
|
render();
|
|
404
409
|
timer = setInterval(render, 90);
|
|
405
410
|
},
|
|
411
|
+
update(newLabel) {
|
|
412
|
+
label = newLabel;
|
|
413
|
+
},
|
|
406
414
|
stop(message = '') {
|
|
407
415
|
if (!started) return;
|
|
408
416
|
started = false;
|
|
@@ -498,13 +506,8 @@ async function createTunnel() {
|
|
|
498
506
|
registrationSpinner = createCliSpinner('Connecting');
|
|
499
507
|
registrationSpinner.start();
|
|
500
508
|
fallbackTimer = setTimeout(() => {
|
|
501
|
-
if (!announced) {
|
|
502
|
-
|
|
503
|
-
registrationSpinner.stop();
|
|
504
|
-
registrationSpinner = null;
|
|
505
|
-
}
|
|
506
|
-
console.error('\x1b[33mStill connecting; showing URL anyway.\x1b[0m');
|
|
507
|
-
announceReady();
|
|
509
|
+
if (!announced && registrationSpinner) {
|
|
510
|
+
registrationSpinner.update('Still connecting to Cloudflare edge');
|
|
508
511
|
}
|
|
509
512
|
}, TUNNEL_REGISTRATION_WAIT_MS);
|
|
510
513
|
}
|