Skip to content

Commit 5c55c28

Browse files
committed
Adding support for uncoloured output for windows environments without
ansicon.
1 parent 90d5c12 commit 5c55c28

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cake/console/console_output.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class ConsoleOutput {
5050
*/
5151
protected $_output;
5252

53+
/**
54+
* Is set to true for consoles that can take pretty output. (Not windows).
55+
*
56+
* @var boolean
57+
*/
58+
protected $_prettyOutput = true;
59+
5360
/**
5461
* Constant for a newline.
5562
*/
@@ -115,10 +122,17 @@ class ConsoleOutput {
115122
/**
116123
* Construct the output object.
117124
*
125+
* Checks for a pretty console enviornment. Ansicon allows pretty consoles
126+
* on windows, and is supported.
127+
*
118128
* @return void
119129
*/
120130
public function __construct($stream = 'php://stdout') {
121131
$this->_output = fopen($stream, 'w');
132+
133+
if (DS == '\\') {
134+
$this->_prettyOutput = (bool)env('ANSICON');
135+
}
122136
}
123137

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

0 commit comments

Comments
 (0)