1 | <?php |
||
16 | class ANSI implements CursorInterface |
||
17 | { |
||
18 | const ESCAPE = "\e"; |
||
19 | |||
20 | const CODE_MOVE_POSITION = '[%d;%dH'; // line, column |
||
21 | const CODE_MOVE_POSITION_FORCE = '[%d;%df'; // line, column |
||
22 | const CODE_MOVE_UP_LINES = '[%dA'; // lines |
||
23 | const CODE_MOVE_DOWN_LINES = '[%dB'; // lines |
||
24 | const CODE_MOVE_FORWARD = '[%dC'; // columns |
||
25 | const CODE_MOVE_BACKWARDS = '[%dD'; // columns |
||
26 | |||
27 | const CODE_ERASE_TO_END_OF_LINE = '[K'; |
||
28 | const CODE_ERASE_TO_START_OF_LINE = '[1K'; |
||
29 | const CODE_ERASE_LINE = '[2K'; |
||
30 | const CODE_ERASE_DOWN = '[J'; |
||
31 | const CODE_ERASE_UP = '[1J'; |
||
32 | const CODE_ERASE_SCREEN = '[2J'; |
||
33 | |||
34 | const REGEX_ANSI = "/(?:\r|\e(?:\\[[0-9;]*[HfABCDKJcnRsurgim]|\\[=\\[[0-9]{1,2}[hl]|[c\\(\\)78DMH]))/"; |
||
35 | const REGEX_FORMAT = "/\e\\[((?:[0-9][0-9;]*|))m/"; |
||
36 | const REGEX_STYLE_ITEM = '/\b(?:(?:([34]8);(?:2;\d{1,3};\d{1,3};\d{1,3}|5;\d{1,3}))|(\d+)(?<!38|48))\b/'; |
||
37 | const REGEX_FIRST_KEY = '/^(\d+)/'; |
||
38 | |||
39 | const STYLE_RESET = '0'; |
||
40 | |||
41 | /** @var array */ |
||
42 | protected $filter = []; |
||
43 | /** @var array */ |
||
44 | private $formats; |
||
45 | |||
46 | public function __construct() |
||
112 | |||
113 | /** |
||
114 | * @param int $line |
||
115 | * @param int $column |
||
116 | * |
||
117 | * @return string |
||
118 | */ |
||
119 | public function move($line, $column) |
||
123 | |||
124 | /** |
||
125 | * @param int $lines |
||
126 | * |
||
127 | * @return string |
||
128 | */ |
||
129 | public function moveUp($lines) |
||
133 | |||
134 | /** |
||
135 | * @param int $lines |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | public function moveDown($lines) |
||
143 | |||
144 | /** |
||
145 | * @param int $columns |
||
146 | * |
||
147 | * @return string |
||
148 | */ |
||
149 | public function moveLeft($columns) |
||
153 | |||
154 | /** |
||
155 | * @param int $columns |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | public function moveRight($columns) |
||
163 | |||
164 | /** |
||
165 | * @return string |
||
166 | */ |
||
167 | public function eraseToEnd() |
||
171 | |||
172 | /** |
||
173 | * @return string |
||
174 | */ |
||
175 | public function eraseToStart() |
||
179 | |||
180 | /** |
||
181 | * @return string |
||
182 | */ |
||
183 | public function eraseDown() |
||
187 | |||
188 | /** |
||
189 | * @return string |
||
190 | */ |
||
191 | public function eraseUp() |
||
195 | |||
196 | /** |
||
197 | * @return string |
||
198 | */ |
||
199 | public function eraseScreen() |
||
203 | |||
204 | /** |
||
205 | * Filter takes a string with Cursor movements and filters them out |
||
206 | * |
||
207 | * @param string $string |
||
208 | * @param string $replacement Optional character or string to replace specific codes with |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | public function filter($string, $replacement = '') |
||
221 | |||
222 | /** |
||
223 | * Gets the styling that would be active at the end of this string |
||
224 | * |
||
225 | * @param string $string |
||
226 | * |
||
227 | * @return string |
||
228 | */ |
||
229 | public function getCurrentFormatting($string) |
||
261 | |||
262 | /** |
||
263 | * Get all the styles in order that should be applied at the end |
||
264 | * |
||
265 | * @param string $string |
||
266 | * |
||
267 | * @return \Generator|void Iterator of numbers representing styles |
||
268 | */ |
||
269 | private function getStyleStack($string) |
||
284 | } |
||
285 |