console : manage correctely the bad provided values

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4264 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2018-07-06 15:08:18 +00:00
parent 70dc1ad73a
commit fb361bfaa4

View File

@@ -292,7 +292,7 @@ class console
$completeArr = call_user_func ($this->completionFunction, $string); $completeArr = call_user_func ($this->completionFunction, $string);
$isAssoc = is_array ($completeArr) && $isAssoc = is_array ($completeArr) &&
array_diff_key ($completeArr, array_keys (array_keys ($completeArr))); array_diff_key ($completeArr, array_keys (array_keys ($completeArr)));
if (count ($completeArr) === 1) if (is_array ($completeArr) && count ($completeArr) === 1)
{ {
if (substr ($string, -1) !== " ") if (substr ($string, -1) !== " ")
{ {
@@ -314,7 +314,7 @@ class console
else else
$string .= reset ($completeArr); $string .= reset ($completeArr);
} }
else elseif (is_array ($completeArr) && count ($completeArr))
{ {
// Multiple answers : display them // Multiple answers : display them
// Manage if all the answers start by the same chars : add them to the // Manage if all the answers start by the same chars : add them to the
@@ -358,9 +358,12 @@ class console
echo "\n".implode ("\n", $completeArr)."\n"; echo "\n".implode ("\n", $completeArr)."\n";
} }
} }
$cursorPos = mb_strlen ($prompt.$string) + 1; if (is_array ($completeArr) && count ($completeArr))
$this->rewriteLine ($prompt.$string); {
$this->moveCursor ($cursorPos); $cursorPos = mb_strlen ($prompt.$string) + 1;
$this->rewriteLine ($prompt.$string);
$this->moveCursor ($cursorPos);
}
} }
// }}} // }}}
elseif (ord ($char) === 3) elseif (ord ($char) === 3)
@@ -377,7 +380,7 @@ class console
// Logout (Ctrl+D) // Logout (Ctrl+D)
// {{{ // {{{
{ {
$string = "exit"; $string = "exit\n";
$this->rewriteLine ($prompt.$string); $this->rewriteLine ($prompt.$string);
return $string; return $string;
} }
@@ -841,6 +844,8 @@ class console
private function shortestIdenticalValues ($completeArr) private function shortestIdenticalValues ($completeArr)
// {{{ // {{{
{ {
if (! is_array ($completeArr))
return "";
$minlen = 99999; $minlen = 99999;
foreach ($completeArr as $val) foreach ($completeArr as $val)
{ {