Skip to content

Finalize SelectableStyle for items #216

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

Merged
merged 6 commits into from
Dec 20, 2019
Merged

Finalize SelectableStyle for items #216

merged 6 commits into from
Dec 20, 2019

Conversation

jtreminio
Copy link
Contributor

@jtreminio jtreminio commented Dec 20, 2019

Related to #200

MenuStyle::$itemExtra should also be removed MenuStyle::$displaysExtra, as they are no longer used for anything. Will put that in a separate PR.

The only thing noteworthy in this particular PR is the addition of SplitItem::calculateItemExtra().

Since SplitItem does not contain its own styling, and markers/item extra are item-level now vs living in MenuStyle, this method loops through all items assigned to the split and finds the item with the largest item-extra value to calculate column sizes.

@codecov-io
Copy link

codecov-io commented Dec 20, 2019

Codecov Report

Merging #216 into master will decrease coverage by 0.28%.
The diff coverage is 89.39%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #216      +/-   ##
============================================
- Coverage     93.29%   93.01%   -0.29%     
- Complexity      589      591       +2     
============================================
  Files            31       30       -1     
  Lines          1760     1761       +1     
============================================
- Hits           1642     1638       -4     
- Misses          118      123       +5
Impacted Files Coverage Δ Complexity Δ
src/MenuStyle.php 96.8% <ø> (-0.2%) 64 <0> (-6)
src/MenuItem/StaticItem.php 100% <100%> (ø) 12 <2> (+2) ⬆️
src/Builder/CliMenuBuilder.php 77.17% <100%> (-0.56%) 89 <0> (ø)
src/MenuItem/MenuMenuItem.php 82.69% <83.78%> (+1.44%) 18 <12> (+11) ⬆️
src/MenuItem/SplitItem.php 99.27% <95%> (-0.73%) 49 <6> (+4)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4992019...16f56b8. Read the comment docs.

/**
* Finds largest itemExtra value in items
*/
private function calculateItemExtra() : void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a change in behaviour or just a refactor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing noteworthy in this particular PR is the addition of SplitItem::calculateItemExtra().
Since SplitItem does not contain its own styling, and markers/item extra are item-level now vs living in MenuStyle, this method loops through all items assigned to the split and finds the item with the largest item-extra value to calculate column sizes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but what I mean is why. Is that new behaviour, for all columns to be equal size? I don't remember the current behaviour.

Copy link
Contributor Author

@jtreminio jtreminio Dec 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking latest stable tag with this:

<?php

use PhpSchool\CliMenu\Builder\SplitItemBuilder;
use PhpSchool\CliMenu\CliMenu;
use PhpSchool\CliMenu\Builder\CliMenuBuilder;

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

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

$builder = (new CliMenuBuilder)
    ->setTitle('Basic CLI Menu Custom Item Extra')
    ->addSplitItem(function (SplitItemBuilder $b) use ($itemCallable) {
        $b->addItem('First Item', $itemCallable, true)
            ->addItem('Second Item', $itemCallable, true)
            ->addItem('Third Item', $itemCallable, true);
    })
    ->setItemExtra('[COMPLETE!]')
    ->addLineBreak('-');

$builder->getStyle()
    ->setDisplaysExtra(true);

$menu = $builder->build();

$menu->open();

It seems the item extra string is not displayed when in a split item:

image

Should I remove?

This is how it looks in this PR:

Peek 2019-12-20 11-41

using this code:

<?php

use PhpSchool\CliMenu\Builder\SplitItemBuilder;
use PhpSchool\CliMenu\CliMenu;
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
use PhpSchool\CliMenu\MenuItem\SelectableItem;

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

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

$menu = (new CliMenuBuilder)
    ->setTitle('Basic CLI Menu Custom Item Extra')
    ->setWidth(150)
    ->addSplitItem(function (SplitItemBuilder $b) use ($itemCallable) {
        $item1 = new SelectableItem('First Item', $itemCallable, true);
        $item1->getStyle()->setItemExtra('[COMPLETE!]');

        $item2 = new SelectableItem('Second Item Second Item Second Item', $itemCallable, true);
        $item2->getStyle()->setItemExtra('[abc!]');

        $item3 = new SelectableItem('Third Item', $itemCallable, true);
        $item3->getStyle()->setItemExtra('[!]');

        $b->build()
            ->addItem($item1)
            ->addItem($item2)
            ->addItem($item3);
    })
    ->addLineBreak('-')
    ->build();

$menu->open();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, no that's fine :)

@AydinHassan AydinHassan merged commit 4a0bb52 into php-school:master Dec 20, 2019
@AydinHassan
Copy link
Member

Thank you

@jtreminio jtreminio deleted the feature/selectable-style branch December 20, 2019 19:49
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

Successfully merging this pull request may close these issues.

3 participants