diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index b9175109c434a..017decf63b98f 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +4.3.0 +----- + + * added support for hyperlinks + 4.2.0 ----- diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatter.php b/src/Symfony/Component/Console/Formatter/OutputFormatter.php index fd3bbd12d30be..600cf76f50180 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatter.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatter.php @@ -141,7 +141,7 @@ public function formatAndWrap(string $message, int $width) { $offset = 0; $output = ''; - $tagRegex = '[a-z][a-z0-9,_=;-]*+'; + $tagRegex = '[a-z][^<>]*+'; $currentLineLength = 0; preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, PREG_OFFSET_CAPTURE); foreach ($matches[0] as $i => $match) { @@ -215,6 +215,8 @@ private function createStyleFromString(string $string) $style->setForeground($match[1]); } elseif ('bg' == $match[0]) { $style->setBackground($match[1]); + } elseif ('href' === $match[0]) { + $style->setHref($match[1]); } elseif ('options' === $match[0]) { preg_match_all('([^,;]+)', $match[1], $options); $options = array_shift($options); diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php index 906021f6f94ab..445de6a200b7e 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php @@ -52,6 +52,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface private $foreground; private $background; + private $href; private $options = array(); /** @@ -118,6 +119,11 @@ public function setBackground($color = null) $this->background = static::$availableBackgroundColors[$color]; } + public function setHref(string $url): void + { + $this->href = $url; + } + /** * Sets some specific style option. * @@ -187,11 +193,14 @@ public function apply($text) $setCodes[] = $this->background['set']; $unsetCodes[] = $this->background['unset']; } - if (\count($this->options)) { - foreach ($this->options as $option) { - $setCodes[] = $option['set']; - $unsetCodes[] = $option['unset']; - } + + foreach ($this->options as $option) { + $setCodes[] = $option['set']; + $unsetCodes[] = $option['unset']; + } + + if (null !== $this->href) { + $text = "\033]8;;$this->href\033\\$text\033]8;;\033\\"; } if (0 === \count($setCodes)) { diff --git a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php index b51668cfa7e20..2639b94043c97 100644 --- a/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php +++ b/src/Symfony/Component/Console/Tests/Formatter/OutputFormatterTest.php @@ -228,7 +228,7 @@ public function testFormatToStringObject() ); } - public function testNotDecoratedFormatter() + public function testFormatterHasStyles() { $formatter = new OutputFormatter(false); @@ -236,39 +236,26 @@ public function testNotDecoratedFormatter() $this->assertTrue($formatter->hasStyle('info')); $this->assertTrue($formatter->hasStyle('comment')); $this->assertTrue($formatter->hasStyle('question')); + } - $this->assertEquals( - 'some error', $formatter->format('some error') - ); - $this->assertEquals( - 'some info', $formatter->format('some info') - ); - $this->assertEquals( - 'some comment', $formatter->format('some comment') - ); - $this->assertEquals( - 'some question', $formatter->format('some question') - ); - $this->assertEquals( - 'some text with inline style', $formatter->format('some text with inline style') - ); - - $formatter->setDecorated(true); + /** + * @dataProvider provideDecoratedAndNonDecoratedOutput + */ + public function testNotDecoratedFormatter(string $input, string $expectedNonDecoratedOutput, string $expectedDecoratedOutput) + { + $this->assertEquals($expectedDecoratedOutput, (new OutputFormatter(true))->format($input)); + $this->assertEquals($expectedNonDecoratedOutput, (new OutputFormatter(false))->format($input)); + } - $this->assertEquals( - "\033[37;41msome error\033[39;49m", $formatter->format('some error') - ); - $this->assertEquals( - "\033[32msome info\033[39m", $formatter->format('some info') - ); - $this->assertEquals( - "\033[33msome comment\033[39m", $formatter->format('some comment') - ); - $this->assertEquals( - "\033[30;46msome question\033[39;49m", $formatter->format('some question') - ); - $this->assertEquals( - "\033[31msome text with inline style\033[39m", $formatter->format('some text with inline style') + public function provideDecoratedAndNonDecoratedOutput() + { + return array( + array('some error', 'some error', "\033[37;41msome error\033[39;49m"), + array('some info', 'some info', "\033[32msome info\033[39m"), + array('some comment', 'some comment', "\033[33msome comment\033[39m"), + array('some question', 'some question', "\033[30;46msome question\033[39;49m"), + array('some text with inline style', 'some text with inline style', "\033[31msome text with inline style\033[39m"), + array('some URL', 'some URL', "\033]8;;idea://open/?file=/path/somefile.php&line=12\033\\some URL\033]8;;\033\\"), ); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy