public static function formatWithColor(string $color, string $buffer) : string
    {
        $codes   = array_map('trim', explode(',', $color));
        $lines   = explode("\n", $buffer);
        $padding = max(array_map('strlen', $lines));

        $styles = [];
        foreach ($codes as $code) {
            $styles[] = self::$ansiCodes[$code];
        }
        $style = sprintf("\x1b[%sm", implode(';', $styles));

        $styledLines = [];
        foreach ($lines as $line) {
            $styledLines[] = strlen($line) ? $style . str_pad($line, $padding) . "\x1b[0m" : '';
        }

        return implode(PHP_EOL, $styledLines);
    }
public static function formatWithColor(string $color, string $buffer) : string
    {
        $codes   = array_map('trim', explode(',', $color));
        $lines   = explode("\n", $buffer);
        $padding = max(array_map('strlen', $lines));

        $styles = [];
        foreach ($codes as $code) {
            $styles[] = self::$ansiCodes[$code];
        }
        $style = sprintf("\x1b[%sm", implode(';', $styles));

        $styledLines = [];
        foreach ($lines as $line) {
            $styledLines[] = strlen($line) ? $style . str_pad($line, $padding) . "\x1b[0m" : '';
        }

        return implode(PHP_EOL, $styledLines);
    }
public static function formatWithColor ( string $ color , string $ buffer ) : string { $ codes = array_map ( 'trim' , explode ( ',' , $ color ) ) ; $ lines = explode ( "\n" , $ buffer ) ; $ padding = max ( array_map ( 'strlen' , $ lines ) ) ; $ styles = [ ] ; foreach ( $ codes as $ code ) { $ styles [ ] = self :: $ ansiCodes [ $ code ] ; } $ style = sprintf ( "\x1b[%sm" , implode ( ';' , $ styles ) ) ; $ styledLines = [ ] ; foreach ( $ lines as $ line ) { $ styledLines [ ] = strlen ( $ line ) ? $ style . str_pad ( $ line , $ padding ) . "\x1b[0m" : '' ; } return implode ( PHP_EOL , $ styledLines ) ; }
Formats a buffer with a specified ANSI color sequence if colors are enabled.

@author Sebastian Bergmann <sebastian@phpunit.de>
@param  string $color
@param  string $buffer
@return string
Formats a buffer with a specified ANSI color sequence if colors are enabled .