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

preserving selection index as you move up/down #279

Open
rbro opened this issue Nov 19, 2023 · 0 comments
Open

preserving selection index as you move up/down #279

rbro opened this issue Nov 19, 2023 · 0 comments

Comments

@rbro
Copy link

rbro commented Nov 19, 2023

I'm trying to see if I can use cli-menu to build a simple table/grid with rows and columns, similar to a spreadsheet.

I realize this was not the intent of cli-menu, but I can get pretty close with SplitItem's. I feel this could be an interesting use of cli-menu.

With the below script, the only usability item I noticed is if I go to cell B2 and press up, it brings me to cell A1, rather than B1 as I was hoping.

Is there a way an option could be set so that when you move up or down, cli-menu can set the index of the selected item to be the index of the item you had last selected?

Thanks for your help.

<?php
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
use PhpSchool\CliMenu\Builder\SplitItemBuilder;
use PhpSchool\CliMenu\CliMenu;

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

$menu = (new CliMenuBuilder)
    ->setWidth(150)
    ->addStaticItem('Below is a SplitItem')
    ->addSplitItem(function (SplitItemBuilder $b) use ($itemCallable) {
        $b->setGutter(5)
            ->addItem('A1', $itemCallable)
            ->addItem('B1', $itemCallable)
            ->addItem('C1', $itemCallable);
    })
    ->addSplitItem(function (SplitItemBuilder $b) use ($itemCallable) {
        $b->setGutter(5)
            ->addItem('A2', $itemCallable)
            ->addItem('B2', $itemCallable)
            ->addItem('C2', $itemCallable);
    })
    ->addSplitItem(function (SplitItemBuilder $b) use ($itemCallable) {
        $b->setGutter(5)
            ->addItem('A3', $itemCallable)
            ->addItem('B3', $itemCallable)
            ->addItem('C3', $itemCallable);
    })
    ->addSplitItem(function (SplitItemBuilder $b) use ($itemCallable) {
        $b->setGutter(5)
            ->addItem('A4', $itemCallable)
            ->addItem('B4', $itemCallable)
            ->addItem('C4', $itemCallable);
    })
    ->build();

$menu->open();
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