Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 83fbce5

Browse files
Merge pull request #174 from php-school/Lynesth-patch-1
Allow ESC key to "cancel" editing an input
2 parents aff5729 + 975b101 commit 83fbce5

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
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 | ^3",
24-
"php-school/terminal": "dev-master",
24+
"php-school/terminal": "^0.2",
2525
"ext-posix": "*"
2626
},
2727
"autoload" : {

‎src/CliMenu.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function disableDefaultControlMappings() : void
214214
public function setDefaultControlMappings(array $defaultControlMappings) : void
215215
{
216216
$this->defaultControlMappings = $defaultControlMappings;
217-
}
217+
}
218218

219219
/**
220220
* Adds a custom control mapping

‎src/Input/InputIO.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function collect(Input $input) : InputResult
4040

4141
$inputValue = $input->getPlaceholderText();
4242
$havePlaceHolderValue = !empty($inputValue);
43+
44+
$originalValue = $inputValue;
4345

4446
$reader = new NonCanonicalReader($this->terminal);
4547

@@ -59,6 +61,9 @@ public function collect(Input $input) : InputResult
5961

6062
if ($char->isHandledControl()) {
6163
switch ($char->getControl()) {
64+
case InputCharacter::ESC:
65+
$this->parentMenu->redraw();
66+
return new InputResult($originalValue);
6267
case InputCharacter::ENTER:
6368
if ($input->validate($inputValue)) {
6469
$this->parentMenu->redraw();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /