Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop with no selectable items in menu #144

Closed
Lynesth opened this issue May 14, 2018 · 0 comments
Closed

Infinite loop with no selectable items in menu #144

Lynesth opened this issue May 14, 2018 · 0 comments

Comments

@Lynesth
Copy link
Collaborator

Lynesth commented May 14, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant