Skip to content

Commit

Permalink
Refactor isTtySupported()
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Jul 18, 2022
1 parent 5bc5827 commit 007fa61
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Console/Tests/CursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 007fa61

Please sign in to comment.