NullOutputFormatter.php
1 year ago
NullOutputFormatterStyle.php
2 years ago
OutputFormatter.php
1 year ago
OutputFormatterInterface.php
2 years ago
OutputFormatterStyle.php
1 year ago
OutputFormatterStyleInterface.php
2 years ago
OutputFormatterStyleStack.php
1 year ago
WrappableOutputFormatterInterface.php
2 years ago
OutputFormatterStyle.php
95 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace Matomo\Dependencies\Symfony\Component\Console\Formatter; |
| 12 | |
| 13 | use Matomo\Dependencies\Symfony\Component\Console\Color; |
| 14 | /** |
| 15 | * Formatter style class for defining styles. |
| 16 | * |
| 17 | * @author Konstantin Kudryashov <ever.zet@gmail.com> |
| 18 | */ |
| 19 | class OutputFormatterStyle implements OutputFormatterStyleInterface |
| 20 | { |
| 21 | private $color; |
| 22 | private $foreground; |
| 23 | private $background; |
| 24 | private $options; |
| 25 | private $href; |
| 26 | private $handlesHrefGracefully; |
| 27 | /** |
| 28 | * Initializes output formatter style. |
| 29 | * |
| 30 | * @param string|null $foreground The style foreground color name |
| 31 | * @param string|null $background The style background color name |
| 32 | */ |
| 33 | public function __construct(?string $foreground = null, ?string $background = null, array $options = []) |
| 34 | { |
| 35 | $this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options); |
| 36 | } |
| 37 | /** |
| 38 | * {@inheritdoc} |
| 39 | */ |
| 40 | public function setForeground(?string $color = null) |
| 41 | { |
| 42 | $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); |
| 43 | } |
| 44 | /** |
| 45 | * {@inheritdoc} |
| 46 | */ |
| 47 | public function setBackground(?string $color = null) |
| 48 | { |
| 49 | $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); |
| 50 | } |
| 51 | public function setHref(string $url) : void |
| 52 | { |
| 53 | $this->href = $url; |
| 54 | } |
| 55 | /** |
| 56 | * {@inheritdoc} |
| 57 | */ |
| 58 | public function setOption(string $option) |
| 59 | { |
| 60 | $this->options[] = $option; |
| 61 | $this->color = new Color($this->foreground, $this->background, $this->options); |
| 62 | } |
| 63 | /** |
| 64 | * {@inheritdoc} |
| 65 | */ |
| 66 | public function unsetOption(string $option) |
| 67 | { |
| 68 | $pos = array_search($option, $this->options); |
| 69 | if (\false !== $pos) { |
| 70 | unset($this->options[$pos]); |
| 71 | } |
| 72 | $this->color = new Color($this->foreground, $this->background, $this->options); |
| 73 | } |
| 74 | /** |
| 75 | * {@inheritdoc} |
| 76 | */ |
| 77 | public function setOptions(array $options) |
| 78 | { |
| 79 | $this->color = new Color($this->foreground, $this->background, $this->options = $options); |
| 80 | } |
| 81 | /** |
| 82 | * {@inheritdoc} |
| 83 | */ |
| 84 | public function apply(string $text) |
| 85 | { |
| 86 | if (null === $this->handlesHrefGracefully) { |
| 87 | $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100) && !isset($_SERVER['IDEA_INITIAL_DIRECTORY']); |
| 88 | } |
| 89 | if (null !== $this->href && $this->handlesHrefGracefully) { |
| 90 | $text = "\x1b]8;;{$this->href}\x1b\\{$text}\x1b]8;;\x1b\\"; |
| 91 | } |
| 92 | return $this->color->apply($text); |
| 93 | } |
| 94 | } |
| 95 |