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 CODE_HIDE_CURSOR = '[?25l'; |
||
35 | const CODE_SHOW_CURSOR = '[?25h'; |
||
36 | |||
37 | const REGEX_ANSI = "/(?:\r|\e(?:\\[[0-9;]*[HfABCDKJcnRsurgim]|\\[(?:=|\?)\\[[0-9]{1,2}[hl]|[c\\(\\)78DMH]))/"; |
||
38 | const REGEX_FORMAT = "/\e\\[((?:[0-9][0-9;]*|))m/"; |
||
39 | 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/'; |
||
40 | const REGEX_FIRST_KEY = '/^(\d+)/'; |
||
41 | |||
42 | const STYLE_RESET = '0'; |
||
43 | |||
44 | /** @var array */ |
||
45 | protected $filter = []; |
||
46 | /** @var array */ |
||
47 | private $formats; |
||
48 | |||
49 | public function __construct() |
||
115 | |||
116 | /** |
||
117 | * @param int $line |
||
118 | * @param int $column |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | public function move($line, $column) |
||
126 | |||
127 | /** |
||
128 | * @param int $lines |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | public function moveUp($lines) |
||
136 | |||
137 | /** |
||
138 | * @param int $lines |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | public function moveDown($lines) |
||
146 | |||
147 | /** |
||
148 | * @param int $columns |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | public function moveLeft($columns) |
||
156 | |||
157 | /** |
||
158 | * @param int $columns |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | public function moveRight($columns) |
||
166 | |||
167 | /** |
||
168 | * @return string |
||
169 | */ |
||
170 | public function eraseToEnd() |
||
174 | |||
175 | /** |
||
176 | * @return string |
||
177 | */ |
||
178 | public function eraseToStart() |
||
182 | |||
183 | /** |
||
184 | * @return string |
||
185 | */ |
||
186 | public function eraseDown() |
||
190 | |||
191 | /** |
||
192 | * @return string |
||
193 | */ |
||
194 | public function eraseUp() |
||
198 | |||
199 | /** |
||
200 | * @return string |
||
201 | */ |
||
202 | public function eraseScreen() |
||
206 | |||
207 | /** |
||
208 | * @return string |
||
209 | */ |
||
210 | public function hideCursor() |
||
214 | |||
215 | /** |
||
216 | * @return string |
||
217 | */ |
||
218 | public function showCursor() |
||
222 | |||
223 | /** |
||
224 | * Filter takes a string with Cursor movements and filters them out |
||
225 | * |
||
226 | * @param string $string |
||
227 | * @param string $replacement Optional character or string to replace specific codes with |
||
228 | * |
||
229 | * @return string |
||
230 | */ |
||
231 | public function filter($string, $replacement = '') |
||
240 | |||
241 | /** |
||
242 | * Gets the styling that would be active at the end of this string |
||
243 | * |
||
244 | * @param string $string |
||
245 | * |
||
246 | * @return string |
||
247 | */ |
||
248 | public function getCurrentFormatting($string) |
||
280 | |||
281 | /** |
||
282 | * Get all the styles in order that should be applied at the end |
||
283 | * |
||
284 | * @param string $string |
||
285 | * |
||
286 | * @return \Generator|void Iterator of numbers representing styles |
||
287 | */ |
||
288 | private function getStyleStack($string) |
||
303 | } |
||
304 |