-
Notifications
You must be signed in to change notification settings - Fork 106
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
Finalize SelectableStyle for items #216
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
src/MenuItem/SplitItem.php
Outdated
/** | ||
* Finds largest itemExtra value in items | ||
*/ | ||
private function calculateItemExtra() : void |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
Should I remove?
This is how it looks in this PR:
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();
There was a problem hiding this comment.
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 :)
Thank you |
Related to #200
MenuStyle::$itemExtra
should also be removedMenuStyle::$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.