12 namespace Symfony\Component\Console\Formatter;
36 return preg_replace(
'/([^\\\\]?)</',
'$1\\<', $text);
56 foreach (
$styles as $name => $style) {
97 $this->styles[strtolower($name)] = $style;
111 return isset($this->styles[strtolower($name)]);
128 throw new \InvalidArgumentException(sprintf(
'Undefined style: %s', $name));
131 return $this->styles[strtolower($name)];
145 $message = (string) $message;
148 $tagRegex =
'[a-z][a-z0-9_=;-]*';
149 preg_match_all(
"#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, PREG_OFFSET_CAPTURE);
150 foreach ($matches[0] as $i => $match) {
154 if (0 != $pos &&
'\\' == $message[$pos - 1]) {
160 $offset = $pos + strlen($text);
163 if ($open =
'/' != $text[1]) {
164 $tag = $matches[1][$i][0];
166 $tag = isset($matches[3][$i][0]) ? $matches[3][$i][0] :
'';
169 if (!$open && !$tag) {
171 $this->styleStack->pop();
175 $this->styleStack->push($style);
177 $this->styleStack->pop($style);
183 return str_replace(
'\\<',
'<', $output);
203 if (isset($this->styles[$string])) {
204 return $this->styles[$string];
207 if (!preg_match_all(
'/([^=]+)=([^;]+)(;|$)/', strtolower($string), $matches, PREG_SET_ORDER)) {
212 foreach ($matches as $match) {
215 if (
'fg' == $match[0]) {
216 $style->setForeground($match[1]);
217 }
elseif (
'bg' == $match[0]) {
218 $style->setBackground($match[1]);
221 $style->setOption($match[1]);
222 }
catch (\InvalidArgumentException $e) {
240 return $this->
isDecorated() && strlen($text) > 0 ? $this->styleStack->getCurrent()->apply($text) : $text;