|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Graze\BufferedConsole\Terminal; |
|
4
|
|
|
|
|
5
|
|
|
class ANSI implements CursorInterface |
|
6
|
|
|
{ |
|
7
|
|
|
const ESCAPE = "\e"; |
|
8
|
|
|
|
|
9
|
|
|
const CODE_MOVE_POSITION = '[%d;%dH'; // line, column |
|
10
|
|
|
const CODE_MOVE_UP_LINES = '[%dA'; // lines |
|
11
|
|
|
const CODE_MOVE_DOWN_LINES = '[%dB'; // lines |
|
12
|
|
|
const CODE_MOVE_FORWARD = '[%dC'; // columns |
|
13
|
|
|
const CODE_MOVE_BACKWARDS = '[%dD'; // columns |
|
14
|
|
|
|
|
15
|
|
|
const CODE_ERASE_TO_END_OF_LINE = '[K'; |
|
16
|
|
|
const CODE_ERASE_TO_START_OF_LINE = '[1K'; |
|
17
|
|
|
const CODE_ERASE_LINE = '[2K'; |
|
18
|
|
|
const CODE_ERASE_DOWN = '[J'; |
|
19
|
|
|
const CODE_ERASE_UP = '[1J'; |
|
20
|
|
|
const CODE_ERASE_SCREEN = '[2J'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param int $line |
|
24
|
|
|
* @param int $column |
|
25
|
|
|
* |
|
26
|
|
|
* @return string |
|
27
|
|
|
*/ |
|
28
|
|
|
public function move($line, $column) |
|
29
|
|
|
{ |
|
30
|
|
|
return static::ESCAPE . sprintf(static::CODE_MOVE_POSITION, $line, $column); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param int $lines |
|
35
|
|
|
* |
|
36
|
|
|
* @return string |
|
37
|
|
|
*/ |
|
38
|
|
|
public function moveUp($lines) |
|
39
|
|
|
{ |
|
40
|
|
|
return static::ESCAPE . sprintf(static::CODE_MOVE_UP_LINES, $lines); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param int $lines |
|
45
|
|
|
* |
|
46
|
|
|
* @return string |
|
47
|
|
|
*/ |
|
48
|
|
|
public function moveDown($lines) |
|
49
|
|
|
{ |
|
50
|
|
|
return static::ESCAPE . sprintf(static::CODE_MOVE_DOWN_LINES, $lines); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param int $columns |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function moveLeft($columns) |
|
59
|
|
|
{ |
|
60
|
|
|
return static::ESCAPE . sprintf(static::CODE_MOVE_BACKWARDS, $columns); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param int $columns |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
public function moveRight($columns) |
|
69
|
|
|
{ |
|
70
|
|
|
return static::ESCAPE . sprintf(static::CODE_MOVE_FORWARD, $columns); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function eraseToEnd() |
|
77
|
|
|
{ |
|
78
|
|
|
return static::ESCAPE . static::CODE_ERASE_TO_END_OF_LINE; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
public function eraseToStart() |
|
85
|
|
|
{ |
|
86
|
|
|
return static::ESCAPE . static::CODE_ERASE_TO_START_OF_LINE; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
|
|
public function eraseDown() |
|
93
|
|
|
{ |
|
94
|
|
|
return static::ESCAPE . static::CODE_ERASE_DOWN; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
|
|
public function eraseUp() |
|
101
|
|
|
{ |
|
102
|
|
|
return static::ESCAPE . static::CODE_ERASE_UP; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
|
|
public function eraseScreen() |
|
109
|
|
|
{ |
|
110
|
|
|
return static::ESCAPE . static::CODE_ERASE_SCREEN; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|