mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding support for uncoloured output for windows environments without
ansicon.
This commit is contained in:
parent
90d5c12b3e
commit
5c55c289f7
1 changed files with 17 additions and 0 deletions
|
@ -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.
|
||||
*/
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,6 +157,9 @@ class ConsoleOutput {
|
|||
* @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
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue