out('Overwrite: foo.php was overwritten.');` * * This would create orange 'Overwrite:' text, while the rest of the text would remain the normal colour. * See ConsoleOutput::styles() to learn more about defining your own styles. * * @package cake.console */ class ConsoleOutput { /** * File handle for output. * * @var resource */ protected $_output; /** * Constant for a newline. */ const LF = PHP_EOL; /** * text colors used in coloured output. * * @var array */ protected static $_foregroundColors = array( 'black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37 ); /** * background colours used in coloured output. * * @var array */ protected static $_backgroundColors = array( 'black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47 ); /** * formatting options for coloured output * * @var string */ protected static $_options = array( 'bold' => 1, 'underscore' => 4, 'blink' => 5, 'reverse' => 7, 'conceal' => 8 ); /** * Styles that are available as tags in console output. * You can modify these styles with ConsoleOutput::styles() * * @var array */ protected static $_styles = array( 'error' => array('text' => 'red'), 'warning' => array('text' => 'yellow'), 'info' => array('text' => 'cyan') ); /** * Construct the output object. * * @return void */ public function __construct($stream = 'php://stdout') { $this->_output = fopen($stream, 'w'); } /** * Outputs a single or multiple messages to stdout. If no parameters * are passed outputs just a newline. * * @param mixed $message A string or a an array of strings to output * @param integer $newlines Number of newlines to append * @return integer Returns the number of bytes returned from writing to stdout. */ public function write($message, $newlines = 1) { if (is_array($message)) { $message = implode(self::LF, $message); } return $this->_write($message . str_repeat(self::LF, $newlines)); } /** * Writes a message to the output stream * * @param string $message Message to write. * @return boolean success */ protected function _write($message) { return fwrite($this->_output, $message); } /** * Get the current styles offered, or append new ones in. * * @param string $style The style to get or create. * @param mixed $definition The array definition of the style to change or create a style * or false to remove a style. * @return mixed */ function styles($style = null, $definition = null) { if (is_string($style) && $definition === null) { return isset(self::$_styles[$style]) ? self::$_styles[$style] : null; } if ($definition === false) { unset(self::$_styles[$style]); return true; } self::$_styles[$style] = $definition; } /** * clean up and close handles * * @return void */ public function __destruct() { fclose($this->_output); } }