@timmy6942025/cli-timer 1.1.13 → 1.1.14

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
@@ -49,7 +49,7 @@ By default, timer and stopwatch output is centered in the terminal.
49
49
 
50
50
  - `p` or `Spacebar`: Pause/Resume
51
51
  - `r`: Restart
52
- - `f`: Change style/font
52
+ - `f`: Random style/font
53
53
  - `q`, `e` or `Ctrl+C`: Exit
54
54
 
55
55
  ## Font Styles
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@timmy6942025/cli-timer",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "description": "Simple customizable terminal timer and stopwatch",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -436,6 +436,30 @@ function setFontInConfig(requestedFont) {
436
436
  return { ok: true, reason: null, font: updated.font };
437
437
  }
438
438
 
439
+ function pickRandomFont(fonts, currentFont) {
440
+ if (!Array.isArray(fonts) || fonts.length === 0) {
441
+ return null;
442
+ }
443
+ if (fonts.length === 1) {
444
+ return fonts[0];
445
+ }
446
+
447
+ let candidate = currentFont;
448
+ for (let attempt = 0; attempt < 8 && candidate === currentFont; attempt += 1) {
449
+ candidate = fonts[Math.floor(Math.random() * fonts.length)];
450
+ }
451
+
452
+ if (candidate === currentFont) {
453
+ const currentIndex = fonts.findIndex((fontName) => fontName === currentFont);
454
+ if (currentIndex >= 0) {
455
+ return fonts[(currentIndex + 1) % fonts.length];
456
+ }
457
+ return fonts[0];
458
+ }
459
+
460
+ return candidate;
461
+ }
462
+
439
463
  function parseDurationArgs(args) {
440
464
  if (args.length === 0 || args.length % 2 !== 0) {
441
465
  return { ok: false, error: "Duration must be in <number> <unit> pairs." };
@@ -525,7 +549,7 @@ function controlsHelpLine(keybindings) {
525
549
  const restart = keyTokenToLabel(keybindings.restartKey);
526
550
  const style = keyTokenToLabel(keybindings.styleKey);
527
551
  const exit = `${keyTokenToLabel(keybindings.exitKey)}/${keyTokenToLabel(keybindings.exitAltKey)}/Ctrl+C`;
528
- return `Controls: ${pause} Pause-Resume | ${restart} Restart | ${style} Style | ${exit} Exit`;
552
+ return `Controls: ${pause} Pause-Resume | ${restart} Restart | ${style} Random Style | ${exit} Exit`;
529
553
  }
530
554
 
531
555
  function keyTokenFromInput(chunk) {
@@ -993,9 +1017,10 @@ function runClock({ mode, initialSeconds, config }) {
993
1017
  if (fonts.length === 0) {
994
1018
  return;
995
1019
  }
996
- const currentIndex = fonts.findIndex((fontName) => fontName === config.font);
997
- const nextIndex = currentIndex >= 0 ? (currentIndex + 1) % fonts.length : 0;
998
- const nextFont = fonts[nextIndex];
1020
+ const nextFont = pickRandomFont(fonts, config.font);
1021
+ if (!nextFont) {
1022
+ return;
1023
+ }
999
1024
  const updated = setFontInConfig(nextFont);
1000
1025
  config.font = updated.ok ? updated.font : nextFont;
1001
1026
  lastDrawState = "";
@@ -1216,7 +1241,7 @@ function printUsage() {
1216
1241
  process.stdout.write("Settings\n");
1217
1242
  process.stdout.write(" timer settings\n\n");
1218
1243
  process.stdout.write("Controls\n");
1219
- process.stdout.write(" Defaults: p/Space Pause-Resume | r Restart | f Style | q/e/Ctrl+C Exit\n");
1244
+ process.stdout.write(" Defaults: p/Space Pause-Resume | r Restart | f Random Style | q/e/Ctrl+C Exit\n");
1220
1245
  process.stdout.write(" Keybindings are customizable in `timer settings`.\n\n");
1221
1246
  process.stdout.write("Font Styles\n");
1222
1247
  process.stdout.write(" timer style\n");
@@ -1276,7 +1301,12 @@ function runTimer(args) {
1276
1301
  process.exitCode = 1;
1277
1302
  return;
1278
1303
  }
1279
- const randomFont = fonts[Math.floor(Math.random() * fonts.length)];
1304
+ const randomFont = pickRandomFont(fonts, getFontFromConfig());
1305
+ if (!randomFont) {
1306
+ process.stderr.write("No fonts are available.\n");
1307
+ process.exitCode = 1;
1308
+ return;
1309
+ }
1280
1310
  const result = setFontInConfig(randomFont);
1281
1311
  if (!result.ok) {
1282
1312
  process.stderr.write(`Failed to set random font: ${randomFont}\n`);