Skip to content

Commit 32bde39

Browse files
bug symfony#34344 [Console] Constant STDOUT might be undefined (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] Constant STDOUT might be undefined | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#34341 | License | MIT | Doc PR | N/A Commits ------- bb8c82c [Console] Constant STDOUT might be undefined.
2 parents 53dc781 + bb8c82c commit 32bde39

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Symfony/Component/Console/Terminal.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ private static function initDimensions()
7979
// or [w, h] from "wxh"
8080
self::$width = (int) $matches[1];
8181
self::$height = isset($matches[4]) ? (int) $matches[4] : (int) $matches[2];
82-
} elseif (self::hasSttyAvailable()) {
82+
} elseif (!self::hasVt100Support() && self::hasSttyAvailable()) {
83+
// only use stty on Windows if the terminal does not support vt100 (e.g. Windows 7 + git-bash)
84+
// testing for stty in a Windows 10 vt100-enabled console will implicitly disable vt100 support on STDOUT
8385
self::initDimensionsUsingStty();
8486
} elseif (null !== $dimensions = self::getConsoleMode()) {
8587
// extract [w, h] from "wxh"
@@ -91,6 +93,17 @@ private static function initDimensions()
9193
}
9294
}
9395

96+
/**
97+
* Returns whether STDOUT has vt100 support (some Windows 10+ configurations).
98+
*/
99+
private static function hasVt100Support()
100+
{
101+
return \function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(fopen('php://stdout', 'w'));
102+
}
103+
104+
/**
105+
* Initializes dimensions using the output of an stty columns line.
106+
*/
94107
private static function initDimensionsUsingStty()
95108
{
96109
if ($sttyString = self::getSttyColumns()) {

0 commit comments

Comments
 (0)