open-notepad 1.0.4 → 1.0.5
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/bin/note.js +98 -22
- package/package.json +1 -1
package/bin/note.js
CHANGED
|
@@ -598,56 +598,132 @@ ${colors.bold}${colors.blue}Current Notepad Config:${colors.reset}
|
|
|
598
598
|
`);
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
+
function selectMenuOption(options, titleCallback) {
|
|
602
|
+
const hasTTY = process.stdin.isTTY && typeof process.stdin.setRawMode === 'function';
|
|
603
|
+
|
|
604
|
+
if (!hasTTY) {
|
|
605
|
+
// Non-interactive fallback
|
|
606
|
+
return new Promise((resolve) => {
|
|
607
|
+
clearScreen();
|
|
608
|
+
titleCallback();
|
|
609
|
+
options.forEach((opt, idx) => {
|
|
610
|
+
log(`${idx + 1}. ${opt}`);
|
|
611
|
+
});
|
|
612
|
+
log('');
|
|
613
|
+
ask(`Select option (1-${options.length})`).then((choice) => {
|
|
614
|
+
const val = parseInt(choice, 10) - 1;
|
|
615
|
+
if (val >= 0 && val < options.length) {
|
|
616
|
+
resolve(val);
|
|
617
|
+
} else {
|
|
618
|
+
resolve(options.length - 1); // default to exit
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
return new Promise((resolve) => {
|
|
625
|
+
let activeIndex = 0;
|
|
626
|
+
|
|
627
|
+
const render = () => {
|
|
628
|
+
clearScreen();
|
|
629
|
+
titleCallback();
|
|
630
|
+
options.forEach((opt, idx) => {
|
|
631
|
+
if (idx === activeIndex) {
|
|
632
|
+
log(`${colors.bold}${colors.blue} > ${opt}${colors.reset}`);
|
|
633
|
+
} else {
|
|
634
|
+
log(` ${colors.dim}${opt}${colors.reset}`);
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
log(`\n${colors.dim}Use Up/Down arrows to navigate, Enter to select.${colors.reset}`);
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
readline.emitKeypressEvents(process.stdin);
|
|
641
|
+
try {
|
|
642
|
+
process.stdin.setRawMode(true);
|
|
643
|
+
} catch (e) {
|
|
644
|
+
process.stdin.setRawMode(false);
|
|
645
|
+
}
|
|
646
|
+
process.stdin.resume();
|
|
647
|
+
|
|
648
|
+
const onKeypress = (str, key) => {
|
|
649
|
+
if (key && key.ctrl && key.name === 'c') {
|
|
650
|
+
try {
|
|
651
|
+
process.stdin.setRawMode(false);
|
|
652
|
+
} catch (e) {}
|
|
653
|
+
process.stdin.off('keypress', onKeypress);
|
|
654
|
+
process.exit(0);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
if (key && key.name === 'up') {
|
|
658
|
+
activeIndex = (activeIndex - 1 + options.length) % options.length;
|
|
659
|
+
render();
|
|
660
|
+
} else if (key && key.name === 'down') {
|
|
661
|
+
activeIndex = (activeIndex + 1) % options.length;
|
|
662
|
+
render();
|
|
663
|
+
} else if (key && (key.name === 'return' || key.name === 'enter')) {
|
|
664
|
+
try {
|
|
665
|
+
process.stdin.setRawMode(false);
|
|
666
|
+
} catch (e) {}
|
|
667
|
+
process.stdin.off('keypress', onKeypress);
|
|
668
|
+
resolve(activeIndex);
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
process.stdin.on('keypress', onKeypress);
|
|
673
|
+
render();
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
|
|
601
677
|
// Interactive Dashboard Menu (If no arguments)
|
|
602
678
|
async function startMainMenu() {
|
|
679
|
+
const options = [
|
|
680
|
+
'📁 List all notes',
|
|
681
|
+
'📖 View a note',
|
|
682
|
+
'✍️ Create a new note',
|
|
683
|
+
'✏️ Edit an existing note',
|
|
684
|
+
'❌ Delete a note',
|
|
685
|
+
'🔑 Configure / Login',
|
|
686
|
+
'🚪 Exit'
|
|
687
|
+
];
|
|
688
|
+
|
|
603
689
|
while (true) {
|
|
604
|
-
clearScreen();
|
|
605
|
-
log(`${colors.bgBlue}${colors.white}${colors.bold} Notepad CLI Menu ${colors.reset}`);
|
|
606
690
|
const config = await loadConfig();
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
log(`${colors.cyan}3. ✍️ Create a new note${colors.reset}`);
|
|
612
|
-
log(`${colors.cyan}4. ✏️ Edit an existing note${colors.reset}`);
|
|
613
|
-
log(`${colors.cyan}5. ❌ Delete a note${colors.reset}`);
|
|
614
|
-
log(`${colors.cyan}6. 🔑 Configure / Login${colors.reset}`);
|
|
615
|
-
log(`${colors.cyan}7. 🚪 Exit${colors.reset}\n`);
|
|
691
|
+
const titleCallback = () => {
|
|
692
|
+
log(`${colors.bgBlue}${colors.white}${colors.bold} Notepad CLI Menu ${colors.reset}`);
|
|
693
|
+
log(`${colors.dim}Namespace: ${colors.reset}${config.roomId ? colors.green + config.roomId : colors.red + '(Not logged in)'}${colors.reset}\n`);
|
|
694
|
+
};
|
|
616
695
|
|
|
617
|
-
const choice = await
|
|
696
|
+
const choice = await selectMenuOption(options, titleCallback);
|
|
618
697
|
|
|
619
698
|
switch (choice) {
|
|
620
|
-
case
|
|
699
|
+
case 0:
|
|
621
700
|
await handleList();
|
|
622
701
|
await ask('Press Enter to return to menu');
|
|
623
702
|
break;
|
|
624
|
-
case
|
|
703
|
+
case 1:
|
|
625
704
|
await handleView();
|
|
626
705
|
await ask('Press Enter to return to menu');
|
|
627
706
|
break;
|
|
628
|
-
case
|
|
707
|
+
case 2:
|
|
629
708
|
await handleCreate();
|
|
630
709
|
await ask('Press Enter to return to menu');
|
|
631
710
|
break;
|
|
632
|
-
case
|
|
711
|
+
case 3:
|
|
633
712
|
await handleEdit();
|
|
634
713
|
await ask('Press Enter to return to menu');
|
|
635
714
|
break;
|
|
636
|
-
case
|
|
715
|
+
case 4:
|
|
637
716
|
await handleDelete();
|
|
638
717
|
await ask('Press Enter to return to menu');
|
|
639
718
|
break;
|
|
640
|
-
case
|
|
719
|
+
case 5:
|
|
641
720
|
await handleLogin();
|
|
642
721
|
await ask('Press Enter to return to menu');
|
|
643
722
|
break;
|
|
644
|
-
case
|
|
723
|
+
case 6:
|
|
645
724
|
clearScreen();
|
|
646
725
|
log('Goodbye!');
|
|
647
726
|
process.exit(0);
|
|
648
|
-
default:
|
|
649
|
-
warning('Invalid option. Please choose 1-7.');
|
|
650
|
-
await new Promise(r => setTimeout(r, 1200));
|
|
651
727
|
}
|
|
652
728
|
}
|
|
653
729
|
}
|