BUGFIX: Improved detection of CLI colour support

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63927 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-10-09 00:49:53 +00:00
parent fce3767389
commit db0644c985

View File

@ -5,6 +5,10 @@
* Support less-trivial output stuff such as colours (on xterm-color)
*/
class SSCli extends Object {
static function supports_colour() {
return posix_isatty(STDOUT);
}
/**
* Return text encoded for CLI output, optionally coloured
* @param string $fgColour The foreground colour - black, red, green, yellow, blue, magenta, cyan, white. Null is default.
@ -12,7 +16,7 @@ class SSCli extends Object {
* @param string $bold A boolean variable - bold or not.
*/
static function text($text, $fgColour = null, $bgColour = null, $bold = false) {
if(!isset($_SERVER['TERM']) || $_SERVER['TERM'] != 'xterm-color') return $text;
if(!self::supports_colour()) return $text;
$colours = array(
'black' => 0,