'Testing', 'description' => 'Test commands', 'icon' => '๐Ÿงช', 'priority' => 0, 'commands' => [] ], [ 'name' => 'Demo', 'description' => 'Demo commands', 'icon' => '๐ŸŽฎ', 'priority' => 0, 'commands' => [] ], [ 'name' => 'Generator', 'description' => 'Code generation', 'icon' => 'โš™๏ธ', 'priority' => 0, 'commands' => [] ], [ 'name' => 'General', 'description' => 'General commands', 'icon' => '๐Ÿ“‚', 'priority' => 0, 'commands' => [] ] ]; echo "๐Ÿ“Š Test Categories:\n"; foreach ($testCategories as $index => $category) { echo " [$index] {$category['icon']} {$category['name']} - {$category['description']}\n"; } echo "\n"; // Setup TUI state $state->setCategories($testCategories); $state->setCurrentView(TuiView::CATEGORIES); $state->setRunning(true); echo "โœ“ TUI State initialized:\n"; echo " Categories: " . count($testCategories) . "\n"; echo " Current View: " . $state->getCurrentView()->name . "\n"; echo " Selected Category: " . $state->getSelectedCategory() . "\n"; $currentCategory = $state->getCurrentCategory(); if ($currentCategory) { echo " Current Category: '{$currentCategory['name']}'\n"; } else { echo " โŒ ERROR: getCurrentCategory() returned NULL!\n"; echo " This would cause navigation to fail!\n"; } echo "\n=== STEP-BY-STEP NAVIGATION DEBUG ===\n\n"; function debugState($state, $step) { echo "Step $step State:\n"; echo " - Selected Index: " . $state->getSelectedCategory() . "\n"; echo " - Current View: " . $state->getCurrentView()->name . "\n"; $category = $state->getCurrentCategory(); if ($category) { echo " - Current Category: '{$category['name']}'\n"; } else { echo " - โŒ Current Category: NULL\n"; } echo "\n"; } // Initial state debugState($state, "Initial"); // Test 1: Direct TuiState navigation echo "๐Ÿ” Test 1: Direct TuiState navigation\n"; echo "Calling \$state->navigateDown()...\n"; $state->navigateDown(); debugState($state, "After navigateDown()"); echo "Calling \$state->navigateUp()...\n"; $state->navigateUp(); debugState($state, "After navigateUp()"); // Test 2: TuiInputHandler navigation echo "๐Ÿ” Test 2: TuiInputHandler with Arrow Keys\n"; echo "Simulating ARROW_DOWN input...\n"; echo "Key code: '" . TuiKeyCode::ARROW_DOWN->value . "' (hex: " . bin2hex(TuiKeyCode::ARROW_DOWN->value) . ")\n"; $beforeIndex = $state->getSelectedCategory(); $inputHandler->handleInput(TuiKeyCode::ARROW_DOWN->value, $state, $history); $afterIndex = $state->getSelectedCategory(); echo "Before: $beforeIndex, After: $afterIndex\n"; echo "Changed: " . ($beforeIndex !== $afterIndex ? "YES โœ“" : "NO โŒ") . "\n"; debugState($state, "After ARROW_DOWN"); echo "Simulating ARROW_UP input...\n"; echo "Key code: '" . TuiKeyCode::ARROW_UP->value . "' (hex: " . bin2hex(TuiKeyCode::ARROW_UP->value) . ")\n"; $beforeIndex = $state->getSelectedCategory(); $inputHandler->handleInput(TuiKeyCode::ARROW_UP->value, $state, $history); $afterIndex = $state->getSelectedCategory(); echo "Before: $beforeIndex, After: $afterIndex\n"; echo "Changed: " . ($beforeIndex !== $afterIndex ? "YES โœ“" : "NO โŒ") . "\n"; debugState($state, "After ARROW_UP"); // Test 3: Check bounds echo "๐Ÿ” Test 3: Boundary testing\n"; // Go to last category $lastIndex = count($testCategories) - 1; $state->setSelectedCategory($lastIndex); echo "Set to last category ($lastIndex)\n"; debugState($state, "Set to last"); echo "Try to go beyond last (ARROW_DOWN)...\n"; $beforeIndex = $state->getSelectedCategory(); $inputHandler->handleInput(TuiKeyCode::ARROW_DOWN->value, $state, $history); $afterIndex = $state->getSelectedCategory(); echo "Before: $beforeIndex, After: $afterIndex\n"; echo "Boundary protected: " . ($beforeIndex === $afterIndex ? "YES โœ“" : "NO โŒ") . "\n"; // Test 4: Check TuiInputHandler logic echo "\n๐Ÿ” Test 4: Debug TuiInputHandler logic\n"; // Let's trace what happens in handleInput echo "Current view check: " . $state->getCurrentView()->name . "\n"; echo "Is CATEGORIES view: " . ($state->getCurrentView() === TuiView::CATEGORIES ? "YES" : "NO") . "\n"; if ($state->getCurrentView() === TuiView::CATEGORIES) { echo "โœ“ View is correct for category navigation\n"; } else { echo "โŒ View is not CATEGORIES - navigation won't work!\n"; } echo "\nโœ… NAVIGATION DEBUG COMPLETED\n"; } catch (\Throwable $e) { echo "\nโŒ DEBUG FAILED:\n"; echo "Error: " . $e->getMessage() . "\n"; echo "File: " . $e->getFile() . ":" . $e->getLine() . "\n"; echo "\nStack trace:\n" . $e->getTraceAsString() . "\n"; }