Skip to content

Commit 6120afd

Browse files
committed
docs
1 parent d503ea1 commit 6120afd

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,56 @@ The third param on the `->addItem` call is what disables an item while the `->di
362362

363363
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.
364364

365+
#### Redrawing the menu
366+
367+
You can modify the menu and its style when executing an action and then you can redraw it! In this example we will toggle the background
368+
colour in an action.
369+
370+
```php
371+
$itemCallable = function (CliMenu $menu) {
372+
$menu->getStyle()->setBg($menu->getStyle()->getBg() === 'red' ? 'blue' : 'red');
373+
$menu->redraw();
374+
};
375+
376+
$menu = (new CliMenuBuilder)
377+
->setTitle('Basic CLI Menu')
378+
->addItem('First Item', $itemCallable)
379+
->addItem('Second Item', $itemCallable)
380+
->addItem('Third Item', $itemCallable)
381+
->addLineBreak('-')
382+
->build();
383+
384+
$menu->open();
385+
```
386+
387+
#### Getting, Removing and Adding items
388+
389+
You can also interact with the menu items in an action:
390+
391+
```php
392+
use PhpSchool\CliMenu\MenuItem\LineBreakItem;
393+
394+
$itemCallable = function (CliMenu $menu) {
395+
foreach ($menu->getItems() as $item) {
396+
$menu->removeItem($item);
397+
}
398+
399+
$menu->addItem(new LineBreakItem('-'));
400+
401+
$menu->redraw();
402+
};
403+
404+
$menu = (new CliMenuBuilder)
405+
->setTitle('Basic CLI Menu')
406+
->addItem('First Item', $itemCallable)
407+
->addItem('Second Item', $itemCallable)
408+
->addItem('Third Item', $itemCallable)
409+
->addLineBreak('-')
410+
->build();
411+
412+
$menu->open();
413+
```
414+
365415
---
366416

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

0 commit comments

Comments
 (0)