yii\helpers\BaseConsole::renderColoredString PHP Method

renderColoredString() public static method

Uses almost the same syntax as https://github.com/pear/Console_Color2/blob/master/Console/Color2.php The conversion table is: ('bold' meaning 'light' on some terminals). It's almost the same conversion table irssi uses.
                 text      text            background
     ------------------------------------------------
     %k %K %0    black     dark grey       black
     %r %R %1    red       bold red        red
     %g %G %2    green     bold green      green
     %y %Y %3    yellow    bold yellow     yellow
     %b %B %4    blue      bold blue       blue
     %m %M %5    magenta   bold magenta    magenta
     %p %P       magenta (think: purple)
     %c %C %6    cyan      bold cyan       cyan
     %w %W %7    white     bold white      white

     %F     Blinking, Flashing
     %U     Underline
     %8     Reverse
     %_,%9  Bold

     %n     Resets the color
     %%     A single %
First param is the string to convert, second is an optional flag if colors should be used. It defaults to true, if set to false, the color codes will just be removed (And %% will be transformed into %)
public static renderColoredString ( string $string, boolean $colored = true ) : string
$string string String to convert
$colored boolean Should the string be colored?
return string
    public static function renderColoredString($string, $colored = true)
    {
        // TODO rework/refactor according to https://github.com/yiisoft/yii2/issues/746
        static $conversions = ['%y' => [self::FG_YELLOW], '%g' => [self::FG_GREEN], '%b' => [self::FG_BLUE], '%r' => [self::FG_RED], '%p' => [self::FG_PURPLE], '%m' => [self::FG_PURPLE], '%c' => [self::FG_CYAN], '%w' => [self::FG_GREY], '%k' => [self::FG_BLACK], '%n' => [0], '%Y' => [self::FG_YELLOW, self::BOLD], '%G' => [self::FG_GREEN, self::BOLD], '%B' => [self::FG_BLUE, self::BOLD], '%R' => [self::FG_RED, self::BOLD], '%P' => [self::FG_PURPLE, self::BOLD], '%M' => [self::FG_PURPLE, self::BOLD], '%C' => [self::FG_CYAN, self::BOLD], '%W' => [self::FG_GREY, self::BOLD], '%K' => [self::FG_BLACK, self::BOLD], '%N' => [0, self::BOLD], '%3' => [self::BG_YELLOW], '%2' => [self::BG_GREEN], '%4' => [self::BG_BLUE], '%1' => [self::BG_RED], '%5' => [self::BG_PURPLE], '%6' => [self::BG_PURPLE], '%7' => [self::BG_CYAN], '%0' => [self::BG_GREY], '%F' => [self::BLINK], '%U' => [self::UNDERLINE], '%8' => [self::NEGATIVE], '%9' => [self::BOLD], '%_' => [self::BOLD]];
        if ($colored) {
            $string = str_replace('%%', '% ', $string);
            foreach ($conversions as $key => $value) {
                $string = str_replace($key, static::ansiFormatCode($value), $string);
            }
            $string = str_replace('% ', '%', $string);
        } else {
            $string = preg_replace('/%((%)|.)/', '$2', $string);
        }
        return $string;
    }