Skip to content

Commit

Permalink
Backport bug #34085 [Console] DDetect dimensions using mode CON if vt…
Browse files Browse the repository at this point in the history
…100 is supported

This PR was merged into the 4.3 branch.

Discussion
----------

[Console] Detect dimensions using mode CON if vt100 is supported

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #33915
| License       | MIT

This fixes color support detection for users of Win10 + git-bash.  If vt100 support is detected, the terminal will not try to use `stty` to test for dimensions. Calling such command implicitly disables vt100 support on STDOUT.

Commits
-------

fdeceff [Console] Fix #33915, Detect dimensions using mode CON if vt100 is supported
  • Loading branch information
nicolas-grekas authored and chalasr committed Nov 13, 2019
1 parent 7064ff3 commit 0059079
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Symfony/Component/Console/Terminal.php
Expand Up @@ -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"
Expand All @@ -91,6 +93,17 @@ private static function initDimensions()
}
}

/**
* Returns whether STDOUT has vt100 support (some Windows 10+ configurations).
*/
private static function hasVt100Support(): bool
{
return \function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT);
}

/**
* Initializes dimensions using the output of an stty columns line.
*/
private static function initDimensionsUsingStty()
{
if ($sttyString = self::getSttyColumns()) {
Expand Down

0 comments on commit 0059079

Please sign in to comment.