Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding support for uncoloured output for windows environments without
ansicon.
  • Loading branch information
markstory committed Oct 14, 2010
1 parent 90d5c12 commit 5c55c28
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cake/console/console_output.php
Expand Up @@ -50,6 +50,13 @@ class ConsoleOutput {
*/
protected $_output;

/**
* Is set to true for consoles that can take pretty output. (Not windows).
*
* @var boolean
*/
protected $_prettyOutput = true;

/**
* Constant for a newline.
*/
Expand Down Expand Up @@ -115,10 +122,17 @@ class ConsoleOutput {
/**
* Construct the output object.
*
* Checks for a pretty console enviornment. Ansicon allows pretty consoles
* on windows, and is supported.
*
* @return void
*/
public function __construct($stream = 'php://stdout') {
$this->_output = fopen($stream, 'w');

if (DS == '\\') {
$this->_prettyOutput = (bool)env('ANSICON');
}
}

/**
Expand All @@ -143,6 +157,9 @@ public function write($message, $newlines = 1) {
* @return string String with color codes added.
*/
public function styleText($text) {
if (!$this->_prettyOutput) {
return strip_tags($text);
}
return preg_replace_callback(
'/<(?<tag>[a-z0-9-_]+)>(?<text>.*)<\/(\1)>/i', array($this, '_replaceTags'), $text
);
Expand Down

0 comments on commit 5c55c28

Please sign in to comment.