FUnit::color PHP Method

color() protected static method

Colouring code loosely based on http://www.zend.com//code/codex.php?ozid=1112&single=1
See also: FUnit::$TERM_COLORS
protected static color ( $txt, string $color = 'DEFAULT' )
$color string default is 'DEFAULT'
    protected static function color($txt, $color = 'DEFAULT')
    {
        if (PHP_SAPI === 'cli') {
            // only color if output is a posix TTY
            if (function_exists('posix_isatty') && posix_isatty(STDOUT)) {
                $color = static::$TERM_COLORS[$color];
                $txt = chr(27) . "[0;{$color}m{$txt}" . chr(27) . "[00m";
            }
            // otherwise, don't touch $txt
        } else {
            $color = strtolower($color);
            $txt = "<span style=\"color: {$color};\">{$txt}</span>";
        }
        return $txt;
    }