@icarusmx/creta 0.6.0 → 0.7.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 +131 -0
  2. package/package.json +1 -1
package/bin/creta.js CHANGED
@@ -579,6 +579,137 @@ function showHelp() {
579
579
  }
580
580
 
581
581
  async function startEnunciadosSelector() {
582
+ // Debug TTY detection
583
+ const hasSetRawMode = typeof process.stdin.setRawMode === 'function'
584
+ const isOutputTTY = process.stdout.isTTY
585
+ const isInputTTY = process.stdin.isTTY
586
+
587
+ // DEBUG: Show detection values for troubleshooting
588
+ // console.log(`DEBUG: hasSetRawMode=${hasSetRawMode}, isOutputTTY=${isOutputTTY}, isInputTTY=${isInputTTY}`)
589
+
590
+ // Try interactive mode unless explicitly disabled
591
+ if (hasSetRawMode && !process.env.CRETA_NO_INTERACTIVE) {
592
+ try {
593
+ return await startEnunciadosSelectorInteractive()
594
+ } catch (error) {
595
+ // If interactive mode fails, fall back to numbered selection
596
+ console.log('\nCambiando a modo de selección numérica...\n')
597
+ }
598
+ }
599
+
600
+ // Fallback to numbered selection
601
+ return await startEnunciadosSelectorFallback()
602
+ }
603
+
604
+ async function startEnunciadosSelectorInteractive() {
605
+ console.log("\n🧠 Los 6 Enunciados Fundamentales de Programación Orientada a Objetos")
606
+ console.log("=" .repeat(70))
607
+ console.log("¿Cuál de estos enunciados te genera más 'ruido' (curiosidad/confusión)?")
608
+ console.log("Usa ↑/↓ para navegar, Enter para seleccionar, 'q' para salir\n")
609
+
610
+ let selectedIndex = 0
611
+ let running = true
612
+
613
+ // Enable raw mode to capture arrow keys
614
+ process.stdin.setRawMode(true)
615
+ process.stdin.resume()
616
+ process.stdin.setEncoding('utf8')
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("🧠 Los 6 Enunciados Fundamentales de Programación Orientada a Objetos")
624
+ console.log("=" .repeat(70))
625
+ console.log("¿Cuál de estos enunciados te genera más 'ruido' (curiosidad/confusión)?")
626
+ console.log("Usa ↑/↓ para navegar, Enter para seleccionar, 'q' para salir\n")
627
+
628
+ ENUNCIADOS.forEach((enunciado, 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}${index + 1}. [${enunciado.nivel}] ${enunciado.enfoque}${reset}`)
635
+
636
+ if (isSelected) {
637
+ // Show full text for selected option with word wrapping
638
+ const maxWidth = 66
639
+ const words = enunciado.texto.split(' ')
640
+ let currentLine = ' "'
641
+
642
+ words.forEach(word => {
643
+ if (currentLine.length + word.length + 1 <= maxWidth) {
644
+ currentLine += (currentLine === ' "' ? '' : ' ') + word
645
+ } else {
646
+ console.log(`${highlight}${currentLine}${reset}`)
647
+ currentLine = ' ' + word
648
+ }
649
+ })
650
+
651
+ if (currentLine.length > 6) {
652
+ console.log(`${highlight}${currentLine}"${reset}`)
653
+ }
654
+ }
655
+ console.log("")
656
+ })
657
+ }
658
+
659
+ return new Promise((resolve) => {
660
+ renderOptions()
661
+
662
+ const onKeyPress = (key) => {
663
+ if (key === 'q' || key === '\x03') { // q or Ctrl+C
664
+ process.stdin.setRawMode(false)
665
+ process.stdin.removeListener('data', onKeyPress)
666
+ console.log("\n¡Hasta la vista! 👋")
667
+ resolve()
668
+ return
669
+ }
670
+
671
+ if (key === '\r' || key === '\n') { // Enter
672
+ process.stdin.setRawMode(false)
673
+ process.stdin.removeListener('data', onKeyPress)
674
+
675
+ const enunciadoSeleccionado = ENUNCIADOS[selectedIndex]
676
+
677
+ // Clear screen and show selection
678
+ process.stdout.write('\x1b[2J')
679
+ process.stdout.write('\x1b[H')
680
+
681
+ console.log(`🎯 Has seleccionado el enunciado ${selectedIndex + 1}:`)
682
+ console.log(`"${enunciadoSeleccionado.texto}"`)
683
+ console.log(`\n💡 Enfoque: ${enunciadoSeleccionado.enfoque}`)
684
+ console.log(`📚 Nivel: ${enunciadoSeleccionado.nivel}`)
685
+
686
+ console.log("\n🚀 Próximamente:")
687
+ console.log("- Sesiones de estudio dirigidas basadas en este enunciado")
688
+ console.log("- Ejercicios prácticos que ilustren el concepto")
689
+ console.log("- Proyectos específicos para internalizar la idea")
690
+
691
+ console.log("\n💭 Por ahora, reflexiona: ¿qué parte específica de este enunciado")
692
+ console.log(" te genera más curiosidad o confusión?")
693
+
694
+ resolve()
695
+ return
696
+ }
697
+
698
+ // Handle arrow keys (escape sequences)
699
+ if (key === '\u001b[A') { // Up arrow
700
+ selectedIndex = selectedIndex > 0 ? selectedIndex - 1 : ENUNCIADOS.length - 1
701
+ renderOptions()
702
+ } else if (key === '\u001b[B') { // Down arrow
703
+ selectedIndex = selectedIndex < ENUNCIADOS.length - 1 ? selectedIndex + 1 : 0
704
+ renderOptions()
705
+ }
706
+ }
707
+
708
+ process.stdin.on('data', onKeyPress)
709
+ })
710
+ }
711
+
712
+ async function startEnunciadosSelectorFallback() {
582
713
  const rl = createInterface({
583
714
  input: process.stdin,
584
715
  output: process.stdout
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icarusmx/creta",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Salgamos de este laberinto.",
5
5
  "type": "module",
6
6
  "bin": {