@nevermorelove/ompp 0.4.0 → 0.4.1
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/ompp.js +53 -59
- package/package.json +1 -1
package/ompp.js
CHANGED
|
@@ -384,76 +384,19 @@ async function pickMode(modes) {
|
|
|
384
384
|
const { select, text, confirm, isCancel, cancel } = require("@clack/prompts");
|
|
385
385
|
for (;;) {
|
|
386
386
|
const options = [
|
|
387
|
-
...modes.map((m) => ({
|
|
388
|
-
value: m,
|
|
389
|
-
label: m.name,
|
|
390
|
-
hint: "r: rename, d: delete",
|
|
391
|
-
})),
|
|
387
|
+
...modes.map((m) => ({ value: m, label: m.name })),
|
|
392
388
|
{ value: CREATE_OPTION, label: "Create a new mode +" },
|
|
393
389
|
];
|
|
394
|
-
let action = null; // "rename" | "delete" | null
|
|
395
|
-
// Registered before the prompt so it sees the keypress first and can
|
|
396
|
-
// rewrite r/d into "return" for the prompt's own keypress listener.
|
|
397
|
-
const onKeypress = (ch, key) => {
|
|
398
|
-
if (!key || !key.name) return;
|
|
399
|
-
if (key.name === "r" && !key.ctrl && !key.meta) {
|
|
400
|
-
action = "rename";
|
|
401
|
-
key.name = "return";
|
|
402
|
-
} else if (key.name === "d" && !key.ctrl && !key.meta) {
|
|
403
|
-
action = "delete";
|
|
404
|
-
key.name = "return";
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
process.stdin.on("keypress", onKeypress);
|
|
408
390
|
const chosen = await select({
|
|
409
391
|
message: "Pick a mode",
|
|
410
392
|
options,
|
|
411
393
|
});
|
|
412
|
-
process.stdin.removeListener("keypress", onKeypress);
|
|
413
394
|
|
|
414
395
|
if (isCancel(chosen)) {
|
|
415
396
|
cancel("Cancelled");
|
|
416
397
|
process.exit(130);
|
|
417
398
|
}
|
|
418
399
|
|
|
419
|
-
// r/d on the highlighted row: run the action, then reopen the picker.
|
|
420
|
-
if (action && chosen !== CREATE_OPTION) {
|
|
421
|
-
if (action === "rename") {
|
|
422
|
-
const newName = await text({
|
|
423
|
-
message: `Rename "${chosen.name}" to`,
|
|
424
|
-
validate: (v) => {
|
|
425
|
-
if (!v || !isValidModeName(v)) {
|
|
426
|
-
return "Lowercase letters, digits, and dashes only";
|
|
427
|
-
}
|
|
428
|
-
if (RESERVED_NAMES.includes(v)) return `"${v}" is reserved`;
|
|
429
|
-
if (modes.some((m) => m.name === v)) return `"${v}" already exists`;
|
|
430
|
-
return undefined;
|
|
431
|
-
},
|
|
432
|
-
});
|
|
433
|
-
if (!isCancel(newName) && renameMode(chosen, newName)) {
|
|
434
|
-
chosen.name = newName;
|
|
435
|
-
} else {
|
|
436
|
-
cancel("Rename cancelled");
|
|
437
|
-
}
|
|
438
|
-
} else {
|
|
439
|
-
const sure = await confirm({
|
|
440
|
-
message: `Delete "${chosen.name}"? This removes its folder.`,
|
|
441
|
-
active: "Delete",
|
|
442
|
-
inactive: "Keep",
|
|
443
|
-
});
|
|
444
|
-
if (!isCancel(sure) && sure) {
|
|
445
|
-
deleteMode(chosen);
|
|
446
|
-
// Splice in place: main() keeps a reference to this array.
|
|
447
|
-
modes.splice(
|
|
448
|
-
modes.findIndex((m) => m.name === chosen.name),
|
|
449
|
-
1,
|
|
450
|
-
);
|
|
451
|
-
} else {
|
|
452
|
-
cancel("Delete cancelled");
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
continue; // reopen the picker with the updated list
|
|
456
|
-
}
|
|
457
400
|
if (chosen === CREATE_OPTION) {
|
|
458
401
|
const name = await text({
|
|
459
402
|
message: "New mode name",
|
|
@@ -471,7 +414,58 @@ async function pickMode(modes) {
|
|
|
471
414
|
}
|
|
472
415
|
return { create: name };
|
|
473
416
|
}
|
|
474
|
-
|
|
417
|
+
|
|
418
|
+
// Second step: what to do with the picked mode. This replaces the
|
|
419
|
+
// previous r/d hotkey hack (process.stdin keypress rewrite) which left
|
|
420
|
+
// Windows terminals in raw mode and hung randomly.
|
|
421
|
+
const action = await select({
|
|
422
|
+
message: `Mode "${chosen.name}" — what next?`,
|
|
423
|
+
options: [
|
|
424
|
+
{ value: "launch", label: "Launch" },
|
|
425
|
+
{ value: "rename", label: "Rename" },
|
|
426
|
+
{ value: "delete", label: "Delete" },
|
|
427
|
+
{ value: "back", label: "Back" },
|
|
428
|
+
],
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
if (isCancel(action) || action === "back") continue;
|
|
432
|
+
if (action === "launch") return chosen;
|
|
433
|
+
|
|
434
|
+
if (action === "rename") {
|
|
435
|
+
const newName = await text({
|
|
436
|
+
message: `Rename "${chosen.name}" to`,
|
|
437
|
+
validate: (v) => {
|
|
438
|
+
if (!v || !isValidModeName(v)) {
|
|
439
|
+
return "Lowercase letters, digits, and dashes only";
|
|
440
|
+
}
|
|
441
|
+
if (RESERVED_NAMES.includes(v)) return `"${v}" is reserved`;
|
|
442
|
+
if (modes.some((m) => m.name === v)) return `"${v}" already exists`;
|
|
443
|
+
return undefined;
|
|
444
|
+
},
|
|
445
|
+
});
|
|
446
|
+
if (!isCancel(newName) && newName !== chosen.name) {
|
|
447
|
+
if (renameMode(chosen, newName)) chosen.name = newName;
|
|
448
|
+
} else {
|
|
449
|
+
cancel("Rename cancelled");
|
|
450
|
+
}
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (action === "delete") {
|
|
455
|
+
const sure = await confirm({
|
|
456
|
+
message: `Delete "${chosen.name}"? This removes its folder.`,
|
|
457
|
+
active: "Delete",
|
|
458
|
+
inactive: "Keep",
|
|
459
|
+
});
|
|
460
|
+
if (!isCancel(sure) && sure) {
|
|
461
|
+
deleteMode(chosen);
|
|
462
|
+
const idx = modes.findIndex((m) => m.name === chosen.name);
|
|
463
|
+
if (idx !== -1) modes.splice(idx, 1);
|
|
464
|
+
} else {
|
|
465
|
+
cancel("Delete cancelled");
|
|
466
|
+
}
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
475
469
|
}
|
|
476
470
|
}
|
|
477
471
|
|