php-school / cli-menu

🖥 Build beautiful PHP CLI menus. Simple yet Powerful. Expressive DSL.
http://www.phpschool.io
MIT License
1.94k stars 106 forks source link

Item Extra outside of bounds when not initially shown #184

Closed jtreminio closed 4 years ago

jtreminio commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Fixed in #187