コード例 #1
0
ファイル: KernelOutput.php プロジェクト: Litipk/Jupyter-PHP
 /**
  * Writes a message to the output.
  *
  * @param string|array $messages The message as an array of lines or a single string
  * @param bool $newline Whether to add a newline
  * @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
  */
 public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL)
 {
     $types = self::OUTPUT_NORMAL | self::OUTPUT_RAW | self::OUTPUT_PLAIN;
     $type = $types & $options ?: self::OUTPUT_NORMAL;
     if (is_string($messages)) {
         if ("<aside>⏎</aside>" === $messages) {
             return;
         }
         $preparedMessage = $messages . ($newline ? '' : "\n");
         switch ($type) {
             case OutputInterface::OUTPUT_NORMAL:
                 $preparedMessage = $this->formatter->format($messages) . ($newline ? '' : "\n");
                 break;
             case OutputInterface::OUTPUT_RAW:
                 break;
             case OutputInterface::OUTPUT_PLAIN:
                 $preparedMessage = strip_tags($this->formatter->format($messages)) . ($newline ? '' : "\n");
                 break;
         }
     } elseif (is_array($messages)) {
         $preparedMessage = implode("\n", $messages) . ($newline ? '' : "\n");
     } else {
         return;
         // TODO: Throw an error?
     }
     $this->executeAction->notifyMessage($preparedMessage);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function format($message)
 {
     $formatted = $this->formatter->format($message);
     $escaped = htmlspecialchars($formatted, ENT_QUOTES, 'UTF-8');
     $converted = preg_replace_callback(self::CLI_COLORS_PATTERN, function ($matches) {
         return $this->replaceFormat($matches);
     }, $escaped);
     return $converted;
 }
コード例 #3
0
ファイル: ShellSpec.php プロジェクト: phpguard/phpguard
 function it_should_show_prompt(Application $application, OutputInterface $output, OutputFormatterInterface $outputFormatter)
 {
     $application->getName()->willReturn('some')->shouldBeCalled();
     $outputFormatter->format(Argument::containingString('some'))->shouldBeCalled()->willReturn('prompt');
     $output->write('prompt')->shouldBeCalled();
     $this->showPrompt();
 }
コード例 #4
0
ファイル: Helper.php プロジェクト: Ryu0621/SaNaVi
 public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, $string)
 {
     $isDecorated = $formatter->isDecorated();
     $formatter->setDecorated(false);
     $string = $formatter->format($string);
     $string = preg_replace("/\\[[^m]*m/", '', $string);
     $formatter->setDecorated($isDecorated);
     return self::strlen($string);
 }