Skip to content

Commit

Permalink
[VarDumper][PhpUnitBridge] Fix color detection
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Feb 5, 2024
1 parent 3da1077 commit f5436ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
14 changes: 1 addition & 13 deletions Helper/QuestionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,19 +503,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
26 changes: 4 additions & 22 deletions Output/StreamOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ protected function hasColorSupport()
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 @@ -114,14 +111,12 @@ protected function hasColorSupport()
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);
return preg_match('/^((screen|xterm|vt100|vt220|putty|rxvt|ansi|cygwin|linux).*)|(.*-256(color)?(-bce)?)$/', $term);
}

/**
Expand All @@ -138,19 +133,6 @@ private function isTty(): bool
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 @stream_isatty($this->stream);
}
}

0 comments on commit f5436ad

Please sign in to comment.