12 namespace Symfony\Component\Console\Formatter;
24 'black' => array(
'set' => 30,
'unset' => 39),
25 'red' => array(
'set' => 31,
'unset' => 39),
26 'green' => array(
'set' => 32,
'unset' => 39),
27 'yellow' => array(
'set' => 33,
'unset' => 39),
28 'blue' => array(
'set' => 34,
'unset' => 39),
29 'magenta' => array(
'set' => 35,
'unset' => 39),
30 'cyan' => array(
'set' => 36,
'unset' => 39),
31 'white' => array(
'set' => 37,
'unset' => 39),
32 'default' => array(
'set' => 39,
'unset' => 39),
35 'black' => array(
'set' => 40,
'unset' => 49),
36 'red' => array(
'set' => 41,
'unset' => 49),
37 'green' => array(
'set' => 42,
'unset' => 49),
38 'yellow' => array(
'set' => 43,
'unset' => 49),
39 'blue' => array(
'set' => 44,
'unset' => 49),
40 'magenta' => array(
'set' => 45,
'unset' => 49),
41 'cyan' => array(
'set' => 46,
'unset' => 49),
42 'white' => array(
'set' => 47,
'unset' => 49),
43 'default' => array(
'set' => 49,
'unset' => 49),
46 'bold' => array(
'set' => 1,
'unset' => 22),
47 'underscore' => array(
'set' => 4,
'unset' => 24),
48 'blink' => array(
'set' => 5,
'unset' => 25),
49 'reverse' => array(
'set' => 7,
'unset' => 27),
50 'conceal' => array(
'set' => 8,
'unset' => 28),
90 if (null === $color) {
91 $this->foreground = null;
96 if (!isset(static::$availableForegroundColors[$color])) {
97 throw new \InvalidArgumentException(sprintf(
98 'Invalid foreground color specified: "%s". Expected one of (%s)',
100 implode(
', ', array_keys(static::$availableForegroundColors))
104 $this->foreground = static::$availableForegroundColors[$color];
118 if (null === $color) {
119 $this->background = null;
124 if (!isset(static::$availableBackgroundColors[$color])) {
125 throw new \InvalidArgumentException(sprintf(
126 'Invalid background color specified: "%s". Expected one of (%s)',
128 implode(
', ', array_keys(static::$availableBackgroundColors))
132 $this->background = static::$availableBackgroundColors[$color];
146 if (!isset(static::$availableOptions[$option])) {
147 throw new \InvalidArgumentException(sprintf(
148 'Invalid option specified: "%s". Expected one of (%s)',
150 implode(
', ', array_keys(static::$availableOptions))
154 if (!in_array(static::$availableOptions[$option], $this->options)) {
155 $this->options[] = static::$availableOptions[$option];
168 if (!isset(static::$availableOptions[$option])) {
169 throw new \InvalidArgumentException(sprintf(
170 'Invalid option specified: "%s". Expected one of (%s)',
172 implode(
', ', array_keys(static::$availableOptions))
176 $pos = array_search(static::$availableOptions[$option], $this->options);
177 if (
false !== $pos) {
178 unset($this->options[$pos]);
189 $this->options = array();
191 foreach ($options as $option) {
206 $unsetCodes = array();
208 if (null !== $this->foreground) {
209 $setCodes[] = $this->foreground[
'set'];
210 $unsetCodes[] = $this->foreground[
'unset'];
212 if (null !== $this->background) {
213 $setCodes[] = $this->background[
'set'];
214 $unsetCodes[] = $this->background[
'unset'];
216 if (count($this->options)) {
217 foreach ($this->options as $option) {
218 $setCodes[] = $option[
'set'];
219 $unsetCodes[] = $option[
'unset'];
223 if (0 === count($setCodes)) {
227 return sprintf(
"\033[%sm%s\033[%sm", implode(
';', $setCodes), $text, implode(
';', $unsetCodes));