From 500d701cc649dcb6be911cbd67fd21cd2046ad43 Mon Sep 17 00:00:00 2001 From: ksauvanaud Date: Wed, 26 Feb 2020 17:11:19 +0100 Subject: [PATCH] fixe confim default value --- src/ConsoleTable/Readline.php | 7 +++---- tests/confirm.php | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/ConsoleTable/Readline.php b/src/ConsoleTable/Readline.php index 4c9f6c4..52c8a27 100644 --- a/src/ConsoleTable/Readline.php +++ b/src/ConsoleTable/Readline.php @@ -23,7 +23,7 @@ private function choices(string $txt, array $availableParams, int $defaultValueI // Upper default value params if is active. if($activeParams && $defaultValueIndex >= 0){ - $availableParams[$defaultValueIndex] = strtoupper($availableParams[$defaultValueIndex]); + $availableParams[$defaultValueIndex] = strtoupper(ucfirst($availableParams[$defaultValueIndex])); } $txt = $activeParams ? $txt .= " (". implode('/', $availableParams) . ")" : $txt; @@ -34,7 +34,7 @@ private function choices(string $txt, array $availableParams, int $defaultValueI if($activeParams){ if(strlen($this->answer) === 0 && $defaultValueIndex >= 0){ $this->answer = $availableParams[$defaultValueIndex]; - }elseif (array_search($this->answer, $availableParams) === false){ + }elseif (array_search(strtolower($this->answer), array_map('strtolower', $availableParams)) === false){ $result = new Readline("The answer $this->answer is invalid, please enter valid value", $availableParams, $defaultValueIndex); $this->answer = $result->getAnswer(); } @@ -50,7 +50,6 @@ public function confirm() :bool { $this->choices("Choice: ".$this->answer."\nyou confirmed your choice ?", ['y', 'n'], 1); $choice = $this->answer; $this->answer = $previousChoice; - return $choice === "y"; + return strtolower($choice) === "y"; } - } diff --git a/tests/confirm.php b/tests/confirm.php index fd4db62..1ad566a 100644 --- a/tests/confirm.php +++ b/tests/confirm.php @@ -35,7 +35,7 @@ ]; $pt = new Table($columns, $lines, $conf); -$readline= new Readline("line to show", ['1', '2']); +$readline= new Readline("line to show", ['AaA', 'bBb']); $confirm = $readline->confirm(); if($confirm){