Skip to content

Commit

Permalink
Added Util class to help detect TTY properly. (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell authored and greg-1-anderson committed Apr 5, 2019
1 parent 6da921a commit c1c1916
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Util/Tty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
namespace Consolidation\SiteProcess\Util;

use Symfony\Component\Process\Process;

/**
* Wrapper for universal support of TTY-related functionality across versions of
* Symfony Process.
*/
class Tty
{
/**
* In Symfony Process 4+, this is simply a wrapper for Process::isTtySupported().
* In lower versions, it mimics the same functionality.
*/
public static function isTtySupported()
{
if (method_exists('\Symfony\Component\Process\Process', 'isTtySupported')) {
return Process::isTtySupported();
}
return (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes);
}
}

0 comments on commit c1c1916

Please sign in to comment.