/** * Constructor. * * @param boolean $forceColors If set to TRUE, colorization will be enforced * whether or not the current console supports it */ public function __construct($forceColors = false) { if (LimeColorizer::isSupported() || $forceColors) { $colorizer = new LimeColorizer(); $colorizer->setStyle(self::ERROR, array('bg' => 'red', 'fg' => 'white', 'bold' => true)); $colorizer->setStyle(self::INFO, array('fg' => 'green', 'bold' => true)); $colorizer->setStyle(self::PARAMETER, array('fg' => 'cyan')); $colorizer->setStyle(self::COMMENT, array('fg' => 'yellow')); $colorizer->setStyle(self::GREEN_BAR, array('fg' => 'white', 'bg' => 'green', 'bold' => true)); $colorizer->setStyle(self::RED_BAR, array('fg' => 'white', 'bg' => 'red', 'bold' => true)); $colorizer->setStyle(self::INFO_BAR, array('fg' => 'cyan', 'bold' => true)); $this->colorizer = $colorizer; } }
/** * (non-PHPdoc) * @see output/LimeOutputFactoryInterface#create($name) */ public function create($name) { $colorizer = LimeColorizer::isSupported() || $this->configuration->getForceColors() ? new LimeColorizer() : null; $printer = new LimePrinter($colorizer); switch ($name) { case 'raw': return new LimeOutputRaw(); case 'xml': return new LimeOutputXml($this->configuration); case 'suite': return new LimeOutputSuite($printer, $this->configuration); case 'tap': default: return new LimeOutputTap($printer, $this->configuration); } }
public function create($name) { $colorizer = LimeColorizer::isSupported() || $this->options['force_colors'] ? new LimeColorizer() : null; $printer = new LimePrinter($colorizer); switch ($name) { case 'raw': return new LimeOutputRaw(); case 'xml': return new LimeOutputXml(); case 'array': return new LimeOutputArray($this->options['serialize']); case 'summary': return new LimeOutputConsoleSummary($printer, $this->options); case 'tap': default: return new LimeOutputTap($printer, $this->options); } }
/** * Returns a colorized export of the given value depending on its type. * * @param mixed $value * @return string */ function lime_colorize($value) { static $colorizer = null; if (is_null($colorizer) && LimeColorizer::isSupported()) { $colorizer = new LimeColorizer(); $colorizer->setStyle('string', array('fg' => 'cyan')); $colorizer->setStyle('integer', array('fg' => 'green')); $colorizer->setStyle('double', array('fg' => 'green')); $colorizer->setStyle('boolean', array('fg' => 'red')); } $type = gettype($value); $value = var_export($value, true); if (!is_null($colorizer) && in_array($type, array('string', 'integer', 'double', 'boolean'))) { $value = $colorizer->colorize($value, $type); } return $value; }
<?php /* * This file is part of the Lime framework. * * (c) Fabien Potencier <*****@*****.**> * (c) Bernhard Schussek <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ $t = new LimeTest(); $t->diag('Text can be colorized with font and color styles'); $c = new LimeColorizer(); $t->is($c->colorize('Hello World', array('bold' => true)), "[1mHello World[0m", 'Text can be bold'); $t->is($c->colorize('Hello World', array('underscore' => true)), "[4mHello World[0m", 'Text can be underscored'); $t->is($c->colorize('Hello World', array('blink' => true)), "[5mHello World[0m", 'Text can be blinking'); $t->is($c->colorize('Hello World', array('reverse' => true)), "[7mHello World[0m", 'Text can be reversed'); $t->is($c->colorize('Hello World', array('conceal' => true)), "[8mHello World[0m", 'Text can be invisible'); $t->is($c->colorize('Hello World', array('fg' => 'white')), "[37mHello World[0m", 'Text can have a custom text color'); $t->is($c->colorize('Hello World', array('bg' => 'white')), "[47mHello World[0m", 'Text can have a custom background color'); $t->is($c->colorize('Hello World', array('bold' => true, 'fg' => 'black', 'bg' => 'white')), "[30;47;1mHello World[0m", 'Styles can be combined'); $t->diag('Text styles can be preset using ->setStyle()'); $c = new LimeColorizer(); $c->setStyle('test_style', array('bold' => true, 'fg' => 'black', 'bg' => 'white')); $t->is($c->colorize('Hello World', 'test_style'), "[30;47;1mHello World[0m", 'Predefined styles can be used'); $t->diag('Text styles can be preset using backwards compatible ::style()'); LimeAutoloader::enableLegacyMode(); lime_colorizer::style('test_style', array('bold' => true, 'fg' => 'black', 'bg' => 'white')); $c = new lime_colorizer(); $t->is($c->colorize('Hello World', 'test_style'), "[30;47;1mHello World[0m", 'Predefined styles can be used');