Return colored string
@param string $string message
@param string|null $foreground_color Foreground color
@param string|null $background_color Background color
@param bool $header If header is present
@return string Colored string
558231
public function getColoredString(
        string $string,
        string $foreground_color = null,
        string $background_color = null,
        bool $header = true
    ):string {
        if ($header) {
            $title = "Console Manager - ".CoreManager::getCurrentModule();
            $titleSeparator = $this->copyContent("-", strlen($title) + 10);
            $string = "\n\n" . $title . "\n" . $titleSeparator . "\n\n" . $string . "\n";
        } else {
            $string = "\n\n" . $string . "\n";
        }
        $string = $this->resizeContent($string);
        $colored_string = "";


        // Check if given foreground color found
        if (isset($this->foreground_colors[$foreground_color])) {
            $colored_string .= "\033[" . $this->foreground_colors[$foreground_color] . "m";
        }
        // Check if given background color found
        if (isset($this->background_colors[$background_color])) {
            $colored_string .= "\033[" . $this->background_colors[$background_color] . "m";
        }

        // Add string and end coloring
        $colored_string .=  $string . "\033[0m";

        return ($colored_string);
    }
621614
public static function dump($string, $color = null, $debug = true)
    {
        if ($debug) {
            print self::formatOutput($string, $color);
            static::flush();
        }
    }
142503
def color(string, status=True, warning=False, bold=True):
    
    attr = []
    if status:
        # green
        attr.append('32')
    if warning:
        # red
        attr.append('31')
    if bold:
        attr.append('1')
    return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
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";
    }
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;
    }
1227242
public function title($string, $backgorund='blue', $forgeground='white')
    {
        $string = $this->paintString(" {$string} ", $forgeground, $backgorund);

        echo $string ."\n\r";
    }
5794
function _hexToDecColor($hex)
    {
        $length = strlen($hex);
        $color['red'] = hexdec(substr($hex, $length - 6, 2));
        $color['green'] = hexdec(substr($hex, $length - 4, 2));
        $color['blue'] = hexdec(substr($hex, $length - 2, 2));
        return $color;
    }
842845
public static String colorHeader() {
        return  Color.BOLD +
                HEADER_L1 + "\n" +
                new Color(Color.YELLOW, Color.UNDERLINE) +
                HEADER_L2 + "    " +
                Color.CLEAR;
    }
98331
public function setDefaultBackgroundColor($color)
    {
        $this->log("Setting default background color to '$color'.");

        if (!(strlen($color) == 6 || strlen($color) == 8)) {
            throw new Exception(
                "Background color needs a hex value of 6 or 8
                digits. 000000-FFFFFF or 00000000-FFFFFF7F.
                Current value was: '$color'."
            );
        }

        $red    = hexdec(substr($color, 0, 2));
        $green  = hexdec(substr($color, 2, 2));
        $blue   = hexdec(substr($color, 4, 2));

        $alpha = (strlen($color) == 8)
            ? hexdec(substr($color, 6, 2))
            : null;

        if (($red < 0 || $red > 255)
            || ($green < 0 || $green > 255)
            || ($blue < 0 || $blue > 255)
            || ($alpha < 0 || $alpha > 127)
        ) {
            throw new Exception(
                "Background color out of range. Red, green blue
                should be 00-FF and alpha should be 00-7F.
                Current value was: '$color'."
            );
        }

        $this->bgColor = strtolower($color);
        $this->bgColorDefault = array(
            'red'   => $red,
            'green' => $green,
            'blue'  => $blue,
            'alpha' => $alpha
        );

        return $this;
    }
323413
public static function printColored ($string, $foreground_color = null, $background_color = null) {
		$colored_string = "";

		// Check if given foreground color found
		if (isset(Bartender::$foreground_colors[$foreground_color])) {
			$colored_string .= "\033[" . Bartender::$foreground_colors[$foreground_color] . "m";
		}
		// Check if given background color found
		if (isset(Bartender::$background_colors[$background_color])) {
			$colored_string .= "\033[" . Bartender::$background_colors[$background_color] . "m";
		}

		// Add string and end coloring
		$colored_string .=  $string;

		echo $colored_string;
	}
963257
public function style($string, $colourOrStyle)
    {
        if (is_array($colourOrStyle)) {
            $this->color->__invoke($string);

            while ($style = array_shift($colourOrStyle)) {
                $this->color->apply($style);
            }
            return $this->color->__toString();
        }

        return $this->color->__invoke($string)->apply($colourOrStyle, $string);
    }
406915
public static function highlight($string)
    {
        $tokens = self::tokenize($string);

        $return = '';

        foreach ($tokens as $token) {
            $return .= self::highlightToken($token);
        }

        return self::output($return);
    }
465228
public static function html2hsv( $string )
	{
		sscanf( $string, "%2X%2X%2X", $r, $g, $b );
		return self::rgb2hsv( array( $r, $g, $b ) );
	}
821300
public function getImageDataUri($string, $size = 64, $color = null, $backgroundColor = null)
    {
        return sprintf('data:%s;base64,%s', $this->generator->getMimeType(), base64_encode($this->getImageData($string, $size, $color, $backgroundColor)));
    }
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;
    }
661336
private function color($text, $fg, $bg = null)
    {
        if ($this->getConfig('use-colors')) {
            
            $colors = [];
            
            if ($fg != 'none') {
                $colors[] = sprintf('fg=%s', $fg);
            }
            
            if ($bg && $bg != 'none') {
                $colors[] = sprintf('bg=%s', $bg);
            }
            
            if (!empty($colors)) {
                return sprintf('<%s>%s</>', implode(';', $colors), $text);
            }
        }
        
        return $text;
    }
842607
protected function strlen($string)
    {
        // don't count color codes
        $string = preg_replace("/\33\\[\\d+(;\\d+)?m/", '', $string);

        if (function_exists('mb_strlen')) {
            return mb_strlen($string, 'utf-8');
        }

        return strlen($string);
    }