Skip to content

Commit

Permalink
fixe confim default value
Browse files Browse the repository at this point in the history
  • Loading branch information
ksauvanaud committed Feb 26, 2020
1 parent 5c6a035 commit 500d701
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/ConsoleTable/Readline.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand All @@ -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";
}

}
2 changes: 1 addition & 1 deletion tests/confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit 500d701

Please sign in to comment.