upgraded dependencies
This commit is contained in:
83
vendor/sebastian/environment/src/Console.php
vendored
83
vendor/sebastian/environment/src/Console.php
vendored
@@ -9,12 +9,32 @@
|
||||
*/
|
||||
namespace SebastianBergmann\Environment;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
use const STDIN;
|
||||
use const STDOUT;
|
||||
use function defined;
|
||||
use function fclose;
|
||||
use function fstat;
|
||||
use function function_exists;
|
||||
use function getenv;
|
||||
use function is_resource;
|
||||
use function is_string;
|
||||
use function posix_isatty;
|
||||
use function preg_match;
|
||||
use function proc_close;
|
||||
use function proc_open;
|
||||
use function sapi_windows_vt100_support;
|
||||
use function shell_exec;
|
||||
use function stream_get_contents;
|
||||
use function stream_isatty;
|
||||
use function trim;
|
||||
|
||||
final class Console
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public const STDIN = 0;
|
||||
public const STDIN = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
@@ -34,26 +54,26 @@ final class Console
|
||||
*/
|
||||
public function hasColorSupport(): bool
|
||||
{
|
||||
if ('Hyper' === \getenv('TERM_PROGRAM')) {
|
||||
if ('Hyper' === getenv('TERM_PROGRAM')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->isWindows()) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return (\defined('STDOUT') && \function_exists('sapi_windows_vt100_support') && @\sapi_windows_vt100_support(\STDOUT))
|
||||
|| false !== \getenv('ANSICON')
|
||||
|| 'ON' === \getenv('ConEmuANSI')
|
||||
|| 'xterm' === \getenv('TERM');
|
||||
return (defined('STDOUT') && function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT)) ||
|
||||
false !== getenv('ANSICON') ||
|
||||
'ON' === getenv('ConEmuANSI') ||
|
||||
'xterm' === getenv('TERM');
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
if (!\defined('STDOUT')) {
|
||||
if (!defined('STDOUT')) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return false;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return $this->isInteractive(\STDOUT);
|
||||
return $this->isInteractive(STDOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,7 +83,7 @@ final class Console
|
||||
*/
|
||||
public function getNumberOfColumns(): int
|
||||
{
|
||||
if (!$this->isInteractive(\defined('STDIN') ? \STDIN : self::STDIN)) {
|
||||
if (!$this->isInteractive(defined('STDIN') ? STDIN : self::STDIN)) {
|
||||
return 80;
|
||||
}
|
||||
|
||||
@@ -84,23 +104,28 @@ final class Console
|
||||
*/
|
||||
public function isInteractive($fileDescriptor = self::STDOUT): bool
|
||||
{
|
||||
if (\is_resource($fileDescriptor)) {
|
||||
if (is_resource($fileDescriptor)) {
|
||||
// These functions require a descriptor that is a real resource, not a numeric ID of it
|
||||
if (\function_exists('stream_isatty') && @\stream_isatty($fileDescriptor)) {
|
||||
if (function_exists('stream_isatty') && @stream_isatty($fileDescriptor)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$stat = @\fstat(\STDOUT);
|
||||
// Check if formatted mode is S_IFCHR
|
||||
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
|
||||
if (function_exists('fstat') && @stream_isatty($fileDescriptor)) {
|
||||
$stat = @fstat(STDOUT);
|
||||
|
||||
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return \function_exists('posix_isatty') && @\posix_isatty($fileDescriptor);
|
||||
return function_exists('posix_isatty') && @posix_isatty($fileDescriptor);
|
||||
}
|
||||
|
||||
private function isWindows(): bool
|
||||
{
|
||||
return \DIRECTORY_SEPARATOR === '\\';
|
||||
return DIRECTORY_SEPARATOR === '\\';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,13 +133,13 @@ final class Console
|
||||
*/
|
||||
private function getNumberOfColumnsInteractive(): int
|
||||
{
|
||||
if (\function_exists('shell_exec') && \preg_match('#\d+ (\d+)#', \shell_exec('stty size') ?: '', $match) === 1) {
|
||||
if (function_exists('shell_exec') && preg_match('#\d+ (\d+)#', shell_exec('stty size') ?: '', $match) === 1) {
|
||||
if ((int) $match[1] > 0) {
|
||||
return (int) $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (\function_exists('shell_exec') && \preg_match('#columns = (\d+);#', \shell_exec('stty') ?: '', $match) === 1) {
|
||||
if (function_exists('shell_exec') && preg_match('#columns = (\d+);#', shell_exec('stty') ?: '', $match) === 1) {
|
||||
if ((int) $match[1] > 0) {
|
||||
return (int) $match[1];
|
||||
}
|
||||
@@ -128,13 +153,13 @@ final class Console
|
||||
*/
|
||||
private function getNumberOfColumnsWindows(): int
|
||||
{
|
||||
$ansicon = \getenv('ANSICON');
|
||||
$ansicon = getenv('ANSICON');
|
||||
$columns = 80;
|
||||
|
||||
if (\is_string($ansicon) && \preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', \trim($ansicon), $matches)) {
|
||||
$columns = $matches[1];
|
||||
} elseif (\function_exists('proc_open')) {
|
||||
$process = \proc_open(
|
||||
if (is_string($ansicon) && preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim($ansicon), $matches)) {
|
||||
$columns = (int) $matches[1];
|
||||
} elseif (function_exists('proc_open')) {
|
||||
$process = proc_open(
|
||||
'mode CON',
|
||||
[
|
||||
1 => ['pipe', 'w'],
|
||||
@@ -146,15 +171,15 @@ final class Console
|
||||
['suppress_errors' => true]
|
||||
);
|
||||
|
||||
if (\is_resource($process)) {
|
||||
$info = \stream_get_contents($pipes[1]);
|
||||
if (is_resource($process)) {
|
||||
$info = stream_get_contents($pipes[1]);
|
||||
|
||||
\fclose($pipes[1]);
|
||||
\fclose($pipes[2]);
|
||||
\proc_close($process);
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
proc_close($process);
|
||||
|
||||
if (\preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
|
||||
$columns = $matches[2];
|
||||
if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
|
||||
$columns = (int) $matches[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user