PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 1.25.1
Independent Analytics – WordPress Analytics Plugin v1.25.1
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / symfony / console / Terminal.php
independent-analytics / vendor / symfony / console Last commit date
Attribute 3 years ago CI 3 years ago Command 3 years ago CommandLoader 3 years ago Completion 3 years ago DependencyInjection 3 years ago Descriptor 3 years ago Event 3 years ago EventListener 3 years ago Exception 3 years ago Formatter 3 years ago Helper 3 years ago Input 3 years ago Logger 3 years ago Output 3 years ago Question 3 years ago Resources 3 years ago SignalRegistry 3 years ago Style 3 years ago Tester 3 years ago Application.php 3 years ago Color.php 3 years ago ConsoleEvents.php 3 years ago Cursor.php 3 years ago SingleCommandApplication.php 3 years ago Terminal.php 3 years ago
Terminal.php
151 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace IAWP_SCOPED\Symfony\Component\Console;
12
13 class Terminal
14 {
15 private static $width;
16 private static $height;
17 private static $stty;
18 /**
19 * Gets the terminal width.
20 *
21 * @return int
22 */
23 public function getWidth()
24 {
25 $width = \getenv('COLUMNS');
26 if (\false !== $width) {
27 return (int) \trim($width);
28 }
29 if (null === self::$width) {
30 self::initDimensions();
31 }
32 return self::$width ?: 80;
33 }
34 /**
35 * Gets the terminal height.
36 *
37 * @return int
38 */
39 public function getHeight()
40 {
41 $height = \getenv('LINES');
42 if (\false !== $height) {
43 return (int) \trim($height);
44 }
45 if (null === self::$height) {
46 self::initDimensions();
47 }
48 return self::$height ?: 50;
49 }
50 /**
51 * @internal
52 */
53 public static function hasSttyAvailable() : bool
54 {
55 if (null !== self::$stty) {
56 return self::$stty;
57 }
58 // skip check if shell_exec function is disabled
59 if (!\function_exists('shell_exec')) {
60 return \false;
61 }
62 return self::$stty = (bool) \shell_exec('stty 2> ' . ('\\' === \DIRECTORY_SEPARATOR ? 'NUL' : '/dev/null'));
63 }
64 private static function initDimensions()
65 {
66 if ('\\' === \DIRECTORY_SEPARATOR) {
67 $ansicon = \getenv('ANSICON');
68 if (\false !== $ansicon && \preg_match('/^(\\d+)x(\\d+)(?: \\((\\d+)x(\\d+)\\))?$/', \trim($ansicon), $matches)) {
69 // extract [w, H] from "wxh (WxH)"
70 // or [w, h] from "wxh"
71 self::$width = (int) $matches[1];
72 self::$height = isset($matches[4]) ? (int) $matches[4] : (int) $matches[2];
73 } elseif (!self::hasVt100Support() && self::hasSttyAvailable()) {
74 // only use stty on Windows if the terminal does not support vt100 (e.g. Windows 7 + git-bash)
75 // testing for stty in a Windows 10 vt100-enabled console will implicitly disable vt100 support on STDOUT
76 self::initDimensionsUsingStty();
77 } elseif (null !== ($dimensions = self::getConsoleMode())) {
78 // extract [w, h] from "wxh"
79 self::$width = (int) $dimensions[0];
80 self::$height = (int) $dimensions[1];
81 }
82 } else {
83 self::initDimensionsUsingStty();
84 }
85 }
86 /**
87 * Returns whether STDOUT has vt100 support (some Windows 10+ configurations).
88 */
89 private static function hasVt100Support() : bool
90 {
91 return \function_exists('sapi_windows_vt100_support') && \sapi_windows_vt100_support(\fopen('php://stdout', 'w'));
92 }
93 /**
94 * Initializes dimensions using the output of an stty columns line.
95 */
96 private static function initDimensionsUsingStty()
97 {
98 if ($sttyString = self::getSttyColumns()) {
99 if (\preg_match('/rows.(\\d+);.columns.(\\d+);/i', $sttyString, $matches)) {
100 // extract [w, h] from "rows h; columns w;"
101 self::$width = (int) $matches[2];
102 self::$height = (int) $matches[1];
103 } elseif (\preg_match('/;.(\\d+).rows;.(\\d+).columns/i', $sttyString, $matches)) {
104 // extract [w, h] from "; h rows; w columns"
105 self::$width = (int) $matches[2];
106 self::$height = (int) $matches[1];
107 }
108 }
109 }
110 /**
111 * Runs and parses mode CON if it's available, suppressing any error output.
112 *
113 * @return int[]|null An array composed of the width and the height or null if it could not be parsed
114 */
115 private static function getConsoleMode() : ?array
116 {
117 $info = self::readFromProcess('mode CON');
118 if (null === $info || !\preg_match('/--------+\\r?\\n.+?(\\d+)\\r?\\n.+?(\\d+)\\r?\\n/', $info, $matches)) {
119 return null;
120 }
121 return [(int) $matches[2], (int) $matches[1]];
122 }
123 /**
124 * Runs and parses stty -a if it's available, suppressing any error output.
125 */
126 private static function getSttyColumns() : ?string
127 {
128 return self::readFromProcess('stty -a | grep columns');
129 }
130 private static function readFromProcess(string $command) : ?string
131 {
132 if (!\function_exists('proc_open')) {
133 return null;
134 }
135 $descriptorspec = [1 => ['pipe', 'w'], 2 => ['pipe', 'w']];
136 $cp = \function_exists('sapi_windows_cp_set') ? \sapi_windows_cp_get() : 0;
137 $process = \proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => \true]);
138 if (!\is_resource($process)) {
139 return null;
140 }
141 $info = \stream_get_contents($pipes[1]);
142 \fclose($pipes[1]);
143 \fclose($pipes[2]);
144 \proc_close($process);
145 if ($cp) {
146 \sapi_windows_cp_set($cp);
147 }
148 return $info;
149 }
150 }
151