From bb8c82c0b5d89969aadd44d44873f69976d0233e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 5 Nov 2019 16:00:49 +0100 Subject: [PATCH] [Console] Constant STDOUT might be undefined. --- src/Symfony/Component/Console/Terminal.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Terminal.php b/src/Symfony/Component/Console/Terminal.php index 53a0f7890b6ff..43a31826270bc 100644 --- a/src/Symfony/Component/Console/Terminal.php +++ b/src/Symfony/Component/Console/Terminal.php @@ -79,7 +79,9 @@ private static function initDimensions() // or [w, h] from "wxh" self::$width = (int) $matches[1]; self::$height = isset($matches[4]) ? (int) $matches[4] : (int) $matches[2]; - } elseif (self::hasSttyAvailable()) { + } elseif (!self::hasVt100Support() && self::hasSttyAvailable()) { + // only use stty on Windows if the terminal does not support vt100 (e.g. Windows 7 + git-bash) + // testing for stty in a Windows 10 vt100-enabled console will implicitly disable vt100 support on STDOUT self::initDimensionsUsingStty(); } elseif (null !== $dimensions = self::getConsoleMode()) { // extract [w, h] from "wxh" @@ -91,6 +93,17 @@ private static function initDimensions() } } + /** + * Returns whether STDOUT has vt100 support (some Windows 10+ configurations). + */ + private static function hasVt100Support() + { + return \function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(fopen('php://stdout', 'w')); + } + + /** + * Initializes dimensions using the output of an stty columns line. + */ private static function initDimensionsUsingStty() { if ($sttyString = self::getSttyColumns()) {