example：^^ color text $$ normal text.....

@param string $string
@param string $color
@param bool   $appendTime
336357
public static function write(string $string, string $color = null, $appendTime = true)
    {
        parseColor:
        $prefix = $suffix = '';
        if ($color) {
            $color = strtolower(trim($color));
            switch ($color) {
                case 'blue' :
                    $prefix = "\033[44;37;1m";
                    break;
                case 'green' :
                    $prefix = "\033[42;37;1m";
                    break;
                case 'red' :
                    $prefix = "\033[41;37;1m";
                    break;
                case 'yellow' :
                    $prefix = "\033[43;37;1m";
                    break;
                default:
                    $color = 'blue';
                    goto parseColor;
                    break;
            }

            if ($prefix) {
                $suffix = "\033[0m";
            }

            if (strpos($string, '^^') === false) {
                $hasEof = mb_substr($string, -1, 1) === "\n";
                $string = rtrim($string, "\n");
                $string = '^^' . $string . '$$';
                if ($hasEof) {
                    $string .= "\n";
                }
            }

            $string = str_replace(['^^', '$$'], [$prefix, $suffix], $string);
        }

        if (mb_substr($string, -1, 1) !== "\n") {
            $string .= "\n";
        }

        if ($appendTime) {
            $string = '[' . date('m-d H:i:s') . '] ' . $string;
        }

        echo $string;
    }
712179
public function paint($string)
    {
        $coloredString = "";

        // set foreground color
        if (array_key_exists($this->foreground, $this->foregroundColors)) {
            $coloredString .= "\033[" . $this->foregroundColors[ $this->foreground ] . "m";
        }

        // set background color
        if (array_key_exists($this->background, $this->backgroundColors)) {
            $coloredString .= "\033[" . $this->backgroundColors[ $this->background ] . "m";
        }

        // combine with string and end the painting
        $coloredString .= $string . "\033[0m";

        return $coloredString;
    }
621614
public static function dump($string, $color = null, $debug = true)
    {
        if ($debug) {
            print self::formatOutput($string, $color);
            static::flush();
        }
    }
984017
public static function color($text, $foreground, $background = null)
    {
        $foreground = self::$colors[$foreground];
        $code = "\x03".$foreground;
        
        if ($background !== null) {
            $background = self::$colors[$background];
            $code .= ','.$background;
        }
        
        return $code.$text."\x03";
    }
1088603
def update_color(string, name, style='normal', when='auto'):
    
    clear()
    write_color(string, name, style, when)
859091
def red(cls, string, auto=False):
        
        return cls.colorize('red', string, auto=auto)
972664
public static function colour($text, $foregroundColors = null, $backgroundColors = null)
    {
        if (self::$noAnsi) {
            return $text;
        }

        $colour = function ($text) use ($foregroundColors, $backgroundColors) {
            $colors = [];
            if ($backgroundColors) {
                $bColor = self::charToCode($backgroundColors);
                $colors[] = "4{$bColor[0]}";
            }

            if ($foregroundColors) {
                list($fColor, $option) = self::charToCode($foregroundColors);
                $option && $colors[] = $option;
                $colors[] = "3{$fColor}";
            }

            $colors && $text = sprintf("\033[%sm", implode(';', $colors)) . $text . "\033[0m";//关闭所有属性;

            return $text;
        };

        $lines = explode("\n", $text);
        foreach ($lines as &$line) {
            $line = $colour($line);
        }
        return implode("\n", $lines);
    }
82625
function colorize(color, str) {
  return str
      .split('\n')
      .map(part => color(part))
      .join('\n');
}
328517
public function writeText($text, $color = null, $bgColor = null)
    {
        $this->adapter->writeText($text, $color, $bgColor);
    }
843297
private void appendStyleColor(final XMLUtil util, final Appendable appendable) throws IOException {
        appendable.append("<style:text-properties");
        util.appendAttribute(appendable, "fo:color", this.negativeValueColor.hexValue());
        appendable.append("/>");
    }
798690
protected function image404($text, $backgroundColor, $color, $width, $height)
    {
        $text = (string) $text;
        $backgroundColor = (string) $backgroundColor;
        $color = (string) $color;
        $width = (int) $width;
        $height = (int) $height;
        
        if (strlen($backgroundColor) != 6 || !preg_match('![0-9abcdef]!i', $backgroundColor)) {
            $backgroundColor = 'F8F8F8';
        }
        if (strlen($color) != 6 || !preg_match('![0-9abcdef]!i', $color)) {
            $color = '777777';
        }
        if ($width <= 0) {
            $width = 100;
        }
        if ($height <= 0) {
            $height = 100;
        }
        
        $palette = new RGB();
        $size  = new Box($width, $height);
        $this->image = $this->getImagineService()->create($size, $palette->color('#' . $backgroundColor, 0));

        if ($text) {
            $this->drawCenteredText($text, $color);
        }
    }
139583
protected function colorize($color, $str, $resetTo = 'default')
    {
        $colors = [
            'cyan' => '1;36',
            'red' => '1;31',
            'yellow' => '1;33',
            'blue' => '0;34',
            'green' => '0;32',
            'default' => '0',
            'purple' => '0;35',
        ];

        return "\033[".$colors[$color].'m'.$str."\033[".$colors[$resetTo].'m';
    }
138962
private String checkColor(String color) {

        if (color != null) {
            if (color.indexOf("#") == -1) {
                // add the "#" to the color string
                color = "#" + color;
            }
            int colLength = color.length();
            if ((colLength == 4) || (colLength == 7)) {
                return color;
            }
        }
        return "#FFFFFF";
    }
1373275
static void tag(StringBuilder sb, String color, String text) {
        sb.append("<span class='label label");
        if (color != null) {
            sb.append("-").append(color);
        }
        String classText = text.replace(' ', '_');
        sb.append(" l-").append(classText).append("'>").append(text).append("</span>");
    }
729774
public void println(String text, Color color) {
        final Label label = new Label(text, skin, "outputEntry");
        label.setColor(color);
        label.setWrap(true);
        addLabel(label);
    }
692277
private static function apply($text, $color)
    {
        if (!array_key_exists($color, self::$outputFormatterStyles)) {
            self::$outputFormatterStyles[$color] = new OutputFormatterStyle($color);
        }

        return self::$outputFormatterStyles[$color]->apply($text);
    }
448140
public static function fromHexString(string $string) : Colour
    {
        list($r, $g, $b) = ColourStringParser::parseHexString($string);

        return new self($r, $g, $b);
    }