1 | <?php |
||
11 | class UnixTerminal implements TerminalInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var bool |
||
15 | */ |
||
16 | private $isTTY; |
||
17 | |||
18 | /** |
||
19 | * @var bool |
||
20 | */ |
||
21 | private $isCanonical = false; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | private $width; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | private $height; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $details; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $originalConfiguration; |
||
42 | |||
43 | /** |
||
44 | * Initialise the terminal from resource |
||
45 | * |
||
46 | */ |
||
47 | public function __construct() |
||
51 | |||
52 | /** |
||
53 | * Get the available width of the terminal |
||
54 | * |
||
55 | * @return int |
||
56 | */ |
||
57 | public function getWidth() |
||
61 | |||
62 | /** |
||
63 | * Get the available height of the terminal |
||
64 | * |
||
65 | * @return int |
||
66 | */ |
||
67 | public function getHeight() |
||
71 | |||
72 | /** |
||
73 | * Get terminal details |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getDetails() |
||
87 | |||
88 | /** |
||
89 | * Get the original terminal configuration / mode |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | private function getOriginalConfiguration() |
||
97 | |||
98 | /** |
||
99 | * Toggle canonical mode on TTY |
||
100 | * |
||
101 | * @param bool $useCanonicalMode |
||
102 | */ |
||
103 | public function setCanonicalMode($useCanonicalMode = true) |
||
113 | |||
114 | /** |
||
115 | * Check if TTY is in canonical mode |
||
116 | * Assumes the terminal was never in canonical mode |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | public function isCanonical() |
||
124 | |||
125 | /** |
||
126 | * Test whether terminal is valid TTY |
||
127 | * |
||
128 | * @return bool |
||
129 | */ |
||
130 | public function isTTY() |
||
134 | |||
135 | /** |
||
136 | * Test whether terminal supports colour output |
||
137 | * |
||
138 | * @return bool |
||
139 | * |
||
140 | * @link https://github.com/symfony/Console/blob/master/Output/StreamOutput.php#L95-L102 |
||
141 | */ |
||
142 | public function supportsColour() |
||
150 | |||
151 | /** |
||
152 | * @return string |
||
153 | */ |
||
154 | public function getKeyedInput() |
||
179 | |||
180 | /** |
||
181 | * Clear the terminal window |
||
182 | */ |
||
183 | public function clear() |
||
187 | |||
188 | /** |
||
189 | * Enable cursor |
||
190 | */ |
||
191 | public function enableCursor() |
||
195 | |||
196 | /** |
||
197 | * Disable cursor |
||
198 | */ |
||
199 | public function disableCursor() |
||
203 | |||
204 | /** |
||
205 | * Move the cursor to the top left of the window |
||
206 | * |
||
207 | * @return void |
||
208 | */ |
||
209 | public function moveCursorToTop() |
||
213 | |||
214 | /** |
||
215 | * Move the cursor to the start of a specific row |
||
216 | * |
||
217 | * @param int $rowNumber |
||
218 | */ |
||
219 | public function moveCursorToRow($rowNumber) |
||
223 | |||
224 | /** |
||
225 | * Move the cursor to the start of a specific column |
||
226 | * |
||
227 | * @param int $column |
||
228 | */ |
||
229 | public function moveCursorToColumn($column) |
||
233 | |||
234 | /** |
||
235 | * Clear the current cursors line |
||
236 | * |
||
237 | * @return void |
||
238 | */ |
||
239 | public function clearLine() |
||
243 | |||
244 | /** |
||
245 | * Clean the whole console without jumping the window |
||
246 | */ |
||
247 | public function clean() |
||
254 | } |
||
255 |