Skip to content

Commit afc9629

Browse files
committed
Merge branch '7.0' into 7.1
* 7.0: fix used class after merge fix tests [Console] Only execute additional checks for color support if the output is a TTY fix aircraft inflection [TwigBundle] Fix configuration when 'paths' is null Fix AttributeClassLoaderTestCase + Added ->setUp() - Removed 'abstract' so it'd be picked up by Tests. * Changed getNamespace() to full path Qualified Name. * Rename file AttributeClassLoaderTestCase to AttributeClassLoaderTest and the class. register the MailPaceTransportFactory [String] Correct inflection of axis [Security] Fix `AuthenticationUtils::getLastUsername()` returning null [Process] Fixed inconsistent test fix(ldap): replace {username} with {user_identifier} in LDAP factories
2 parents e930278 + e6ab42f commit afc9629

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

Output/StreamOutput.php

+35-2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ protected function hasColorSupport(): bool
9494
return false;
9595
}
9696

97+
if (!$this->isTty()) {
98+
return false;
99+
}
100+
97101
if (\DIRECTORY_SEPARATOR === '\\'
98102
&& \function_exists('sapi_windows_vt100_support')
99103
&& @sapi_windows_vt100_support($this->stream)
@@ -104,7 +108,36 @@ protected function hasColorSupport(): bool
104108
return 'Hyper' === getenv('TERM_PROGRAM')
105109
|| false !== getenv('ANSICON')
106110
|| 'ON' === getenv('ConEmuANSI')
107-
|| str_starts_with((string) getenv('TERM'), 'xterm')
108-
|| stream_isatty($this->stream);
111+
|| str_starts_with((string) getenv('TERM'), 'xterm');
112+
}
113+
114+
/**
115+
* Checks if the stream is a TTY, i.e; whether the output stream is connected to a terminal.
116+
*
117+
* Reference: Composer\Util\Platform::isTty
118+
* https://github.com/composer/composer
119+
*/
120+
private function isTty(): bool
121+
{
122+
// Detect msysgit/mingw and assume this is a tty because detection
123+
// does not work correctly, see https://github.com/composer/composer/issues/9690
124+
if (\in_array(strtoupper((string) getenv('MSYSTEM')), ['MINGW32', 'MINGW64'], true)) {
125+
return true;
126+
}
127+
128+
// Modern cross-platform function, includes the fstat fallback so if it is present we trust it
129+
if (\function_exists('stream_isatty')) {
130+
return stream_isatty($this->stream);
131+
}
132+
133+
// Only trusting this if it is positive, otherwise prefer fstat fallback.
134+
if (\function_exists('posix_isatty') && posix_isatty($this->stream)) {
135+
return true;
136+
}
137+
138+
$stat = @fstat($this->stream);
139+
140+
// Check if formatted mode is S_IFCHR
141+
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;
109142
}
110143
}

0 commit comments

Comments
 (0)