diff --git a/console.php b/console.php index f62095f..a3bced2 100644 --- a/console.php +++ b/console.php @@ -498,7 +498,8 @@ class console if ($historyPos > 0) { $historyPos--; - $string = $this->history[$historyPos]; + $slice = array_slice ($this->history, $historyPos, 1); + $string = reset ($slice); $cursorPos = mb_strlen ($prompt.$string) + 1; $this->rewriteLine ($prompt.$string); $this->moveCursor ($cursorPos); @@ -513,7 +514,8 @@ class console if ($historyPos < count ($this->history) - 1) { $historyPos++; - $string = $this->history[$historyPos]; + $slice = array_slice ($this->history, $historyPos, 1); + $string = reset ($slice); $cursorPos = mb_strlen ($prompt.$string) + 1; } elseif (isset ($historyTmp)) @@ -925,6 +927,30 @@ class console } // }}} + /** Tokenize the provided line and aggragate if there is single or double + * quotes. + * Trim the spaces + * @param string $line The line to tokenize + * @return array The tokens + */ + public function tokenize ($line) + // {{{ + { + $tokens = array (); + $token = strtok ($line,' '); + while ($token) + { + // find double quoted tokens + if ($token{0}=='"') { $token .= ' '.strtok('"').'"'; } + // find single quoted tokens + if ($token{0}=="'") { $token .= ' '.strtok("'")."'"; } + $tokens[] = $token; + $token = strtok(' '); + } + return $tokens; + } + // }}} + /** This function return an array with each char, but supports UTF-8 * @param string $string The string to explode * @param integer $split_length The number of chars in each split