/** * Creates the formatter. * * @param StyleSet $styleSet The style set to use. */ public function __construct(StyleSet $styleSet = null) { $this->innerFormatter = new OutputFormatter(false); if (!$styleSet) { $styleSet = new DefaultStyleSet(); } foreach ($styleSet->toArray() as $tag => $style) { $this->innerFormatter->setStyle($tag, StyleConverter::convert($style)); } }
public function testRedefineStyle() { $formatter = new OutputFormatter(true); $style = new OutputFormatterStyle('blue', 'white'); $formatter->setStyle('info', $style); $this->assertEquals("[34;47msome custom msg[39;49m", $formatter->format('<info>some custom msg</info>')); }
public function testRedefineStyle() { $formatter = new OutputFormatter(true); $style = $this->getMockBuilder('Symfony\\Component\\Console\\Formatter\\OutputFormatterStyleInterface')->getMock(); $formatter->setStyle('info', $style); $style->expects($this->once())->method('apply')->will($this->returnValue('[STYLE_BEG]some custom msg[STYLE_END]')); $this->assertEquals("[STYLE_BEG]some custom msg[STYLE_END]", $formatter->format('<info>some custom msg</info>')); }
public function __construct($config) { $this->config = array_merge($this->config, $config); // enable interactive output mode for CLI $this->isInteractive = $this->config['interactive'] && isset($_SERVER['TERM']) && php_sapi_name() == 'cli' && $_SERVER['TERM'] != 'linux'; $formatter = new OutputFormatter($this->config['colors']); $formatter->setStyle('default', new OutputFormatterStyle()); $formatter->setStyle('bold', new OutputFormatterStyle(null, null, ['bold'])); $formatter->setStyle('focus', new OutputFormatterStyle('magenta', null, ['bold'])); $formatter->setStyle('ok', new OutputFormatterStyle('green', null, ['bold'])); $formatter->setStyle('error', new OutputFormatterStyle('white', 'red', ['bold'])); $formatter->setStyle('fail', new OutputFormatterStyle('red', null, ['bold'])); $formatter->setStyle('pending', new OutputFormatterStyle('yellow', null, ['bold'])); $formatter->setStyle('debug', new OutputFormatterStyle('cyan')); $formatter->setStyle('comment', new OutputFormatterStyle('yellow')); $formatter->setStyle('info', new OutputFormatterStyle('green')); $this->formatHelper = new FormatterHelper(); parent::__construct($this->config['verbosity'], $this->config['colors'], $formatter); }
/** * Override run method to internationalize error message. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return int Return code */ public function run(InputInterface $input, OutputInterface $output) { // Set extra colors // The most problem is $output->getFormatter() don't work. // So create new formatter to add extra color. $formatter = new OutputFormatter($output->isDecorated()); $formatter->setStyle('red', new OutputFormatterStyle('red', 'black')); $formatter->setStyle('green', new OutputFormatterStyle('green', 'black')); $formatter->setStyle('yellow', new OutputFormatterStyle('yellow', 'black')); $formatter->setStyle('blue', new OutputFormatterStyle('blue', 'black')); $formatter->setStyle('magenta', new OutputFormatterStyle('magenta', 'black')); $formatter->setStyle('yellow-blue', new OutputFormatterStyle('yellow', 'blue')); $output->setFormatter($formatter); \App::setLocale(\Config::get('syncle::MessageLang')); try { $result = parent::run($input, $output); } catch (\RuntimeException $e) { // All error messages were hard coded in // Symfony/Component/Console/Input/Input.php if ($e->getMessage() == 'Not enough arguments.') { $this->error(\Lang::get('syncle::BaseCommand.ArgumentNotEnough')); } elseif ($e->getMessage() == 'Too many arguments.') { $this->error(\Lang::get('syncle::BaseCommand.TooManyArgument')); } elseif (preg_match('/The "(.+)" option does not exist./', $e->getMessage(), $matches)) { $this->error(\Lang::get('syncle::BaseCommand.OptionNotExist', array('option' => $matches[1]))); } else { $this->error($e->getMessage()); } $result = 1; } return $result; }
/** * Initialize and get console output formatter * * @return OutputFormatter */ protected function getOutputFormatter() { if (null === $this->outputFormatter) { $formatter = new OutputFormatter(true); $formatter->setStyle(LogLevel::EMERGENCY, new OutputFormatterStyle('white', 'red')); $formatter->setStyle(LogLevel::ALERT, new OutputFormatterStyle('white', 'red')); $formatter->setStyle(LogLevel::CRITICAL, new OutputFormatterStyle('red')); $formatter->setStyle(LogLevel::ERROR, new OutputFormatterStyle('red')); $formatter->setStyle(LogLevel::WARNING, new OutputFormatterStyle('yellow')); $formatter->setStyle(LogLevel::NOTICE, new OutputFormatterStyle()); $formatter->setStyle(LogLevel::INFO, new OutputFormatterStyle()); $formatter->setStyle(LogLevel::DEBUG, new OutputFormatterStyle('cyan')); $this->outputFormatter = $formatter; } return $this->outputFormatter; }
function __construct($config) { $this->config = array_merge($this->config, $config); $formatter = new OutputFormatter($this->config['colors']); $formatter->setStyle('bold', new OutputFormatterStyle(null, null, array('bold'))); $formatter->setStyle('focus', new OutputFormatterStyle('magenta', null, array('bold'))); $formatter->setStyle('ok', new OutputFormatterStyle('white', 'magenta')); $formatter->setStyle('error', new OutputFormatterStyle('white', 'red')); $formatter->setStyle('debug', new OutputFormatterStyle('cyan')); $formatter->setStyle('info', new OutputFormatterStyle('yellow')); $this->formatHelper = new FormatterHelper(); parent::__construct($this->config['verbosity'], $this->config['colors'], $formatter); }
public function run(InputInterface $input, OutputInterface $output) { // Set extra colors. // The most problem is $output->getFormatter() don't work... // So create new formatter to add extra color. $formatter = new OutputFormatter($output->isDecorated()); $formatter->setStyle('red', new OutputFormatterStyle('red', 'black')); $formatter->setStyle('green', new OutputFormatterStyle('green', 'black')); $formatter->setStyle('yellow', new OutputFormatterStyle('yellow', 'black')); $formatter->setStyle('blue', new OutputFormatterStyle('blue', 'black')); $formatter->setStyle('magenta', new OutputFormatterStyle('magenta', 'black')); $formatter->setStyle('yellow-blue', new OutputFormatterStyle('yellow', 'blue')); $output->setFormatter($formatter); return parent::run($input, $output); }
/** * Configure the output formatter */ private function configureFormatter(OutputFormatter $formatter) { $style = new OutputFormatterStyle('yellow', null, array('bold')); $formatter->setStyle('path', $style); $style = new OutputFormatterStyle('green'); $formatter->setStyle('localname', $style); $style = new OutputFormatterStyle(null, null, array('bold')); $formatter->setStyle('node', $style); $style = new OutputFormatterStyle('blue', null, array('bold')); $formatter->setStyle('templatenode', $style); $style = new OutputFormatterStyle('blue', null, array()); $formatter->setStyle('templateproperty', $style); $style = new OutputFormatterStyle(null, null, array()); $formatter->setStyle('property', $style); $style = new OutputFormatterStyle('magenta', null, array('bold')); $formatter->setStyle('node-type', $style); $style = new OutputFormatterStyle('magenta', null, array()); $formatter->setStyle('property-type', $style); $style = new OutputFormatterStyle(null, null, array()); $formatter->setStyle('property-value', $style); $style = new OutputFormatterStyle(null, 'red', array()); $formatter->setStyle('exception', $style); }