Skip to content

Commit 4867b80

Browse files
committed
docs
1 parent 45c1848 commit 4867b80

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
* [Menu Methods](#menu-methods)
5353
* [Redrawing the Menu](#redrawing-the-menu)
5454
* [Getting, Removing and Adding items](#getting-removing-and-adding-items)
55-
* [Custom Control Mapping](#custom-control-mapping)
55+
* [Custom Control Mapping](#custom-control-mapping)
56+
* [Item Keyboard Shortcuts](#item-keyboard-shortcuts)
5657
* [Dialogues](#dialogues)
5758
* [Flash](#flash)
5859
* [Confirm](#confirm)
@@ -61,7 +62,7 @@
6162
* [Number](#number-input)
6263
* [Password](#password-input)
6364
* [Custom Input](#custom-input)
64-
* [Dialogues & Input Styling](#dialogues-input-styling)
65+
* [Dialogues & Input Styling](#dialogues--input-styling)
6566
* [Docs Translations](#docs-translations)
6667
* [Integrations](#integrations)
6768

@@ -888,7 +889,7 @@ $menu = (new CliMenuBuilder)
888889
$menu->open();
889890
```
890891

891-
### Custom Control Mapping
892+
## Custom Control Mapping
892893

893894
This functionality allows to map custom key presses to a callable. For example we can set the key press "x" to close the menu:
894895

@@ -933,6 +934,38 @@ $menu->addCustomControlMapping('C', $myCallback);
933934
$menu->open();
934935
```
935936

937+
## Item Keyboard Shortcuts
938+
939+
By default `CliMenuBuilder` will parse the items text and check for shortcuts. Any single character inside square brackets
940+
will be treated as a shortcut. Pressing that character when the menu is open will trigger that items callable.
941+
942+
This functionality works for split items as well as sub menus. The same characters can be used inside sub menus and the
943+
callable which is invoked will depend on which menu is currently open.
944+
945+
Note: all shortcuts are lower cased.
946+
947+
You can disable this automatic keyboard shortcut mapping if you would like:
948+
949+
```php
950+
<?php
951+
952+
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
953+
use PhpSchool\CliMenu\CliMenu;
954+
955+
$myCallback = function(CliMenu $menu) {
956+
// Do something
957+
};
958+
959+
$menu = (new CliMenuBuilder)
960+
->disableAutoShortcuts()
961+
->addItem('List of [C]lients', $myCallback)
962+
->build();
963+
964+
$menu->open();
965+
966+
//Pressing c will do nothing.
967+
```
968+
936969
### Dialogues
937970

938971
#### Flash

0 commit comments

Comments
 (0)