protected function formatWithColor($color, $buffer)
{
if (!$this->colors) {
return $buffer;
}
$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("[%sm", implode(';', $styles));
$styledLines = [];
foreach ($lines as $line) {
$styledLines[] = $style . str_pad($line, $padding) . "[0m";
}
return implode("\n", $styledLines);
}