A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.yiiframework.com/doc/api/2.0/yii-helpers-console below:

Console, yii\helpers\Console | API Documentation for Yii 2.0

Defined in: yii\helpers\BaseConsole::renderColoredString()

Converts a string to ansi formatted by replacing patterns like %y (for yellow) with ansi control codes.

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 function renderColoredString($string, $colored = true)
{
    
    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_CYAN],
        '%7' => [self::BG_GREY],
        '%0' => [self::BG_BLACK],
        '%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;
}

            

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4