File tree Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Expand file tree Collapse file tree 3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1111};
1212
1313$ menu = (new CliMenuBuilder )
14+ ->disableAutoShortcuts ()
1415 ->setTitle ('Basic CLI Menu ' )
1516 ->addItem ('[F]irst Item ' , $ itemCallable )
1617 ->addItem ('Se[c]ond Item ' , $ itemCallable )
Original file line number Diff line number Diff line change @@ -57,6 +57,14 @@ class CliMenuBuilder
5757 */
5858 private $ disabled = false ;
5959
60+ /**
61+ * Whether or not to auto create keyboard shortcuts for items
62+ * when they contain square brackets. Eg: [M]y item
63+ *
64+ * @var bool
65+ */
66+ private $ autoShortcuts = true ;
67+
6068 /**
6169 * @var bool
6270 */
@@ -183,6 +191,13 @@ public function addSubMenuFromBuilder(string $text, CliMenuBuilder $builder) : s
183191 return $ this ;
184192 }
185193
194+ public function disableAutoShortcuts () : self
195+ {
196+ $ this ->autoShortcuts = false ;
197+
198+ return $ this ;
199+ }
200+
186201 private function extractShortcut (string $ title ) : ?string
187202 {
188203 preg_match ('/\[(.)\]/ ' , $ title , $ match );
@@ -217,6 +232,10 @@ private function processSplitItemShortcuts(SplitItem $splitItem) : void
217232
218233 private function processIndividualShortcut (MenuItemInterface $ item , callable $ callback ) : void
219234 {
235+ if (!$ this ->autoShortcuts ) {
236+ return ;
237+ }
238+
220239 if ($ shortcut = $ this ->extractShortcut ($ item ->getText ())) {
221240 $ this ->menu ->addCustomControlMapping (
222241 $ shortcut ,
Original file line number Diff line number Diff line change @@ -779,7 +779,7 @@ public function testAddSplitItemWithClosureBinding() : void
779779
780780 $ this ->checkItems ($ menu ->getItems ()[0 ]->getItems (), $ expected );
781781 }
782-
782+
783783 private function checkMenuItems (CliMenu $ menu , array $ expected ) : void
784784 {
785785 $ this ->checkItems ($ this ->readAttribute ($ menu , 'items ' ), $ expected );
You can’t perform that action at this time.
0 commit comments