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 | * Constructs a new Output Formatting Style. |
||
80 | * |
||
81 | * @param string $foreground The foreground color to be set. |
||
82 | * @param string $background The background color to be set. |
||
83 | * @param array $options An array of additional options emphasis to be set. |
||
84 | */ |
||
85 | public function __construct(?string $foreground, string $background = null, array $options = null) |
||
99 | |||
100 | /** |
||
101 | * {@inheritDoc} |
||
102 | */ |
||
103 | public function setForeground(?string $color) : interfaces\Style |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | public function setBackground(?string $color) : interfaces\Style |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | public function setEmphasis(array $options) : interfaces\Style |
||
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | public function apply(string $text) : string |
||
165 | |||
166 | /** |
||
167 | * Sets a specific type of color on this Style. |
||
168 | * |
||
169 | * @param string $type The type of the color to set. |
||
170 | * @param string $color The color to set. |
||
171 | * @return $this |
||
172 | */ |
||
173 | protected function setColor(string $type, ?string $color) : interfaces\Style |
||
183 | } |
||
184 |