Skip to content

Infinite loop with no selectable items in menu #144

Closed
@Lynesth

Description

@Lynesth

So if you create a menu without any selectable item and then try to move the selection up/down, we end up in the moveSelectionVertically() loop forever.

Here is a sample to try it:

<?php

use PhpSchool\CliMenu\CliMenu;
use PhpSchool\CliMenu\CliMenuBuilder;
use PhpSchool\CliMenu\Action\ExitAction;

require_once(__DIR__ . '/../vendor/autoload.php');

$itemCallable = function (CliMenu $menu) {
    echo $menu->getSelectedItem()->getText();
};

$menu = (new CliMenuBuilder)
    ->disableDefaultItems()
    ->addStaticItem('blablabla')
    ->build();

$menu->addCustomControlMapping('Q', new ExitAction);
$menu->open();

Launch the example, then press Q to quit it, it works.
Launch the example, then press up or down arrow. Try to press Q to quit, doesn't work.

I think we should allow static only menus, as we can still do stuff with custom controls, but at some point we need to either remember if the menu contains selectable items or check during the loop if we went back to the start without finding anything to select.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions