當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Question::getAutocompleterValues方法代碼示例

本文整理匯總了PHP中Symfony\Component\Console\Question\Question::getAutocompleterValues方法的典型用法代碼示例。如果您正苦於以下問題:PHP Question::getAutocompleterValues方法的具體用法?PHP Question::getAutocompleterValues怎麽用?PHP Question::getAutocompleterValues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Console\Question\Question的用法示例。


在下文中一共展示了Question::getAutocompleterValues方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: autocomplete

 /**
  * Autocompletes a question.
  *
  * @param OutputInterface $output
  * @param Question        $question
  *
  * @return string
  */
 private function autocomplete(OutputInterface $output, Question $question, $inputStream)
 {
     $autocomplete = $question->getAutocompleterValues();
     $ret = '';
     $i = 0;
     $ofs = -1;
     $matches = $autocomplete;
     $numMatches = count($matches);
     $sttyMode = shell_exec('stty -g');
     // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
     shell_exec('stty -icanon -echo');
     // Add highlighted text style
     $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white'));
     // Read a keypress
     while (!feof($inputStream)) {
         $c = fread($inputStream, 1);
         // Backspace Character
         if ("" === $c) {
             if (0 === $numMatches && 0 !== $i) {
                 --$i;
                 // Move cursor backwards
                 $output->write("[1D");
             }
             if ($i === 0) {
                 $ofs = -1;
                 $matches = $autocomplete;
                 $numMatches = count($matches);
             } else {
                 $numMatches = 0;
             }
             // Pop the last character off the end of our string
             $ret = substr($ret, 0, $i);
         } elseif ("" === $c) {
             // Did we read an escape sequence?
             $c .= fread($inputStream, 2);
             // A = Up Arrow. B = Down Arrow
             if (isset($c[2]) && ('A' === $c[2] || 'B' === $c[2])) {
                 if ('A' === $c[2] && -1 === $ofs) {
                     $ofs = 0;
                 }
                 if (0 === $numMatches) {
                     continue;
                 }
                 $ofs += 'A' === $c[2] ? -1 : 1;
                 $ofs = ($numMatches + $ofs) % $numMatches;
             }
         } elseif (ord($c) < 32) {
             if ("\t" === $c || "\n" === $c) {
                 if ($numMatches > 0 && -1 !== $ofs) {
                     $ret = $matches[$ofs];
                     // Echo out remaining chars for current match
                     $output->write(substr($ret, $i));
                     $i = strlen($ret);
                 }
                 if ("\n" === $c) {
                     $output->write($c);
                     break;
                 }
                 $numMatches = 0;
             }
             continue;
         } else {
             $output->write($c);
             $ret .= $c;
             ++$i;
             $numMatches = 0;
             $ofs = 0;
             foreach ($autocomplete as $value) {
                 // If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
                 if (0 === strpos($value, $ret) && $i !== strlen($value)) {
                     $matches[$numMatches++] = $value;
                 }
             }
         }
         // Erase characters from cursor to end of line
         $output->write("[K");
         if ($numMatches > 0 && -1 !== $ofs) {
             // Save cursor position
             $output->write("7");
             // Write highlighted text
             $output->write('<hl>' . substr($matches[$ofs], $i) . '</hl>');
             // Restore cursor position
             $output->write("8");
         }
     }
     // Reset stty so it behaves normally again
     shell_exec(sprintf('stty %s', $sttyMode));
     return $ret;
 }
開發者ID:unexge,項目名稱:symfony,代碼行數:97,代碼來源:QuestionHelper.php

示例2: autocomplete

 private function autocomplete(OutputInterface $output, Question $question, $inputStream)
 {
     $autocomplete = $question->getAutocompleterValues();
     $ret = '';
     $i = 0;
     $ofs = -1;
     $matches = $autocomplete;
     $numMatches = count($matches);
     $sttyMode = shell_exec('stty -g');
     shell_exec('stty -icanon -echo');
     $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white'));
     while (!feof($inputStream)) {
         $c = fread($inputStream, 1);
         if ("" === $c) {
             if (0 === $numMatches && 0 !== $i) {
                 --$i;
                 $output->write("[1D");
             }
             if ($i === 0) {
                 $ofs = -1;
                 $matches = $autocomplete;
                 $numMatches = count($matches);
             } else {
                 $numMatches = 0;
             }
             $ret = substr($ret, 0, $i);
         } elseif ("" === $c) {
             $c .= fread($inputStream, 2);
             if (isset($c[2]) && ('A' === $c[2] || 'B' === $c[2])) {
                 if ('A' === $c[2] && -1 === $ofs) {
                     $ofs = 0;
                 }
                 if (0 === $numMatches) {
                     continue;
                 }
                 $ofs += 'A' === $c[2] ? -1 : 1;
                 $ofs = ($numMatches + $ofs) % $numMatches;
             }
         } elseif (ord($c) < 32) {
             if ("\t" === $c || "\n" === $c) {
                 if ($numMatches > 0 && -1 !== $ofs) {
                     $ret = $matches[$ofs];
                     $output->write(substr($ret, $i));
                     $i = strlen($ret);
                 }
                 if ("\n" === $c) {
                     $output->write($c);
                     break;
                 }
                 $numMatches = 0;
             }
             continue;
         } else {
             $output->write($c);
             $ret .= $c;
             ++$i;
             $numMatches = 0;
             $ofs = 0;
             foreach ($autocomplete as $value) {
                 if (0 === strpos($value, $ret) && $i !== strlen($value)) {
                     $matches[$numMatches++] = $value;
                 }
             }
         }
         $output->write("[K");
         if ($numMatches > 0 && -1 !== $ofs) {
             $output->write("7");
             $output->write('<hl>' . substr($matches[$ofs], $i) . '</hl>');
             $output->write("8");
         }
     }
     shell_exec(sprintf('stty %s', $sttyMode));
     return $ret;
 }
開發者ID:Ryu0621,項目名稱:SaNaVi,代碼行數:74,代碼來源:QuestionHelper.php


注:本文中的Symfony\Component\Console\Question\Question::getAutocompleterValues方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。