Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Ridzhi committed Jan 16, 2017
1 parent f2efc53 commit 561dd0f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 38 deletions.
44 changes: 22 additions & 22 deletions demo/hoa.php
Expand Up @@ -10,7 +10,7 @@
//} while (false !== $line && 'quit' !== $line);

//$input = 'command "some arg fdfsd';
$input = 'command some --name= --city="moscow"';
$input = 'command some -n --name --city="moscow"';


//var_dump(substr_count($input, "\""));
Expand All @@ -20,12 +20,12 @@



//$parser = new \Hoa\Console\Parser();
$parser = new \Hoa\Console\Parser();
//$parser->
//$parser->parse($input);
$parser->parse($input);

//var_dump($parser->getInputs());
//var_dump($parser->getSwitches());
var_dump($parser->getInputs());
var_dump($parser->getSwitches());

//$arr = [
// 'one' => "dn",
Expand All @@ -41,20 +41,20 @@
////
////var_dump($last[0]);

echo
'abcdef', "\n",
'ghijkl', "\n",
'mnopqr', "\n",
'stuvwx';

sleep(3);
Hoa\Console\Cursor::move('↑');
sleep(1);
Hoa\Console\Cursor::move('↑ ←');
sleep(5);
Hoa\Console\Cursor::move('left', 3);
echo "inject";
sleep(2);
Hoa\Console\Cursor::move('DOWN');
sleep(1);
Hoa\Console\Cursor::move('→', 4);
//echo
//'abcdef', "\n",
//'ghijkl', "\n",
//'mnopqr', "\n",
//'stuvwx';
//
//sleep(3);
//Hoa\Console\Cursor::move('↑');
//sleep(1);
//Hoa\Console\Cursor::move('↑ ←');
//sleep(5);
//Hoa\Console\Cursor::move('left', 3);
//echo "inject";
//sleep(2);
//Hoa\Console\Cursor::move('DOWN');
//sleep(1);
//Hoa\Console\Cursor::move('→', 4);
2 changes: 1 addition & 1 deletion src/InputBuffer.php
Expand Up @@ -94,7 +94,7 @@ public function getAbsolutePos(): int
public function removeChar()
{
if (!$this->isEmpty()) {
$this->buffer = substr($this->buffer, 0, -1);
$this->buffer = substr($this->buffer, 0, $this->pos - 1) . substr($this->buffer, $this->pos);
$this->pos--;

return true;
Expand Down
36 changes: 21 additions & 15 deletions src/Readline.php
Expand Up @@ -138,21 +138,8 @@ protected function bindBackspace(Readline $self)
protected function bindLF(Readline $self)
{
if ($self->window->isActive()) {
$value = $self->window->getValue();
$current = $this->buffer->getCurrent();

$info = new InputInfo($current);
//TODO Рассмотреть что дополняем и по ситуации ставить в конце пробел и смещать курсор за скобки,
// если это например значение опции
//TODO всего три кейса: аргумент, опция, значение опции
// пока только аргумент
// в буффер должна быть вставка с учетом внутренней позиции
$current = $info->getCurrent();
$offset = ($current !== InputBuffer::EMPTY) ? strlen($current) : 0;
$complition = substr($value, $offset);
$this->buffer->insert($complition);
$this->processComplete();

$this->resetWindow();
} else {
// код запуска команды

Expand Down Expand Up @@ -182,14 +169,33 @@ protected function bindArrowDown(Readline $self)

protected function bindArrowLeft(Readline $self)
{
$this->buffer->prev();
$self->buffer->prev();
}

protected function resetWindow()
{
$this->window->loadContent($this->getComplete());
}

protected function processComplete()
{
$value = $this->window->getValue();
$current = $this->buffer->getCurrent();

$info = new InputInfo($current);
//TODO Рассмотреть что дополняем и по ситуации ставить в конце пробел и смещать курсор за скобки,
// если это например значение опции
//TODO всего три кейса: аргумент, опция, значение опции
// пока только аргумент
// в буффер должна быть вставка с учетом внутренней позиции
$current = $info->getCurrent();
$offset = ($current !== InputBuffer::EMPTY) ? strlen($current) : 0;
$complition = substr($value, $offset);
$this->buffer->insert($complition);

$this->resetWindow();
}

protected function printBuffer()
{
Cursor::clear('line');
Expand Down
1 change: 1 addition & 0 deletions src/TestCompleter.php
Expand Up @@ -32,6 +32,7 @@ public function complete(InputInfoInterface $info): array
return $this->getArguments();
}

return [];
}

public function getCommands()
Expand Down

0 comments on commit 561dd0f

Please sign in to comment.