console : manage the history without error (bug introduced with the time of each command stored)
console : add a tokenize method to get the user data from line git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5547 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
30
console.php
30
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
|
||||
|
||||
Reference in New Issue
Block a user