diff --git a/console.php b/console.php index 95a289e..b69ebbe 100644 --- a/console.php +++ b/console.php @@ -292,7 +292,7 @@ class console $completeArr = call_user_func ($this->completionFunction, $string); $isAssoc = is_array ($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) !== " ") { @@ -314,7 +314,7 @@ class console else $string .= reset ($completeArr); } - else + elseif (is_array ($completeArr) && count ($completeArr)) { // Multiple answers : display them // 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"; } } - $cursorPos = mb_strlen ($prompt.$string) + 1; - $this->rewriteLine ($prompt.$string); - $this->moveCursor ($cursorPos); + if (is_array ($completeArr) && count ($completeArr)) + { + $cursorPos = mb_strlen ($prompt.$string) + 1; + $this->rewriteLine ($prompt.$string); + $this->moveCursor ($cursorPos); + } } // }}} elseif (ord ($char) === 3) @@ -377,7 +380,7 @@ class console // Logout (Ctrl+D) // {{{ { - $string = "exit"; + $string = "exit\n"; $this->rewriteLine ($prompt.$string); return $string; } @@ -841,6 +844,8 @@ class console private function shortestIdenticalValues ($completeArr) // {{{ { + if (! is_array ($completeArr)) + return ""; $minlen = 99999; foreach ($completeArr as $val) {