Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fdeceff

Browse files
rteknicolas-grekas
authored andcommitted
[Console] Fix #33915, Detect dimensions using mode CON if vt100 is supported
1 parent 5da67f9 commit fdeceff

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Symfony/Component/Console/Terminal.php

Lines changed: 14 additions & 1 deletion
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(): bool
100+
{
101+
return \function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT);
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)