From 0c55adebe0182ac0984952a5250539033899b0e0 Mon Sep 17 00:00:00 2001 From: Markus Fischer Date: Wed, 3 Sep 2014 10:47:05 +0200 Subject: [PATCH] console: don't use colored output if there's no TTY This prevents ANSI escape codes and style tags showing up in cron-jobs, pipes or redirects. --- lib/Cake/Console/ConsoleOutput.php | 5 ++++- lib/Cake/Log/Engine/ConsoleLog.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Console/ConsoleOutput.php b/lib/Cake/Console/ConsoleOutput.php index ab9828d83..2b5176887 100644 --- a/lib/Cake/Console/ConsoleOutput.php +++ b/lib/Cake/Console/ConsoleOutput.php @@ -161,7 +161,10 @@ class ConsoleOutput { public function __construct($stream = 'php://stdout') { $this->_output = fopen($stream, 'w'); - if (DS === '\\' && !(bool)env('ANSICON')) { + if ( + (DS === '\\' && !(bool)env('ANSICON')) || + (function_exists('posix_isatty') && !posix_isatty($this->_output)) + ) { $this->_outputAs = self::PLAIN; } } diff --git a/lib/Cake/Log/Engine/ConsoleLog.php b/lib/Cake/Log/Engine/ConsoleLog.php index 14f40d2c6..807b02777 100644 --- a/lib/Cake/Log/Engine/ConsoleLog.php +++ b/lib/Cake/Log/Engine/ConsoleLog.php @@ -48,7 +48,10 @@ class ConsoleLog extends BaseLog { */ public function __construct($config = array()) { parent::__construct($config); - if (DS === '\\' && !(bool)env('ANSICON')) { + if ( + (DS === '\\' && !(bool)env('ANSICON')) || + (function_exists('posix_isatty') && !posix_isatty($this->_output)) + ) { $outputAs = ConsoleOutput::PLAIN; } else { $outputAs = ConsoleOutput::COLOR;