Esempio n. 1
0
 public function bindBackspace(Readline $self)
 {
     $cursor = '';
     if ($self->getLineCurrent() > 0) {
         if ($self->getLineLength() == ($current = $self->getLineCurrent())) {
             $self->setLine(mb_substr($self->getLine(), 0, -1));
         } else {
             $line = $self->getLine();
             $current = $self->getLineCurrent();
             $tail = mb_substr($line, $current);
             $movecursor = $self->getLineLength() - $current;
             $cursor = "[{$movecursor}D";
             $self->setLine(mb_substr($line, 0, $current - 1) . $tail);
             $self->setLineCurrent($current - 1);
         }
     }
     $prefix = $self->getPrefix();
     $self->clearTerminalLine();
     $self->setBuffer("\r" . $prefix . $self->getLine() . $cursor);
     return $self::READ_CONTINUE;
 }
Esempio n. 2
0
 /**
  * Control-F binding.
  * Move cursor forward one word.
  *
  * @access  public
  * @param   \Hoa\Console\Readline  $self    Self.
  * @return  int
  */
 public function _bindControlF(Readline $self)
 {
     $current = $self->getLineCurrent();
     if ($self->getLineLength() === $current) {
         return static::STATE_CONTINUE;
     }
     $words = preg_split('#\\b#u', $self->getLine(), -1, PREG_SPLIT_OFFSET_CAPTURE | PREG_SPLIT_NO_EMPTY);
     for ($i = 0, $max = count($words) - 1; $i < $max && $words[$i][1] < $current; ++$i) {
     }
     if (!isset($words[$i + 1])) {
         $words[$i + 1] = array(1 => $self->getLineLength());
     }
     for ($j = $words[$i + 1][1]; $j > $current; --$j) {
         $self->_bindArrowRight($self);
     }
     return static::STATE_CONTINUE;
 }