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

Item Extra outside of bounds when not initially shown #184

Closed
jtreminio opened this issue Dec 15, 2019 · 2 comments
Closed

Item Extra outside of bounds when not initially shown #184

jtreminio opened this issue Dec 15, 2019 · 2 comments

Comments

@jtreminio
Copy link
Contributor

Using the example here:

https://github.com/php-school/cli-menu/blob/master/examples/toggle-item-extra.php

but changing the following

->addItem('First Item', $itemCallable, true)
->addItem('Second Item', $itemCallable, true)
->addItem('Third Item', $itemCallable, true)

to

->addItem('First Item', $itemCallable, false)
->addItem('Second Item', $itemCallable, false)
->addItem('Third Item', $itemCallable, false)

creates the item-extra string outside of terminal window:

image

Toggling the items to trigger $item->hideItemExtra() does not hide the item-extra strings.

A workaround is passing true to addItem() then looping through all items and hiding item-extra:

    $itemCallable = function (CliMenu $menu) {
        $item = $menu->getSelectedItem();

        $item->showsItemExtra()
            ? $item->hideItemExtra()
            : $item->showItemExtra();

        $menu->redraw();
    };

    $menu = (new CliMenuBuilder)
        ->setTitle('Basic CLI Menu')
        ->addItem('Option 1', $itemCallable, true)
        ->addItem('Option 2', $itemCallable, true)
        ->addItem('Option 3', $itemCallable, true)
        ->addLineBreak('-')
        ->build();

    foreach ($menu->getItems() as $item) {
        $item->hideItemExtra();
    }

    $menu->open();

This shows an initial list without the item-extra string, allows toggling an item to show item-extra, and allows toggling again to hide the item-extra string.

@AydinHassan
Copy link
Member

Yeah this is a known issue, reported in #66. I did have a look at fixing it the other day but couldn't think of a solution without changing loads of code. If you can think of a nice way to solve this, we'd happily accept a fix.

@AydinHassan
Copy link
Member

Fixed in #187

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

2 participants