open-notepad 1.0.3 → 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.
Files changed (2) hide show
  1. package/bin/note.js +104 -23
  2. package/package.json +1 -1
package/bin/note.js CHANGED
@@ -490,7 +490,12 @@ async function handleEdit(codeArg) {
490
490
  await fs.writeFile(tempFilePath, initialContent, 'utf-8');
491
491
 
492
492
  // Open editor
493
- const editor = process.env.EDITOR || (process.platform === 'win32' ? 'notepad' : 'nano');
493
+ let editor = process.env.EDITOR;
494
+ if (process.platform === 'linux') {
495
+ editor = 'nano';
496
+ } else if (!editor) {
497
+ editor = process.platform === 'win32' ? 'notepad' : 'nano';
498
+ }
494
499
  info(`Opening editor: ${colors.bold}${editor}${colors.reset} with note content...`);
495
500
 
496
501
  const child = spawn(editor, [tempFilePath], { stdio: 'inherit', shell: true });
@@ -593,56 +598,132 @@ ${colors.bold}${colors.blue}Current Notepad Config:${colors.reset}
593
598
  `);
594
599
  }
595
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
+
596
677
  // Interactive Dashboard Menu (If no arguments)
597
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
+
598
689
  while (true) {
599
- clearScreen();
600
- log(`${colors.bgBlue}${colors.white}${colors.bold} Notepad CLI Menu ${colors.reset}`);
601
690
  const config = await loadConfig();
602
- log(`${colors.dim}Namespace: ${colors.reset}${config.roomId ? colors.green + config.roomId : colors.red + '(Not logged in)'}${colors.reset}\n`);
603
-
604
- log(`${colors.cyan}1. 📁 List all notes${colors.reset}`);
605
- log(`${colors.cyan}2. 📖 View a note${colors.reset}`);
606
- log(`${colors.cyan}3. ✍️ Create a new note${colors.reset}`);
607
- log(`${colors.cyan}4. ✏️ Edit an existing note${colors.reset}`);
608
- log(`${colors.cyan}5. ❌ Delete a note${colors.reset}`);
609
- log(`${colors.cyan}6. 🔑 Configure / Login${colors.reset}`);
610
- 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
+ };
611
695
 
612
- const choice = await ask('Select option (1-7)');
696
+ const choice = await selectMenuOption(options, titleCallback);
613
697
 
614
698
  switch (choice) {
615
- case '1':
699
+ case 0:
616
700
  await handleList();
617
701
  await ask('Press Enter to return to menu');
618
702
  break;
619
- case '2':
703
+ case 1:
620
704
  await handleView();
621
705
  await ask('Press Enter to return to menu');
622
706
  break;
623
- case '3':
707
+ case 2:
624
708
  await handleCreate();
625
709
  await ask('Press Enter to return to menu');
626
710
  break;
627
- case '4':
711
+ case 3:
628
712
  await handleEdit();
629
713
  await ask('Press Enter to return to menu');
630
714
  break;
631
- case '5':
715
+ case 4:
632
716
  await handleDelete();
633
717
  await ask('Press Enter to return to menu');
634
718
  break;
635
- case '6':
719
+ case 5:
636
720
  await handleLogin();
637
721
  await ask('Press Enter to return to menu');
638
722
  break;
639
- case '7':
723
+ case 6:
640
724
  clearScreen();
641
725
  log('Goodbye!');
642
726
  process.exit(0);
643
- default:
644
- warning('Invalid option. Please choose 1-7.');
645
- await new Promise(r => setTimeout(r, 1200));
646
727
  }
647
728
  }
648
729
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "open-notepad",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "CLI tool for notepad.web.id to access, edit, create, and list room notes interactively.",
5
5
  "type": "module",
6
6
  "bin": {