Skip to content

Commit ab3d9fc

Browse files
committed
minor #46971 [Console] Refactor isTtySupported() (Yurunsoft)
This PR was merged into the 6.2 branch. Discussion ---------- [Console] Refactor isTtySupported() | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | - | License | MIT | Doc PR | - <!-- Replace this notice by a short README for your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against the latest branch. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> `stream_isatty()`: <https://www.php.net/manual/en/function.stream-isatty.php> (PHP 7 >= 7.2.0, PHP 8) Commits ------- 007fa61 Refactor isTtySupported()
2 parents e89f0ff + 007fa61 commit ab3d9fc

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/Symfony/Component/Console/Cursor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ public function getCurrentPosition(): array
183183
{
184184
static $isTtySupported;
185185

186-
if (null === $isTtySupported && \function_exists('proc_open')) {
187-
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes);
186+
if (null === $isTtySupported) {
187+
$isTtySupported = ('/' === \DIRECTORY_SEPARATOR && stream_isatty(\STDOUT));
188188
}
189189

190190
if (!$isTtySupported) {

src/Symfony/Component/Console/Tests/CursorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ public function testGetCurrentPosition()
184184
$this->assertEquals("\x1b[11;10H", $this->getOutputContent($output));
185185

186186
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes);
187+
$this->assertEquals($isTtySupported, '/' === \DIRECTORY_SEPARATOR && stream_isatty(\STDOUT));
187188

188189
if ($isTtySupported) {
189190
// When tty is supported, we can't validate the exact cursor position since it depends where the cursor is when the test runs.

src/Symfony/Component/Process/Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ public static function isTtySupported(): bool
12051205
static $isTtySupported;
12061206

12071207
if (null === $isTtySupported) {
1208-
$isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes);
1208+
$isTtySupported = ('/' === \DIRECTORY_SEPARATOR && stream_isatty(\STDOUT));
12091209
}
12101210

12111211
return $isTtySupported;

0 commit comments

Comments
 (0)