getSelectedCategory(); parent::setSelectedCategory($index); $newIndex = $this->getSelectedCategory(); echo "\n[DEBUG] Category index: $oldIndex โ†’ $newIndex\n"; flush(); } public function navigateUp(): void { echo "\n[DEBUG] โฌ†๏ธ navigateUp() called\n"; flush(); $before = $this->getSelectedCategory(); parent::navigateUp(); $after = $this->getSelectedCategory(); echo "[DEBUG] โฌ†๏ธ Result: $before โ†’ $after\n"; flush(); } public function navigateDown(): void { echo "\n[DEBUG] โฌ‡๏ธ navigateDown() called\n"; flush(); $before = $this->getSelectedCategory(); parent::navigateDown(); $after = $this->getSelectedCategory(); echo "[DEBUG] โฌ‡๏ธ Result: $before โ†’ $after\n"; flush(); } }; // Custom input handler with debug $debugInputHandler = new class($debugExecutor) extends TuiInputHandler { public function handleInput(string $key, \App\Framework\Console\Components\TuiState $state, \App\Framework\Console\CommandHistory $history): void { $keyHex = bin2hex($key); $keyDesc = match($key) { "\033[A" => "ARROW_UP", "\033[B" => "ARROW_DOWN", "\033[C" => "ARROW_RIGHT", "\033[D" => "ARROW_LEFT", "\n" => "ENTER", " " => "SPACE", "\033" => "ESC", 'q', 'Q' => "QUIT", default => "OTHER('$key')" }; echo "\n[INPUT] ๐ŸŽฏ Key: $keyDesc (hex: $keyHex)\n"; echo "[INPUT] ๐Ÿ“ Current view: " . $state->getCurrentView()->name . "\n"; echo "[INPUT] ๐Ÿ“ Current category: " . $state->getSelectedCategory() . "\n"; flush(); parent::handleInput($key, $state, $history); echo "[INPUT] โœ… After processing - Category: " . $state->getSelectedCategory() . "\n"; flush(); } }; $state = $debugState; $history = new CommandHistory(); $inputHandler = $debugInputHandler; // Add test categories $testCategories = [ ['name' => 'Testing', 'description' => 'Test commands', 'icon' => '๐Ÿงช', 'commands' => []], ['name' => 'Demo', 'description' => 'Demo commands', 'icon' => '๐ŸŽฎ', 'commands' => []], ['name' => 'Generator', 'description' => 'Code generation', 'icon' => 'โš™๏ธ', 'commands' => []], ['name' => 'General', 'description' => 'General commands', 'icon' => '๐Ÿ“‚', 'commands' => []] ]; $state->setCategories($testCategories); $state->setCurrentView(TuiView::CATEGORIES); $state->setRunning(true); echo "โœ“ Debug TUI ready\n"; echo "Categories: " . count($testCategories) . "\n"; echo "Selected: " . $state->getSelectedCategory() . "\n\n"; // Save terminal settings $originalSettings = trim(shell_exec('stty -g') ?: ''); echo "Setting up terminal for PHPStorm...\n"; // Set up terminal if ($isPhpStorm) { shell_exec('stty raw -echo min 1 time 0 2>/dev/null'); } else { shell_exec('stty -icanon -echo 2>/dev/null'); } echo "โœ“ Terminal configured\n\n"; echo "๐Ÿš€ SIMPLE DEBUG TUI\n"; echo "==================\n\n"; function renderSimpleMenu($categories, $selectedIndex) { echo "Categories:\n"; foreach ($categories as $index => $category) { $indicator = $index === $selectedIndex ? 'โ–ถ๏ธ' : ' '; echo "$indicator {$category['icon']} {$category['name']}\n"; } echo "\n"; } function readKeyPHPStorm() { $key = fgetc(STDIN); if ($key === false) return ''; if ($key === "\033") { $sequence = $key; stream_set_blocking(STDIN, false); $next = fgetc(STDIN); if ($next === false) { usleep(10000); $next = fgetc(STDIN); } if ($next !== false) { $sequence .= $next; if ($next === '[') { $third = fgetc(STDIN); if ($third === false) { usleep(10000); $third = fgetc(STDIN); } if ($third !== false) { $sequence .= $third; } } } stream_set_blocking(STDIN, true); return $sequence; } return $key; } // Simple debug loop echo "Use โ†‘/โ†“ arrow keys to navigate. Press 'q' to quit.\n\n"; while ($state->isRunning()) { // Render current state renderSimpleMenu($testCategories, $state->getSelectedCategory()); echo "Debug Info:\n"; echo "- Selected Index: " . $state->getSelectedCategory() . "\n"; echo "- Current View: " . $state->getCurrentView()->name . "\n"; $category = $state->getCurrentCategory(); echo "- Category Name: " . ($category ? $category['name'] : 'NULL') . "\n"; echo "\nPress arrow keys...\n"; echo str_repeat('=', 40) . "\n"; // Read input $key = readKeyPHPStorm(); if ($key === 'q' || $key === 'Q') { echo "\n[QUIT] Stopping TUI...\n"; $state->setRunning(false); break; } if ($key !== '') { // Clear screen for next render echo ScreenControlCode::CLEAR_ALL->format(); echo CursorControlCode::POSITION->format(1, 1); // Process input with full debug output $inputHandler->handleInput($key, $state, $history); echo "\n" . str_repeat('-', 40) . "\n"; } } } finally { // Restore terminal if (!empty($originalSettings)) { shell_exec("stty $originalSettings 2>/dev/null"); } echo "\nโœ… Simple Debug TUI ended\n"; }