|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Console\Style;
|
13 | 13 |
|
| 14 | +use Symfony\Component\Console\Application; |
14 | 15 | use Symfony\Component\Console\Formatter\OutputFormatter;
|
15 | 16 | use Symfony\Component\Console\Helper\Helper;
|
16 | 17 | use Symfony\Component\Console\Helper\ProgressBar;
|
@@ -312,74 +313,9 @@ private function getProgressBar()
|
312 | 313 |
|
313 | 314 | private function getTerminalWidth()
|
314 | 315 | {
|
315 |
| - if ('\\' === DIRECTORY_SEPARATOR) { |
316 |
| - // extract [w, H] from "wxh (WxH)" |
317 |
| - if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) { |
318 |
| - return (int) $matches[1]; |
319 |
| - } |
320 |
| - // extract [w, h] from "wxh" |
321 |
| - if (preg_match('/^(\d+)x(\d+)$/', $this->getConsoleMode(), $matches)) { |
322 |
| - return (int) $matches[1]; |
323 |
| - } |
324 |
| - } |
325 |
| - |
326 |
| - if ($sttyString = $this->getSttyColumns()) { |
327 |
| - // extract [w, h] from "rows h; columns w;" |
328 |
| - if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) { |
329 |
| - return (int) $matches[2]; |
330 |
| - } |
331 |
| - // extract [w, h] from "; h rows; w columns" |
332 |
| - if (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) { |
333 |
| - return (int) $matches[2]; |
334 |
| - } |
335 |
| - } |
336 |
| - } |
| 316 | + $application = new Application(); |
| 317 | + list ($width, $height) = $application->getTerminalDimensions(); |
337 | 318 |
|
338 |
| - /** |
339 |
| - * Runs and parses stty -a if it's available, suppressing any error output. |
340 |
| - * |
341 |
| - * @return string |
342 |
| - */ |
343 |
| - private function getSttyColumns() |
344 |
| - { |
345 |
| - if (!function_exists('proc_open')) { |
346 |
| - return; |
347 |
| - } |
348 |
| - |
349 |
| - $descriptorspec = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')); |
350 |
| - $process = proc_open('stty -a | grep columns', $descriptorspec, $pipes, null, null, array('suppress_errors' => true)); |
351 |
| - if (is_resource($process)) { |
352 |
| - $info = stream_get_contents($pipes[1]); |
353 |
| - fclose($pipes[1]); |
354 |
| - fclose($pipes[2]); |
355 |
| - proc_close($process); |
356 |
| - |
357 |
| - return $info; |
358 |
| - } |
359 |
| - } |
360 |
| - |
361 |
| - /** |
362 |
| - * Runs and parses mode CON if it's available, suppressing any error output. |
363 |
| - * |
364 |
| - * @return string <width>x<height> or null if it could not be parsed |
365 |
| - */ |
366 |
| - private function getConsoleMode() |
367 |
| - { |
368 |
| - if (!function_exists('proc_open')) { |
369 |
| - return; |
370 |
| - } |
371 |
| - |
372 |
| - $descriptorspec = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')); |
373 |
| - $process = proc_open('mode CON', $descriptorspec, $pipes, null, null, array('suppress_errors' => true)); |
374 |
| - if (is_resource($process)) { |
375 |
| - $info = stream_get_contents($pipes[1]); |
376 |
| - fclose($pipes[1]); |
377 |
| - fclose($pipes[2]); |
378 |
| - proc_close($process); |
379 |
| - |
380 |
| - if (preg_match('/-{8}+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) { |
381 |
| - return $matches[2].'x'.$matches[1]; |
382 |
| - } |
383 |
| - } |
| 319 | + return $width; |
384 | 320 | }
|
385 | 321 | }
|
0 commit comments