1 | <?php namespace nyx\console\output\formatting; |
||
17 | class Style implements interfaces\Style |
||
18 | { |
||
19 | /** |
||
20 | * @var array The available foreground colors. The actual color representations may vary from the names as it |
||
21 | * depends on the terminal used to display them. |
||
22 | */ |
||
23 | protected static $foregrounds = [ |
||
24 | 'black' => 30, |
||
25 | 'red' => 31, |
||
26 | 'green' => 32, |
||
27 | 'yellow' => 33, |
||
28 | 'blue' => 34, |
||
29 | 'magenta' => 35, |
||
30 | 'cyan' => 36, |
||
31 | 'white' => 37, |
||
32 | 'default' => 39 |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * @var array The available background colors. |
||
37 | */ |
||
38 | protected static $backgrounds = [ |
||
39 | 'black' => 40, |
||
40 | 'red' => 41, |
||
41 | 'green' => 42, |
||
42 | 'yellow' => 43, |
||
43 | 'blue' => 44, |
||
44 | 'magenta' => 45, |
||
45 | 'cyan' => 46, |
||
46 | 'white' => 47, |
||
47 | 'default' => 49 |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * @var array The available additional emphasis options (Note: support for those depends on the type |
||
52 | * of the terminal used to display the application). |
||
53 | */ |
||
54 | protected static $options = [ |
||
55 | 'bold' => [1, 22], |
||
56 | 'italic' => [3, 23], |
||
57 | 'underscore' => [4, 24], |
||
58 | 'blink' => [5, 25], |
||
59 | 'reverse' => [7, 27], |
||
60 | 'conceal' => [8, 28] |
||
61 | ]; |
||
62 | |||
63 | /** |
||
64 | * @var int The currently set foreground color of this Style. |
||
65 | */ |
||
66 | private $foreground; |
||
67 | |||
68 | /** |
||
69 | * @var int The currently set background color of this Style. |
||
70 | */ |
||
71 | private $background; |
||
72 | |||
73 | /** |
||
74 | * @var array The currently set additional emphasis options of this Style. |
||
75 | */ |
||
76 | private $emphasis = []; |
||
77 | |||
78 | /** |
||
79 | * Factory which attempts to create a new Style based on an inline styling syntax. |
||
80 | * |
||
81 | * @param string $string The string to parse. |
||
82 | * @param array $properties An array containing at most 2 keys: 'foreground' and 'background', |
||
83 | * denoting the names those properties will be sought for to in the string. |
||
84 | * Defaults to: ['foreground' => 'color', 'background' => 'bg']. |
||
85 | * @return Style The Style that was created based on it. |
||
86 | */ |
||
87 | public static function fromString(string $string, array $properties = null) : ?Style |
||
113 | |||
114 | /** |
||
115 | * Constructs a new Output Formatting Style. |
||
116 | * |
||
117 | * @param string $foreground The foreground color to be set. |
||
118 | * @param string $background The background color to be set. |
||
119 | * @param array $options An array of additional options emphasis to be set. |
||
120 | */ |
||
121 | public function __construct(?string $foreground, string $background = null, array $options = null) |
||
135 | |||
136 | /** |
||
137 | * {@inheritDoc} |
||
138 | */ |
||
139 | public function setForeground(?string $color) : interfaces\Style |
||
143 | |||
144 | /** |
||
145 | * {@inheritdoc} |
||
146 | */ |
||
147 | public function setBackground(?string $color) : interfaces\Style |
||
151 | |||
152 | /** |
||
153 | * {@inheritdoc} |
||
154 | */ |
||
155 | public function setEmphasis(array $options) : interfaces\Style |
||
170 | |||
171 | /** |
||
172 | * {@inheritdoc} |
||
173 | */ |
||
174 | public function apply(string $text) : string |
||
201 | |||
202 | /** |
||
203 | * Sets a specific type of color on this Style. |
||
204 | * |
||
205 | * @param string $type The type of the color to set. |
||
206 | * @param string $color The color to set. |
||
207 | * @return $this |
||
208 | */ |
||
209 | protected function setColor(string $type, ?string $color) : interfaces\Style |
||
219 | } |
||
220 |