[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <[email protected]> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\Console\Formatter; 13 14 use Symfony\Component\Console\Color; 15 16 /** 17 * Formatter style class for defining styles. 18 * 19 * @author Konstantin Kudryashov <[email protected]> 20 */ 21 class OutputFormatterStyle implements OutputFormatterStyleInterface 22 { 23 private $color; 24 private $foreground; 25 private $background; 26 private $options; 27 private $href; 28 private $handlesHrefGracefully; 29 30 /** 31 * Initializes output formatter style. 32 * 33 * @param string|null $foreground The style foreground color name 34 * @param string|null $background The style background color name 35 */ 36 public function __construct(string $foreground = null, string $background = null, array $options = []) 37 { 38 $this->color = new Color($this->foreground = $foreground ?: '', $this->background = $background ?: '', $this->options = $options); 39 } 40 41 /** 42 * {@inheritdoc} 43 */ 44 public function setForeground(string $color = null) 45 { 46 $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); 47 } 48 49 /** 50 * {@inheritdoc} 51 */ 52 public function setBackground(string $color = null) 53 { 54 $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); 55 } 56 57 public function setHref(string $url): void 58 { 59 $this->href = $url; 60 } 61 62 /** 63 * {@inheritdoc} 64 */ 65 public function setOption(string $option) 66 { 67 $this->options[] = $option; 68 $this->color = new Color($this->foreground, $this->background, $this->options); 69 } 70 71 /** 72 * {@inheritdoc} 73 */ 74 public function unsetOption(string $option) 75 { 76 $pos = array_search($option, $this->options); 77 if (false !== $pos) { 78 unset($this->options[$pos]); 79 } 80 81 $this->color = new Color($this->foreground, $this->background, $this->options); 82 } 83 84 /** 85 * {@inheritdoc} 86 */ 87 public function setOptions(array $options) 88 { 89 $this->color = new Color($this->foreground, $this->background, $this->options = $options); 90 } 91 92 /** 93 * {@inheritdoc} 94 */ 95 public function apply(string $text) 96 { 97 if (null === $this->handlesHrefGracefully) { 98 $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') 99 && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100); 100 } 101 102 if (null !== $this->href && $this->handlesHrefGracefully) { 103 $text = "\033]8;;$this->href\033\\$text\033]8;;\033\\"; 104 } 105 106 return $this->color->apply($text); 107 } 108 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |