1 | <?php |
||
15 | abstract class Element |
||
16 | { |
||
17 | const ANSI_ESCAPE_CODE_RESET = "\033[0m"; |
||
18 | const ANSI_ESCAPE_CODE_REGEX = '\\033\[[\d]+m'; |
||
19 | |||
20 | /** |
||
21 | * @var TextColor |
||
22 | */ |
||
23 | private $textColor; |
||
24 | |||
25 | /** |
||
26 | * @var BackgroundColor |
||
27 | */ |
||
28 | private $backgroundColor; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | private $styles; |
||
34 | |||
35 | /** |
||
36 | * @param BackgroundColor $backgroundColor |
||
37 | * |
||
38 | * @return static |
||
39 | */ |
||
40 | public function setBackgroundColor(BackgroundColor $backgroundColor) |
||
46 | |||
47 | /** |
||
48 | * @return BackgroundColor |
||
49 | */ |
||
50 | public function getBackgroundColor() |
||
54 | |||
55 | /** |
||
56 | * @param TextColor $textColor |
||
57 | * |
||
58 | * @return static |
||
59 | */ |
||
60 | public function setTextColor(TextColor $textColor) |
||
66 | |||
67 | /** |
||
68 | * @return TextColor |
||
69 | */ |
||
70 | public function getTextColor() |
||
74 | |||
75 | /** |
||
76 | * @param Style $style |
||
77 | * |
||
78 | * @return static |
||
79 | */ |
||
80 | public function addStyle(Style $style) |
||
86 | |||
87 | /** |
||
88 | * @param Style $style |
||
89 | * |
||
90 | * @return static |
||
91 | */ |
||
92 | public function removeStyle(Style $style) |
||
110 | |||
111 | /** |
||
112 | * @return Style[] |
||
113 | */ |
||
114 | public function getStyles() |
||
118 | |||
119 | /** |
||
120 | * @return string |
||
121 | */ |
||
122 | abstract public function render(); |
||
123 | |||
124 | /** |
||
125 | * Apply escape code to string and close section |
||
126 | * |
||
127 | * @param string $string |
||
128 | * @param string $escapeCharacter |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | protected function frame($string, $escapeCharacter) |
||
138 | } |
||
139 |