Skip to content

Commit 32b500a

Browse files
committed
Only switch handled controls
1 parent 27779f8 commit 32b500a

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"require": {
2222
"php" : ">=7.1",
2323
"beberlei/assert": "^2.4",
24-
"php-school/terminal": "dev-master",
24+
"php-school/terminal": "dev-catch-all-controls",
2525
"ext-posix": "*"
2626
},
2727
"autoload" : {

src/CliMenu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private function display() : void
174174
]);
175175

176176
while ($this->isOpen() && $char = $reader->readCharacter()) {
177-
if ($char->isNotControl()) {
177+
if (!$char->isHandledControl()) {
178178
continue;
179179
}
180180

src/Input/InputIO.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,29 @@ public function collect(Input $input) : InputResult
5757
continue;
5858
}
5959

60-
switch ($char->getControl()) {
61-
case InputCharacter::ENTER:
62-
if ($input->validate($inputValue)) {
60+
if ($char->isHandledControl()) {
61+
switch ($char->getControl()) {
62+
case InputCharacter::ENTER:
63+
if ($input->validate($inputValue)) {
64+
$this->parentMenu->redraw();
65+
return new InputResult($inputValue);
66+
} else {
67+
$this->drawInputWithError($input, $inputValue);
68+
continue 2;
69+
}
70+
71+
case InputCharacter::BACKSPACE:
72+
$inputValue = substr($inputValue, 0, -1);
6373
$this->parentMenu->redraw();
64-
return new InputResult($inputValue);
65-
} else {
66-
$this->drawInputWithError($input, $inputValue);
74+
$this->drawInput($input, $inputValue);
6775
continue 2;
68-
}
69-
70-
case InputCharacter::BACKSPACE:
71-
$inputValue = substr($inputValue, 0, -1);
72-
$this->parentMenu->redraw();
73-
$this->drawInput($input, $inputValue);
74-
continue 2;
75-
}
76+
}
7677

77-
if (!empty($this->callbacks[$char->getControl()])) {
78-
foreach ($this->callbacks[$char->getControl()] as $callback) {
79-
$inputValue = $callback($inputValue);
80-
$this->drawInput($input, $inputValue);
78+
if (!empty($this->callbacks[$char->getControl()])) {
79+
foreach ($this->callbacks[$char->getControl()] as $callback) {
80+
$inputValue = $callback($inputValue);
81+
$this->drawInput($input, $inputValue);
82+
}
8183
}
8284
}
8385
}

0 commit comments

Comments
 (0)