@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 +1 -1
- package/package.json +1 -1
- package/src/index.js +36 -6
package/README.md
CHANGED
package/package.json
CHANGED
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
|
|
997
|
-
|
|
998
|
-
|
|
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
|
|
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`);
|