1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace League\CLImate\Util\System; |
4
|
|
|
|
5
|
|
|
class Windows extends System |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Get the width of the terminal |
9
|
|
|
* |
10
|
|
|
* @return integer|null |
11
|
|
|
*/ |
12
|
8 |
|
public function width() |
13
|
|
|
{ |
14
|
8 |
|
return $this->getDimension('width'); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Get the height of the terminal |
19
|
|
|
* |
20
|
|
|
* @return integer|null |
21
|
|
|
*/ |
22
|
8 |
|
public function height() |
23
|
|
|
{ |
24
|
8 |
|
return $this->getDimension('height'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Get specified terminal dimension |
29
|
|
|
* |
30
|
|
|
* @param string $key |
31
|
|
|
* |
32
|
|
|
* @return integer|null |
33
|
|
|
*/ |
34
|
|
|
|
35
|
16 |
|
protected function getDimension($key) |
36
|
|
|
{ |
37
|
16 |
|
$index = array_search($key, ['height', 'width']); |
38
|
16 |
|
$dimensions = $this->getDimensions(); |
39
|
|
|
|
40
|
16 |
|
return (!empty($dimensions[$index])) ? $dimensions[$index] : null; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get information about the dimensions of the terminal |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
16 |
|
protected function getDimensions() |
49
|
|
|
{ |
50
|
16 |
|
$output = $this->exec('mode CON', true); |
51
|
|
|
|
52
|
16 |
|
if (!is_array($output)) { |
53
|
8 |
|
return []; |
54
|
|
|
} |
55
|
|
|
|
56
|
8 |
|
$output = implode("\n", $output); |
57
|
|
|
|
58
|
8 |
|
preg_match_all('/.*:\s*(\d+)/', $output, $matches); |
59
|
|
|
|
60
|
8 |
|
return (!empty($matches[1])) ? $matches[1] : []; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Check if the stream supports ansi escape characters. |
65
|
|
|
* |
66
|
|
|
* Based on https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Output/StreamOutput.php |
67
|
|
|
* |
68
|
|
|
* @return bool |
69
|
|
|
*/ |
70
|
|
|
protected function systemHasAnsiSupport() |
71
|
|
|
{ |
72
|
|
|
return (function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT)) |
73
|
|
|
|| false !== getenv('ANSICON') |
74
|
|
|
|| 'ON' === getenv('ConEmuANSI') |
75
|
|
|
|| 'Hyper' === getenv('TERM_PROGRAM') |
76
|
|
|
|| 'xterm' === getenv('TERM'); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|