Skip to content

Commit f5436ad

Browse files
[VarDumper][PhpUnitBridge] Fix color detection
1 parent 3da1077 commit f5436ad

File tree

2 files changed

+5
-35
lines changed

2 files changed

+5
-35
lines changed

Helper/QuestionHelper.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -503,19 +503,7 @@ private function isInteractiveInput($inputStream): bool
503503
return self::$stdinIsInteractive;
504504
}
505505

506-
if (\function_exists('stream_isatty')) {
507-
return self::$stdinIsInteractive = @stream_isatty(fopen('php://stdin', 'r'));
508-
}
509-
510-
if (\function_exists('posix_isatty')) {
511-
return self::$stdinIsInteractive = @posix_isatty(fopen('php://stdin', 'r'));
512-
}
513-
514-
if (!\function_exists('shell_exec')) {
515-
return self::$stdinIsInteractive = true;
516-
}
517-
518-
return self::$stdinIsInteractive = (bool) shell_exec('stty 2> '.('\\' === \DIRECTORY_SEPARATOR ? 'NUL' : '/dev/null'));
506+
return self::$stdinIsInteractive = @stream_isatty(fopen('php://stdin', 'r'));
519507
}
520508

521509
/**

Output/StreamOutput.php

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ protected function hasColorSupport()
9999
return false;
100100
}
101101

102-
if (\DIRECTORY_SEPARATOR === '\\'
103-
&& \function_exists('sapi_windows_vt100_support')
104-
&& @sapi_windows_vt100_support($this->stream)
105-
) {
102+
if ('\\' === \DIRECTORY_SEPARATOR && @sapi_windows_vt100_support($this->stream)) {
106103
return true;
107104
}
108105

@@ -114,14 +111,12 @@ protected function hasColorSupport()
114111
return true;
115112
}
116113

117-
$term = (string) getenv('TERM');
118-
119-
if ('dumb' === $term) {
114+
if ('dumb' === $term = (string) getenv('TERM')) {
120115
return false;
121116
}
122117

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

127122
/**
@@ -138,19 +133,6 @@ private function isTty(): bool
138133
return true;
139134
}
140135

141-
// Modern cross-platform function, includes the fstat fallback so if it is present we trust it
142-
if (\function_exists('stream_isatty')) {
143-
return stream_isatty($this->stream);
144-
}
145-
146-
// Only trusting this if it is positive, otherwise prefer fstat fallback.
147-
if (\function_exists('posix_isatty') && posix_isatty($this->stream)) {
148-
return true;
149-
}
150-
151-
$stat = @fstat($this->stream);
152-
153-
// Check if formatted mode is S_IFCHR
154-
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
136+
return @stream_isatty($this->stream);
155137
}
156138
}

0 commit comments

Comments
 (0)