protected function formatOutput($output)
    {
        $tagFormats = $this->tagFormats;
        $disableAnsi = $this->disableAnsi;
        do {
            $lastOutput = $output;
            $output = preg_replace_callback('|(<([^>]+?)>(.*?)</\2>)|s', function ($matches) use ($tagFormats, $disableAnsi) {
                $format = isset($tagFormats[$matches[2]]) ? $tagFormats[$matches[2]] : '|';
                if ($disableAnsi) {
                    return $matches[3];
                } else {
                    return str_replace('|', $matches[3], $format);
                }
            }, $output);
        } while ($lastOutput !== $output);
        return $output;
    }