@icarusmx/creta 0.8.0 → 0.8.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.
Files changed (2) hide show
  1. package/bin/creta.js +215 -3
  2. package/package.json +1 -1
package/bin/creta.js CHANGED
@@ -580,6 +580,110 @@ function showHelp() {
580
580
  }
581
581
 
582
582
  async function startMainMenu() {
583
+ // Always try interactive mode first, fall back only if it fails
584
+ try {
585
+ return await startMainMenuInteractive()
586
+ } catch (error) {
587
+ // If interactive mode fails, fall back to numbered selection
588
+ console.log('\nModo interactivo no disponible, usando selección numérica...\n')
589
+ return await startMainMenuFallback()
590
+ }
591
+ }
592
+
593
+ async function startMainMenuInteractive() {
594
+ // Check if setRawMode is available before trying to use it
595
+ if (typeof process.stdin.setRawMode !== 'function') {
596
+ throw new Error('setRawMode not available')
597
+ }
598
+
599
+ console.log("Te ofrecemos las siguientes opciones")
600
+ console.log("Usa ↑/↓ para navegar, Enter para seleccionar, 'q' para salir\n")
601
+
602
+ const options = [
603
+ { id: 1, title: "🧠 Aprender conceptos", description: "Explora los enunciados fundamentales" },
604
+ { id: 2, title: "🚀 Construir proyectos", description: "Crea tu portafolio personal" }
605
+ ]
606
+
607
+ let selectedIndex = 0
608
+
609
+ // Enable raw mode to capture arrow keys
610
+ try {
611
+ process.stdin.setRawMode(true)
612
+ process.stdin.resume()
613
+ process.stdin.setEncoding('utf8')
614
+ } catch (error) {
615
+ throw new Error('Failed to enable raw mode: ' + error.message)
616
+ }
617
+
618
+ const renderOptions = () => {
619
+ // Clear previous output and move cursor to top
620
+ process.stdout.write('\x1b[2J')
621
+ process.stdout.write('\x1b[H')
622
+
623
+ console.log("🏛️ Bienvenido a Creta")
624
+ console.log("La escuela de software de icarus.mx\n")
625
+ console.log("Te ofrecemos las siguientes opciones")
626
+ console.log("Usa ↑/↓ para navegar, Enter para seleccionar, 'q' para salir\n")
627
+
628
+ options.forEach((option, index) => {
629
+ const isSelected = index === selectedIndex
630
+ const prefix = isSelected ? '▶ ' : ' '
631
+ const highlight = isSelected ? '\x1b[36m' : '\x1b[37m' // cyan for selected, white for normal
632
+ const reset = '\x1b[0m'
633
+
634
+ console.log(`${highlight}${prefix}${option.title}${reset}`)
635
+ if (isSelected) {
636
+ console.log(`${highlight} ${option.description}${reset}`)
637
+ }
638
+ console.log("")
639
+ })
640
+ }
641
+
642
+ return new Promise((resolve) => {
643
+ renderOptions()
644
+
645
+ const onKeyPress = (key) => {
646
+ if (key === 'q' || key === '\x03') { // q or Ctrl+C
647
+ process.stdin.setRawMode(false)
648
+ process.stdin.removeListener('data', onKeyPress)
649
+ console.log("\n¡Hasta la vista! 👋")
650
+ resolve()
651
+ return
652
+ }
653
+
654
+ if (key === '\r' || key === '\n') { // Enter
655
+ process.stdin.setRawMode(false)
656
+ process.stdin.removeListener('data', onKeyPress)
657
+
658
+ const selectedOption = options[selectedIndex]
659
+
660
+ // Clear screen
661
+ process.stdout.write('\x1b[2J')
662
+ process.stdout.write('\x1b[H')
663
+
664
+ if (selectedOption.id === 1) {
665
+ startEnunciadosSelector().then(resolve)
666
+ } else if (selectedOption.id === 2) {
667
+ startProyectosSelector().then(resolve)
668
+ }
669
+ return
670
+ }
671
+
672
+ // Handle arrow keys (escape sequences)
673
+ if (key === '\u001b[A') { // Up arrow
674
+ selectedIndex = selectedIndex > 0 ? selectedIndex - 1 : options.length - 1
675
+ renderOptions()
676
+ } else if (key === '\u001b[B') { // Down arrow
677
+ selectedIndex = selectedIndex < options.length - 1 ? selectedIndex + 1 : 0
678
+ renderOptions()
679
+ }
680
+ }
681
+
682
+ process.stdin.on('data', onKeyPress)
683
+ })
684
+ }
685
+
686
+ async function startMainMenuFallback() {
583
687
  const rl = createInterface({
584
688
  input: process.stdin,
585
689
  output: process.stdout
@@ -592,10 +696,10 @@ async function startMainMenu() {
592
696
  }
593
697
 
594
698
  try {
595
- console.log("¿Qué quieres hacer hoy?")
699
+ console.log("Te ofrecemos las siguientes opciones")
596
700
  console.log("")
597
- console.log("1. 🧠 Conceptos - Explora los enunciados fundamentales")
598
- console.log("2. 🚀 Proyectos - Crea tu portafolio personal")
701
+ console.log("1. 🧠 Aprender conceptos - Explora los enunciados fundamentales")
702
+ console.log("2. 🚀 Construir proyectos - Crea tu portafolio personal")
599
703
  console.log("")
600
704
 
601
705
  const respuesta = await askQuestion("Elige una opción (1-2) o 'q' para salir: ")
@@ -815,6 +919,114 @@ async function startEnunciadosSelectorFallback() {
815
919
 
816
920
 
817
921
  async function startProyectosSelector() {
922
+ // Always try interactive mode first, fall back only if it fails
923
+ try {
924
+ return await startProyectosSelectorInteractive()
925
+ } catch (error) {
926
+ // If interactive mode fails, fall back to numbered selection
927
+ console.log('\nModo interactivo no disponible, usando selección numérica...\n')
928
+ return await startProyectosSelectorFallback()
929
+ }
930
+ }
931
+
932
+ async function startProyectosSelectorInteractive() {
933
+ // Check if setRawMode is available before trying to use it
934
+ if (typeof process.stdin.setRawMode !== 'function') {
935
+ throw new Error('setRawMode not available')
936
+ }
937
+
938
+ console.log("\n🚀 Proyectos Disponibles")
939
+ console.log("¿Qué proyecto quieres crear?")
940
+ console.log("Usa ↑/↓ para navegar, Enter para seleccionar, 'q' para salir\n")
941
+
942
+ const projects = [
943
+ { id: 1, title: "🎨 Portafolio Personal", description: "Reto completo", level: 0 },
944
+ { id: 2, title: "🔓 Portafolio Nivel 1", description: "Solo navbar", level: 1 },
945
+ { id: 3, title: "🔓 Portafolio Nivel 2", description: "Navbar + hero", level: 2 },
946
+ { id: 4, title: "🔓 Portafolio Nivel 3", description: "Solución completa", level: 3 }
947
+ ]
948
+
949
+ let selectedIndex = 0
950
+
951
+ // Enable raw mode to capture arrow keys
952
+ try {
953
+ process.stdin.setRawMode(true)
954
+ process.stdin.resume()
955
+ process.stdin.setEncoding('utf8')
956
+ } catch (error) {
957
+ throw new Error('Failed to enable raw mode: ' + error.message)
958
+ }
959
+
960
+ const renderOptions = () => {
961
+ // Clear previous output and move cursor to top
962
+ process.stdout.write('\x1b[2J')
963
+ process.stdout.write('\x1b[H')
964
+
965
+ console.log("🚀 Proyectos Disponibles")
966
+ console.log("¿Qué proyecto quieres crear?")
967
+ console.log("Usa ↑/↓ para navegar, Enter para seleccionar, 'q' para salir\n")
968
+
969
+ projects.forEach((project, index) => {
970
+ const isSelected = index === selectedIndex
971
+ const prefix = isSelected ? '▶ ' : ' '
972
+ const highlight = isSelected ? '\x1b[36m' : '\x1b[37m' // cyan for selected, white for normal
973
+ const reset = '\x1b[0m'
974
+
975
+ console.log(`${highlight}${prefix}${project.title}${reset}`)
976
+ if (isSelected) {
977
+ console.log(`${highlight} ${project.description}${reset}`)
978
+ }
979
+ console.log("")
980
+ })
981
+ }
982
+
983
+ return new Promise((resolve) => {
984
+ renderOptions()
985
+
986
+ const onKeyPress = (key) => {
987
+ if (key === 'q' || key === '\x03') { // q or Ctrl+C
988
+ process.stdin.setRawMode(false)
989
+ process.stdin.removeListener('data', onKeyPress)
990
+ console.log("\n¡Hasta la vista! 👋")
991
+ resolve()
992
+ return
993
+ }
994
+
995
+ if (key === '\r' || key === '\n') { // Enter
996
+ process.stdin.setRawMode(false)
997
+ process.stdin.removeListener('data', onKeyPress)
998
+
999
+ const selectedProject = projects[selectedIndex]
1000
+ const level = selectedProject.level
1001
+
1002
+ // Clear screen
1003
+ process.stdout.write('\x1b[2J')
1004
+ process.stdout.write('\x1b[H')
1005
+
1006
+ // Check if we're in an existing Creta project
1007
+ if (level > 0 && isInCretaProject()) {
1008
+ unstuckProject(level).then(resolve)
1009
+ } else {
1010
+ createPortfolioProject(level).then(resolve)
1011
+ }
1012
+ return
1013
+ }
1014
+
1015
+ // Handle arrow keys (escape sequences)
1016
+ if (key === '\u001b[A') { // Up arrow
1017
+ selectedIndex = selectedIndex > 0 ? selectedIndex - 1 : projects.length - 1
1018
+ renderOptions()
1019
+ } else if (key === '\u001b[B') { // Down arrow
1020
+ selectedIndex = selectedIndex < projects.length - 1 ? selectedIndex + 1 : 0
1021
+ renderOptions()
1022
+ }
1023
+ }
1024
+
1025
+ process.stdin.on('data', onKeyPress)
1026
+ })
1027
+ }
1028
+
1029
+ async function startProyectosSelectorFallback() {
818
1030
  const rl = createInterface({
819
1031
  input: process.stdin,
820
1032
  output: process.stdout
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icarusmx/creta",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "Salgamos de este laberinto.",
5
5
  "type": "module",
6
6
  "bin": {