/** * @param string $input * @param int $verbosity * @param OutputFormatterInterface|null $formatter */ public function __construct($input = '', $verbosity = StreamOutput::VERBOSITY_NORMAL, OutputFormatterInterface $formatter = null) { $input = new StringInput($input); $input->setInteractive(false); $output = new StreamOutput(fopen('php://memory', 'rw'), $verbosity, $formatter ? $formatter->isDecorated() : false, $formatter); parent::__construct($input, $output, new HelperSet(array())); }
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(); }
/** * 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); }
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); }
/** * {@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; }
/** * Adds some output formatters. * * @param OutputFormatterInterface */ private function configureFormatters(OutputFormatterInterface $formatter) { $formatter->setStyle('title', new OutputFormatterStyle('white', null, array('bold'))); $formatter->setStyle('description', new OutputFormatterStyle(null, null, array())); }
public function applyTo(OutputFormatterInterface $outputFormatter) { foreach ($this->styles as $name => $style) { $outputFormatter->setStyle($name, $style); } }
/** * Setup the formatter. * * @param OutputFormatterInterface $formatter */ protected function setupFormatters(OutputFormatterInterface $formatter) { $formatter->setStyle('file', new OutputFormatterStyle('white', 'default', ['bold'])); $formatter->setStyle('source', new OutputFormatterStyle('blue', 'default', [])); $formatter->setStyle('success', new OutputFormatterStyle('white', 'green', [])); }