src/Cli/Cli.php
public static function color($string, $options = null)
    {
        if ($options === null) {
            return $string;
        }

        if (is_string($options)) {
            $options = explode(';', $options);
            if (strlen($options[0]) === 1) {
                $options = array_pad($options, 3, 'default');
                $options = array_combine(['style', 'color', 'background'], $options);
            } else {
                $options = ['color' => reset($options)];
            }
        }

        $options += [
            'style'      => 'default',
            'color'      => 'default',
            'background' => 'default'
        ];

        $format = "\e[";
        $format .= static::_vtstyle($options['style']) . ';';
        $format .= static::_vtcolor($options['color']) . ';';
        $format .= static::_vtbackground($options['background']) . 'm';

        return $format . $string . "\e[0m";
    }
public static function color($string, $options = null)
    {
        if ($options === null) {
            return $string;
        }

        if (is_string($options)) {
            $options = explode(';', $options);
            if (strlen($options[0]) === 1) {
                $options = array_pad($options, 3, 'default');
                $options = array_combine(['style', 'color', 'background'], $options);
            } else {
                $options = ['color' => reset($options)];
            }
        }

        $options += [
            'style'      => 'default',
            'color'      => 'default',
            'background' => 'default'
        ];

        $format = "\e[";
        $format .= static::_vtstyle($options['style']) . ';';
        $format .= static::_vtcolor($options['color']) . ';';
        $format .= static::_vtbackground($options['background']) . 'm';

        return $format . $string . "\e[0m";
    }
public static function color ( $ string , $ options = null ) { if ( $ options === null ) { return $ string ; } if ( is_string ( $ options ) ) { $ options = explode ( ';' , $ options ) ; if ( strlen ( $ options [ 0 ] ) === 1 ) { $ options = array_pad ( $ options , 3 , 'default' ) ; $ options = array_combine ( [ 'style' , 'color' , 'background' ] , $ options ) ; } else { $ options = [ 'color' => reset ( $ options ) ] ; } } $ options += [ 'style' => 'default' , 'color' => 'default' , 'background' => 'default' ] ; $ format = "\e[" ; $ format .= static :: _vtstyle ( $ options [ 'style' ] ) . ';' ; $ format .= static :: _vtcolor ( $ options [ 'color' ] ) . ';' ; $ format .= static :: _vtbackground ( $ options [ 'background' ] ) . 'm' ; return $ format . $ string . "\e[0m" ; }
Return a VT100 colored string.

@param mixed        $string  The string to color.
@param string|array $options The possible values for an array are:
- `'style`: a style code.
- `'color'`: a color code.
- `'background'`: a background color code.

The string must respect one of the following format:
- `'style;color;background'`.
- `'style;color'`.
- `'color'`.
Return a VT100 colored string .