Skip to content

Propagates styles from bottom up #210

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 5 commits into from
Dec 20, 2019
Merged

Propagates styles from bottom up #210

merged 5 commits into from
Dec 20, 2019

Conversation

jtreminio
Copy link
Contributor

Test code:

<?php

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

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

$menu = (new CliMenuBuilder)
    ->setBackgroundColour('black')
    ->setForegroundColour('green')
    ->setTitle('Color Test #1')
    ->addLineBreak()
    ->addSubMenu('Submenu #1', function (CliMenuBuilder $b) {
        $b->setTitle('Color Test #2')
            ->addLineBreak()
            ->addSubMenu('Submenu #2', function (CliMenuBuilder $b) {
                $b->setTitle('Color Test #3')
                    ->addLineBreak()
                    ->addItem('Foo #6', function (CliMenu $menu) {})
                    ->addItem('Foo #7', function (CliMenu $menu) {})
                    ->addLineBreak()
                ;
            })
            ->addItem('Foo #4', function (CliMenu $menu) {})
            ->addItem('Foo #5', function (CliMenu $menu) {})
            ->addLineBreak()
        ;
    })
    ->addItem('Foo #2', function (CliMenu $menu) {})
    ->addItem('Foo #3', function (CliMenu $menu) {})
    ->addLineBreak()
    ->build()
;

$menu->open();

@codecov-io
Copy link

codecov-io commented Dec 20, 2019

Codecov Report

Merging #210 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##             master   #210      +/-   ##
==========================================
+ Coverage     93.91%    94%   +0.09%     
- Complexity      516    521       +5     
==========================================
  Files            29     29              
  Lines          1561   1569       +8     
==========================================
+ Hits           1466   1475       +9     
+ Misses           95     94       -1
Impacted Files Coverage Δ Complexity Δ
src/Builder/CliMenuBuilder.php 82.87% <100%> (+1.13%) 75 <6> (+5) ⬆️

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 c72b588...6253477. Read the comment docs.

@jtreminio
Copy link
Contributor Author

jtreminio commented Dec 20, 2019

Fixes #201

Waits until CliMenuBuilder() is called to pass styles from the root-level CliMenu and drilling into all children submenus.

If a submenu has custom styles, it passes that to its children, ignoring the parent's style.

@jtreminio
Copy link
Contributor Author

Added support for propagating to split item children.

<?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();
};

$menu = (new CliMenuBuilder)
    ->setTitle('Select a Language')
    ->setUncheckedMarker('o ')
    ->setCheckedMarker('x ')
    ->addSplitItem(function (SplitItemBuilder $b) use ($itemCallable) {
        $b->setGutter(5)
            ->addCheckboxItem('2-A', $itemCallable)
            ->addSubMenu('Options', function (CliMenuBuilder $b) use ($itemCallable) {
                $b->setTitle('CLI Menu > Options')
                    ->addCheckboxItem('Rust', $itemCallable)
                    ->addLineBreak('-');
            })
        ;
    })
    ->build();

$menu->open();

@AydinHassan AydinHassan merged commit da5a0b7 into php-school:master Dec 20, 2019
@jtreminio jtreminio deleted the feature/propagate-styles branch December 20, 2019 07:18
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