src/Differ/DiffConsoleFormatter.php
public function format($diff, $lineTemplate = '%s')
    {
        $isDecorated = $this->isDecoratedOutput;

        $template = $isDecorated
            ? $this->template
            : Preg::replace('/<[^<>]+>/', '', $this->template)
        ;

        return sprintf(
            $template,
            implode(
                PHP_EOL,
                array_map(
                    static function ($line) use ($isDecorated, $lineTemplate) {
                        if ($isDecorated) {
                            $count = 0;
                            $line = Preg::replaceCallback(
                                [
                                    '/^(\+.*)/',
                                    '/^(\-.*)/',
                                    '/^(@.*)/',
                                ],
                                function ($matches) {
                                    if ('+' === $matches[0][0]) {
                                        $colour = 'green';
                                    } elseif ('-' === $matches[0][0]) {
                                        $colour = 'red';
                                    } else {
                                        $colour = 'cyan';
                                    }

                                    return sprintf('<fg=%s>%s</fg=%s>', $colour, OutputFormatter::escape($matches[0]), $colour);
                                },
                                $line,
                                1,
                                $count
                            );

                            if (0 === $count) {
                                $line = OutputFormatter::escape($line);
                            }
                        }

                        return sprintf($lineTemplate, $line);
                    },
                    Preg::split('#\R#u', $diff)
                )
            )
        );
    }
public function format($diff, $lineTemplate = '%s')
    {
        $isDecorated = $this->isDecoratedOutput;

        $template = $isDecorated
            ? $this->template
            : Preg::replace('/<[^<>]+>/', '', $this->template)
        ;

        return sprintf(
            $template,
            implode(
                PHP_EOL,
                array_map(
                    static function ($line) use ($isDecorated, $lineTemplate) {
                        if ($isDecorated) {
                            $count = 0;
                            $line = Preg::replaceCallback(
                                [
                                    '/^(\+.*)/',
                                    '/^(\-.*)/',
                                    '/^(@.*)/',
                                ],
                                function ($matches) {
                                    if ('+' === $matches[0][0]) {
                                        $colour = 'green';
                                    } elseif ('-' === $matches[0][0]) {
                                        $colour = 'red';
                                    } else {
                                        $colour = 'cyan';
                                    }

                                    return sprintf('<fg=%s>%s</fg=%s>', $colour, OutputFormatter::escape($matches[0]), $colour);
                                },
                                $line,
                                1,
                                $count
                            );

                            if (0 === $count) {
                                $line = OutputFormatter::escape($line);
                            }
                        }

                        return sprintf($lineTemplate, $line);
                    },
                    Preg::split('#\R#u', $diff)
                )
            )
        );
    }
@param string $diff
@param string $lineTemplate

@return string