|
52 | 52 | * [Menu Methods](#menu-methods) |
53 | 53 | * [Redrawing the Menu](#redrawing-the-menu) |
54 | 54 | * [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) |
56 | 57 | * [Dialogues](#dialogues) |
57 | 58 | * [Flash](#flash) |
58 | 59 | * [Confirm](#confirm) |
|
61 | 62 | * [Number](#number-input) |
62 | 63 | * [Password](#password-input) |
63 | 64 | * [Custom Input](#custom-input) |
64 | | - * [Dialogues & Input Styling](#dialogues-input-styling) |
| 65 | + * [Dialogues & Input Styling](#dialogues--input-styling) |
65 | 66 | * [Docs Translations](#docs-translations) |
66 | 67 | * [Integrations](#integrations) |
67 | 68 |
|
@@ -888,7 +889,7 @@ $menu = (new CliMenuBuilder) |
888 | 889 | $menu->open(); |
889 | 890 | ``` |
890 | 891 |
|
891 | | -### Custom Control Mapping |
| 892 | +## Custom Control Mapping |
892 | 893 |
|
893 | 894 | This functionality allows to map custom key presses to a callable. For example we can set the key press "x" to close the menu: |
894 | 895 |
|
@@ -933,6 +934,38 @@ $menu->addCustomControlMapping('C', $myCallback); |
933 | 934 | $menu->open(); |
934 | 935 | ``` |
935 | 936 |
|
| 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 | + |
936 | 969 | ### Dialogues |
937 | 970 |
|
938 | 971 | #### Flash |
|
0 commit comments