[ 'name' => 'Testing', 'description' => '', 'icon' => '๐Ÿงช', 'priority' => 0, 'commands' => [] ], 'Demo' => [ 'name' => 'Demo', 'description' => '', 'icon' => '๐ŸŽฎ', 'priority' => 0, 'commands' => [] ], 'Generator' => [ 'name' => 'Generator', 'description' => '', 'icon' => 'โš™๏ธ', 'priority' => 0, 'commands' => [] ], 'General' => [ 'name' => 'General', 'description' => '', 'icon' => '๐Ÿ“‚', 'priority' => 0, 'commands' => [] ] ]; // Sort by priority (all have priority 0 in this case, so order by keys) uasort($organizedCategories, fn($a, $b) => $b['priority'] <=> $a['priority']); echo "๐Ÿ“Š Before array_values() conversion (associative array):\n"; foreach ($organizedCategories as $key => $category) { echo " Key: '$key' => Category: '{$category['name']}'\n"; } echo "\n"; // Convert to numeric array like our fix $numericCategories = array_values($organizedCategories); echo "๐Ÿ“Š After array_values() conversion (numeric array):\n"; foreach ($numericCategories as $index => $category) { echo " Index: $index => Category: '{$category['name']}'\n"; } echo "\n"; // Test with the numeric array structure $state->setCategories($numericCategories); $state->setCurrentView(TuiView::CATEGORIES); $state->setRunning(true); echo "โœ“ Setup Complete:\n"; echo " Categories Count: " . count($numericCategories) . "\n"; echo " Current View: " . $state->getCurrentView()->name . "\n"; echo " Selected Category Index: " . $state->getSelectedCategory() . "\n"; $currentCategory = $state->getCurrentCategory(); if ($currentCategory) { echo " Current Category Name: '{$currentCategory['name']}'\n"; } else { echo " โŒ Current Category: NULL (This would cause navigation issues!)\n"; } echo "\n"; // Test navigation with the real structure echo "๐Ÿ” Testing Navigation with Real Structure:\n\n"; // Test 1: Arrow Down echo "Test 1: Arrow DOWN\n"; $beforeCategory = $state->getCurrentCategory(); $beforeIndex = $state->getSelectedCategory(); echo " Before: Index $beforeIndex => '{$beforeCategory['name']}'\n"; $inputHandler->handleInput(TuiKeyCode::ARROW_DOWN->value, $state, $history); $afterCategory = $state->getCurrentCategory(); $afterIndex = $state->getSelectedCategory(); echo " After: Index $afterIndex => '{$afterCategory['name']}'\n"; echo " โœ“ Navigation worked: " . ($beforeIndex !== $afterIndex ? "YES" : "NO") . "\n\n"; // Test 2: Arrow Down again echo "Test 2: Arrow DOWN again\n"; $beforeCategory = $state->getCurrentCategory(); $beforeIndex = $state->getSelectedCategory(); echo " Before: Index $beforeIndex => '{$beforeCategory['name']}'\n"; $inputHandler->handleInput(TuiKeyCode::ARROW_DOWN->value, $state, $history); $afterCategory = $state->getCurrentCategory(); $afterIndex = $state->getSelectedCategory(); echo " After: Index $afterIndex => '{$afterCategory['name']}'\n"; echo " โœ“ Navigation worked: " . ($beforeIndex !== $afterIndex ? "YES" : "NO") . "\n\n"; // Test 3: Arrow Up echo "Test 3: Arrow UP\n"; $beforeCategory = $state->getCurrentCategory(); $beforeIndex = $state->getSelectedCategory(); echo " Before: Index $beforeIndex => '{$beforeCategory['name']}'\n"; $inputHandler->handleInput(TuiKeyCode::ARROW_UP->value, $state, $history); $afterCategory = $state->getCurrentCategory(); $afterIndex = $state->getSelectedCategory(); echo " After: Index $afterIndex => '{$afterCategory['name']}'\n"; echo " โœ“ Navigation worked: " . ($beforeIndex !== $afterIndex ? "YES" : "NO") . "\n\n"; echo "โœ… Real Navigation Test COMPLETED\n"; } catch (\Throwable $e) { echo "\nโŒ Real Navigation Test FAILED:\n"; echo "Error: " . $e->getMessage() . "\n"; echo "File: " . $e->getFile() . ":" . $e->getLine() . "\n"; echo "\nStack trace:\n" . $e->getTraceAsString() . "\n"; }