Skip to content

Commit f61d122

Browse files
committed
Add example and API docs for disabling items
1 parent 18a66a7 commit f61d122

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Check out the [examples](examples) directory and run them to check out what is p
8585
<img width="600" alt="submenu" src="https://cloud.githubusercontent.com/assets/2817002/11442401/e6f03ef2-950c-11e5-897a-6d55496a4105.png">
8686
<img width="600" alt="submenu-options" src="https://cloud.githubusercontent.com/assets/2817002/11442403/eaf4782e-950c-11e5-82c5-ab57f84cd6bc.png">
8787

88+
##### Disabled Items & Submenus
89+
<img width="600" alt="submenu" src="https://cloud.githubusercontent.com/assets/2174476/19047849/868fa8c0-899b-11e6-9004-811c8da6d435.png">
8890

8991
### API
9092

@@ -329,7 +331,38 @@ $subMenu = $mainMenuBuilder->getSubMenu('Super Sub Menu');
329331

330332
You can only do this after the main menu has been built, this is because the main menu builder takes care of building all sub menus.
331333

334+
#### Disabling Items & Sub Menus
332335

336+
In this example we are disabling certain items and a submenu but still having them shown in the output.
337+
338+
```php
339+
$itemCallable = function (CliMenu $menu) {
340+
echo $menu->getSelectedItem()->getText();
341+
};
342+
343+
$menu = (new CliMenuBuilder)
344+
->setTitle('Basic CLI Menu Disabled Items')
345+
->addItem('First Item', $itemCallable)
346+
->addItem('Second Item', $itemCallable, false, true)
347+
->addItem('Third Item', $itemCallable, false, true)
348+
->addSubMenu('Submenu')
349+
->setTitle('Basic CLI Menu Disabled Items > Submenu')
350+
->addItem('You can go in here!', $itemCallable)
351+
->end()
352+
->addSubMenu('Disabled Submenu')
353+
->setTitle('Basic CLI Menu Disabled Items > Disabled Submenu')
354+
->addItem('Nope can\'t see this!', $itemCallable)
355+
->disableMenu()
356+
->end()
357+
->addLineBreak('-')
358+
->build();
359+
```
360+
361+
The third param on the `->addItem` call is what disables an item while the `->disableMenu()` call disables the relevent menu.
362+
363+
The outcome is a full menu with dimmed rows to denote them being disabled. When a user navigates these items are jumped over to the next available selectable item.
364+
365+
---
333366

334367
Once you get going you might just end up with something that looks a little like this...
335368

0 commit comments

Comments
 (0)