Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  Skip Twig v3.9-dev for now
  [Validator] Update Dutch (nl) translation
  Update Albanian translations
  [Validator] Update translation
  [FrameworkBundle] Prevent silenced warning by checking if /proc/mount exists
  [VarDumper][PhpUnitBridge] Fix color detection
  prevent throwing NOT_FOUND error when tube is empty
  [Validator] Update missing validator translation for Swedish
  [FrameworkBundle] Fix eager-loading of env vars in ConfigBuilderCacheWarmer
  [Messenger] Fix failing Redis test
  [Validator] Update Italian (it) translations
  [Validator] Missing translations for Hungarian (hu) #53769
  revert to native PHP union types
  [Validator] Missing translations for Russian (ru) #53775
  fix syntax errors on PHP 7
  • Loading branch information
nicolas-grekas committed Feb 7, 2024
2 parents 2900969 + faaaa5e commit b95e86a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 61 deletions.
14 changes: 1 addition & 13 deletions Helper/QuestionHelper.php
Expand Up @@ -495,19 +495,7 @@ private function isInteractiveInput($inputStream): bool
return self::$stdinIsInteractive;
}

if (\function_exists('stream_isatty')) {
return self::$stdinIsInteractive = @stream_isatty(fopen('php://stdin', 'r'));
}

if (\function_exists('posix_isatty')) {
return self::$stdinIsInteractive = @posix_isatty(fopen('php://stdin', 'r'));
}

if (!\function_exists('shell_exec')) {
return self::$stdinIsInteractive = true;
}

return self::$stdinIsInteractive = (bool) shell_exec('stty 2> '.('\\' === \DIRECTORY_SEPARATOR ? 'NUL' : '/dev/null'));
return self::$stdinIsInteractive = @stream_isatty(fopen('php://stdin', 'r'));
}

/**
Expand Down
45 changes: 6 additions & 39 deletions Output/StreamOutput.php
Expand Up @@ -94,14 +94,13 @@ protected function hasColorSupport(): bool
return false;
}

if (!$this->isTty()) {
// Detect msysgit/mingw and assume this is a tty because detection
// does not work correctly, see https://github.com/composer/composer/issues/9690
if (!@stream_isatty($this->stream) && !\in_array(strtoupper((string) getenv('MSYSTEM')), ['MINGW32', 'MINGW64'], true)) {
return false;
}

if (\DIRECTORY_SEPARATOR === '\\'
&& \function_exists('sapi_windows_vt100_support')
&& @sapi_windows_vt100_support($this->stream)
) {
if ('\\' === \DIRECTORY_SEPARATOR && @sapi_windows_vt100_support($this->stream)) {
return true;
}

Expand All @@ -113,43 +112,11 @@ protected function hasColorSupport(): bool
return true;
}

$term = (string) getenv('TERM');

if ('dumb' === $term) {
if ('dumb' === $term = (string) getenv('TERM')) {
return false;
}

// See https://github.com/chalk/supports-color/blob/d4f413efaf8da045c5ab440ed418ef02dbb28bf1/index.js#L157
return 1 === @preg_match('/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/', $term);
}

/**
* Checks if the stream is a TTY, i.e; whether the output stream is connected to a terminal.
*
* Reference: Composer\Util\Platform::isTty
* https://github.com/composer/composer
*/
private function isTty(): bool
{
// Detect msysgit/mingw and assume this is a tty because detection
// does not work correctly, see https://github.com/composer/composer/issues/9690
if (\in_array(strtoupper((string) getenv('MSYSTEM')), ['MINGW32', 'MINGW64'], true)) {
return true;
}

// Modern cross-platform function, includes the fstat fallback so if it is present we trust it
if (\function_exists('stream_isatty')) {
return stream_isatty($this->stream);
}

// Only trusting this if it is positive, otherwise prefer fstat fallback.
if (\function_exists('posix_isatty') && posix_isatty($this->stream)) {
return true;
}

$stat = @fstat($this->stream);

// Check if formatted mode is S_IFCHR
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
return preg_match('/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/', $term);
}
}
10 changes: 1 addition & 9 deletions Terminal.php
Expand Up @@ -140,7 +140,7 @@ private static function initDimensions(): void
// or [w, h] from "wxh"
self::$width = (int) $matches[1];
self::$height = isset($matches[4]) ? (int) $matches[4] : (int) $matches[2];
} elseif (!self::hasVt100Support() && self::hasSttyAvailable()) {
} elseif (!sapi_windows_vt100_support(fopen('php://stdout', 'w')) && 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();
Expand All @@ -154,14 +154,6 @@ private static function initDimensions(): void
}
}

/**
* 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(fopen('php://stdout', 'w'));
}

/**
* Initializes dimensions using the output of an stty columns line.
*/
Expand Down

0 comments on commit b95e86a

Please sign in to comment.