Skip to content

Commit 9146e20

Browse files
committed
Update CliMenu.php
allow usage of special chars with custom control mappings
1 parent 835c28e commit 9146e20

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/CliMenu.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ private function display() : void
296296
continue;
297297
}
298298

299-
switch ($char->getControl()) {
299+
$controlChar = $char->getControl();
300+
301+
switch ($controlChar) {
300302
case InputCharacter::UP:
301303
case InputCharacter::DOWN:
302304
$this->moveSelectionVertically($char->getControl());
@@ -310,6 +312,11 @@ private function display() : void
310312
case InputCharacter::ENTER:
311313
$this->executeCurrentItem();
312314
break;
315+
default:
316+
if (isset($this->customControlMappings[$controlChar])) {
317+
$this->customControlMappings[$controlChar]($this);
318+
}
319+
break;
313320
}
314321
}
315322
unset($reader);
@@ -374,7 +381,7 @@ protected function moveSelectionHorizontally(string $direction) : void
374381
: (int) reset($itemKeys);
375382
}
376383
} while (!$item->canSelectIndex($selectedItemIndex));
377-
384+
378385
$item->setSelectedItemIndex($selectedItemIndex);
379386
}
380387

@@ -541,7 +548,7 @@ protected function draw() : void
541548
protected function drawMenuItem(MenuItemInterface $item, bool $selected = false) : array
542549
{
543550
$rows = $item->getRows($this->style, $selected);
544-
551+
545552
if ($item instanceof SplitItem) {
546553
$selected = false;
547554
}
@@ -586,7 +593,7 @@ public function open() : void
586593
if ($this->isOpen()) {
587594
return;
588595
}
589-
596+
590597
if (count($this->items) === 0) {
591598
throw new \RuntimeException('Menu must have at least 1 item before it can be opened');
592599
}

0 commit comments

Comments
 (0)