@kud/foxhop-cli 1.1.1 → 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.
Files changed (2) hide show
  1. package/dist/cli.js +50 -21
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -289,6 +289,20 @@ var clearScripts = (dir = defaultScriptsDir()) => {
289
289
 
290
290
  // src/cli.ts
291
291
  import { fileURLToPath as fileURLToPath2 } from "url";
292
+
293
+ // src/ui.ts
294
+ var enabled = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
295
+ var paint = (code) => (text) => enabled ? `\x1B[${code}m${text}\x1B[0m` : text;
296
+ var bold = paint(1);
297
+ var dim = paint(2);
298
+ var red = paint(31);
299
+ var green = paint(32);
300
+ var yellow = paint(33);
301
+ var cyan = paint(36);
302
+ var ok = (message) => `${green("\u2713")} ${message}`;
303
+ var fail = (message) => `${red("\u2717")} ${message}`;
304
+
305
+ // src/cli.ts
292
306
  var browserApp = () => process.env.FOXHOP_BROWSER ?? "Firefox Nightly";
293
307
  var runOpen = (args) => {
294
308
  const child = spawn("/usr/bin/open", args, {
@@ -341,7 +355,9 @@ var focus = defineCommand({
341
355
  } : resolveNamed(String(args.name ?? ""));
342
356
  if (!request) {
343
357
  console.error(
344
- `foxhop: no target named "${args.name}". Edit ${CONFIG_PATH}, or run \`foxhop list\` / \`foxhop init\`.`
358
+ fail(
359
+ `no target named "${args.name}". Edit ${CONFIG_PATH}, or run \`foxhop list\` / \`foxhop init\`.`
360
+ )
345
361
  );
346
362
  process.exit(1);
347
363
  }
@@ -349,15 +365,15 @@ var focus = defineCommand({
349
365
  const ack = await sendToHost(request);
350
366
  if (ack?.ok && ack.action !== "not-found") foreground();
351
367
  else
352
- console.error(
353
- `foxhop: ${ack?.error ?? "no matching tab and no url to open"}`
354
- );
368
+ console.error(fail(ack?.error ?? "no matching tab and no url to open"));
355
369
  } catch {
356
370
  if ("url" in request && request.url) {
357
371
  openUrl(request.url);
358
372
  } else {
359
373
  console.error(
360
- "foxhop: cannot reach the host \u2014 is Firefox running with the foxhop extension?"
374
+ fail(
375
+ "cannot reach the host \u2014 is Firefox running with the foxhop extension?"
376
+ )
361
377
  );
362
378
  process.exit(1);
363
379
  }
@@ -386,7 +402,9 @@ var list = defineCommand({
386
402
  }
387
403
  if (!targets.length) {
388
404
  console.log(
389
- `No targets yet. Run \`foxhop init\` for an example, or edit ${CONFIG_PATH}.`
405
+ dim(
406
+ `No targets yet. Run \`foxhop init\` for an example, or edit ${CONFIG_PATH}.`
407
+ )
390
408
  );
391
409
  return;
392
410
  }
@@ -394,9 +412,12 @@ var list = defineCommand({
394
412
  ...targets.filter((target) => target.favorite),
395
413
  ...targets.filter((target) => !target.favorite)
396
414
  ];
415
+ const width = Math.max(...ordered.map((target) => target.name.length));
397
416
  for (const target of ordered) {
398
- const star = target.favorite ? "\u2605 " : " ";
399
- console.log(`${star}${target.name.padEnd(16)} ${target.match}`);
417
+ const star = target.favorite ? yellow("\u2605") : " ";
418
+ console.log(
419
+ `${star} ${cyan(target.name.padEnd(width))} ${dim(target.match)}`
420
+ );
400
421
  }
401
422
  }
402
423
  });
@@ -412,13 +433,13 @@ var tabs = defineCommand({
412
433
  }
413
434
  if (!openTabs.length) {
414
435
  console.error(
415
- "foxhop: no tabs (is Firefox running with the foxhop extension?)"
436
+ fail("no tabs \u2014 is Firefox running with the foxhop extension?")
416
437
  );
417
438
  process.exit(1);
418
439
  }
419
440
  for (const tab of openTabs) {
420
- console.log(`${tab.title}
421
- ${tab.url}`);
441
+ console.log(`${bold(tab.title)}
442
+ ${dim(tab.url)}`);
422
443
  }
423
444
  }
424
445
  });
@@ -429,7 +450,7 @@ var init = defineCommand({
429
450
  },
430
451
  run: () => {
431
452
  const path = writeExampleConfig();
432
- console.log(`foxhop: wrote example config and schema next to ${path}`);
453
+ console.log(ok(`wrote example config + schema \u2192 ${dim(path)}`));
433
454
  }
434
455
  });
435
456
  var installCommand = defineCommand({
@@ -463,7 +484,9 @@ var syncCommand = defineCommand({
463
484
  return;
464
485
  }
465
486
  console.log(
466
- `foxhop: removed ${cleared.removed} script(s) from ${cleared.dir}`
487
+ ok(
488
+ `removed ${bold(String(cleared.removed))} script(s) \u2192 ${dim(cleared.dir)}`
489
+ )
467
490
  );
468
491
  return;
469
492
  }
@@ -477,10 +500,14 @@ var syncCommand = defineCommand({
477
500
  return;
478
501
  }
479
502
  console.log(
480
- `foxhop: wrote ${result.written} script(s)` + (result.removed ? `, removed ${result.removed} stale` : "") + ` in ${result.dir}`
503
+ ok(
504
+ `wrote ${bold(String(result.written))} script(s)` + (result.removed ? `, removed ${result.removed} stale` : "") + ` \u2192 ${dim(result.dir)}`
505
+ )
481
506
  );
482
507
  console.log(
483
- "Add that folder in Raycast \u2192 Extensions \u2192 Script Commands \u2192 Add Directories, then assign hotkeys."
508
+ dim(
509
+ "Add that folder in Raycast \u2192 Extensions \u2192 Script Commands \u2192 Add Directories, then assign hotkeys."
510
+ )
484
511
  );
485
512
  }
486
513
  });
@@ -519,7 +546,7 @@ var add = defineCommand({
519
546
  const matchArg = args.match ? String(args.match) : void 0;
520
547
  const source = url ?? matchArg;
521
548
  if (!source) {
522
- console.error("foxhop: provide a URL or --match");
549
+ console.error(fail("provide a URL or --match"));
523
550
  process.exit(1);
524
551
  }
525
552
  const derived = deriveTarget(source);
@@ -534,7 +561,7 @@ var add = defineCommand({
534
561
  pick: args.pick,
535
562
  favorite: args.favorite || existing?.favorite ? true : void 0
536
563
  });
537
- console.log(`foxhop: saved "${name}"`);
564
+ console.log(ok(`saved ${bold(name)}`));
538
565
  autoSync();
539
566
  }
540
567
  });
@@ -550,10 +577,10 @@ var remove = defineCommand({
550
577
  run: ({ args }) => {
551
578
  const { removed } = removeTarget(String(args.name));
552
579
  if (!removed) {
553
- console.error(`foxhop: no target named "${args.name}"`);
580
+ console.error(fail(`no target named "${args.name}"`));
554
581
  process.exit(1);
555
582
  }
556
- console.log(`foxhop: removed "${args.name}"`);
583
+ console.log(ok(`removed ${bold(String(args.name))}`));
557
584
  autoSync();
558
585
  }
559
586
  });
@@ -572,11 +599,13 @@ var fav = defineCommand({
572
599
  run: ({ args }) => {
573
600
  const { favorite, found } = toggleFavorite(String(args.name));
574
601
  if (!found) {
575
- console.error(`foxhop: no target named "${args.name}"`);
602
+ console.error(fail(`no target named "${args.name}"`));
576
603
  process.exit(1);
577
604
  }
578
605
  console.log(
579
- `foxhop: "${args.name}" ${favorite ? "favourited \u2605" : "unfavourited"}`
606
+ ok(
607
+ `${bold(String(args.name))} ${favorite ? yellow("favourited \u2605") : "unfavourited"}`
608
+ )
580
609
  );
581
610
  }
582
611
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kud/foxhop-cli",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "foxhop CLI and native messaging host — focus specific Firefox tabs from macOS",
5
5
  "type": "module",
6
6
  "license": "MIT",