Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/CliMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,17 @@ protected function moveSelectionVertically(string $direction) : void
{
$itemKeys = array_keys($this->items);

$increments = 0;

do {
$increments++;

if ($increments > count($itemKeys)) {
//full cycle detected, there must be no selected items
//in the menu, so stop trying to select one.
return;
}

$direction === 'UP'
? $this->selectedItem--
: $this->selectedItem++;
Expand Down
14 changes: 14 additions & 0 deletions test/CliMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,20 @@ public function testGetSelectedItemThrowsExceptionIfNoSelectedItem() : void
$menu->getSelectedItem();
}

public function testMenuCanOpenAndFunctionWithoutAnySelectableItems() : void
{
$this->terminal->expects($this->exactly(3))
->method('read')
->willReturn("\033[B", "\033[B", 'Q');
$menu = new CliMenu('PHP School FTW', [new StaticItem('One')], $this->terminal);
$menu->addCustomControlMapping('Q', function (CliMenu $menu) {
$menu->close();
});
$menu->open();

self::assertCount(1, $menu->getItems());
}

private function getTestFile() : string
{
return sprintf('%s/res/%s.txt', __DIR__, $this->getName());
Expand Down