From e4e380dd0837fdf6801260b24a844c66b6e9a083 Mon Sep 17 00:00:00 2001 From: Lynesth Date: Tue, 2 Apr 2019 15:07:39 +1100 Subject: [PATCH 1/3] Allow ESC key to "cancel" editing an input It will simply return the initial value (empty string or the placeholder text) when the user presses the ESC key, even if the text was modified. --- src/Input/InputIO.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Input/InputIO.php b/src/Input/InputIO.php index 2efb3a18..163f00ca 100644 --- a/src/Input/InputIO.php +++ b/src/Input/InputIO.php @@ -40,6 +40,8 @@ public function collect(Input $input) : InputResult $inputValue = $input->getPlaceholderText(); $havePlaceHolderValue = !empty($inputValue); + + $originalValue = $inputValue; $reader = new NonCanonicalReader($this->terminal); @@ -59,6 +61,9 @@ public function collect(Input $input) : InputResult if ($char->isHandledControl()) { switch ($char->getControl()) { + case InputCharacter::ESC: + $this->parentMenu->redraw(); + return new InputResult($originalValue); case InputCharacter::ENTER: if ($input->validate($inputValue)) { $this->parentMenu->redraw(); From f8064bdba6c2fb69139aaf5c6820a2a5254ebed7 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Tue, 2 Apr 2019 13:58:57 +0400 Subject: [PATCH 2/3] Update php-school/terminal --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8c15c0a7..3cddb176 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "require": { "php" : ">=7.1", "beberlei/assert": "^2.4 | ^3", - "php-school/terminal": "dev-master", + "php-school/terminal": "^0.2", "ext-posix": "*" }, "autoload" : { From 975b101233ece85dfd6229e6591549364fbd5ba7 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Tue, 2 Apr 2019 14:00:23 +0400 Subject: [PATCH 3/3] CS --- src/CliMenu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CliMenu.php b/src/CliMenu.php index 01cc9f7f..49ec3ee2 100644 --- a/src/CliMenu.php +++ b/src/CliMenu.php @@ -214,7 +214,7 @@ public function disableDefaultControlMappings() : void public function setDefaultControlMappings(array $defaultControlMappings) : void { $this->defaultControlMappings = $defaultControlMappings; - } + } /** * Adds a custom control mapping