From 007fa61ffe703fcab9301226f5c31b6f87437137 Mon Sep 17 00:00:00 2001 From: Yurun Date: Mon, 18 Jul 2022 16:59:48 +0800 Subject: [PATCH] Refactor isTtySupported() --- src/Symfony/Component/Console/Cursor.php | 4 ++-- src/Symfony/Component/Console/Tests/CursorTest.php | 1 + src/Symfony/Component/Process/Process.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Console/Cursor.php b/src/Symfony/Component/Console/Cursor.php index 03e8c618b76dd..f34824a0dc8af 100644 --- a/src/Symfony/Component/Console/Cursor.php +++ b/src/Symfony/Component/Console/Cursor.php @@ -183,8 +183,8 @@ public function getCurrentPosition(): array { static $isTtySupported; - if (null === $isTtySupported && \function_exists('proc_open')) { - $isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes); + if (null === $isTtySupported) { + $isTtySupported = ('/' === \DIRECTORY_SEPARATOR && stream_isatty(\STDOUT)); } if (!$isTtySupported) { diff --git a/src/Symfony/Component/Console/Tests/CursorTest.php b/src/Symfony/Component/Console/Tests/CursorTest.php index 3c22f252d6b0a..7237f8dde98d0 100644 --- a/src/Symfony/Component/Console/Tests/CursorTest.php +++ b/src/Symfony/Component/Console/Tests/CursorTest.php @@ -184,6 +184,7 @@ public function testGetCurrentPosition() $this->assertEquals("\x1b[11;10H", $this->getOutputContent($output)); $isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes); + $this->assertEquals($isTtySupported, '/' === \DIRECTORY_SEPARATOR && stream_isatty(\STDOUT)); if ($isTtySupported) { // When tty is supported, we can't validate the exact cursor position since it depends where the cursor is when the test runs. diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index 972fe703d509e..7df95fc426c19 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -1205,7 +1205,7 @@ public static function isTtySupported(): bool static $isTtySupported; if (null === $isTtySupported) { - $isTtySupported = (bool) @proc_open('echo 1 >/dev/null', [['file', '/dev/tty', 'r'], ['file', '/dev/tty', 'w'], ['file', '/dev/tty', 'w']], $pipes); + $isTtySupported = ('/' === \DIRECTORY_SEPARATOR && stream_isatty(\STDOUT)); } return $isTtySupported; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy