Skip to content

Commit

Permalink
Merge pull request #135 from joeparsons/bug/131
Browse files Browse the repository at this point in the history
Addresses #131.  Added check to see if TTY is available.
  • Loading branch information
mglaman authored Feb 27, 2020
2 parents 58a51a8 + 4976ea5 commit 3ec4b60
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Command/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace DrupalCheck\Command;

use DrupalCheck\Util\Tty;
use DrupalFinder\DrupalFinder;
use Nette\Neon\Neon;
use PHPStan\ShouldNotHappenException;
Expand Down Expand Up @@ -211,7 +212,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$command = array_merge($command, $paths);

$process = new Process($command);
$process->setTty(true);
$process->setTty(Tty::isTtySupported());
$process->setTimeout(null);
$process->run(static function ($type, $buffer) use ($output) {
if (Process::ERR === $type) {
Expand Down
28 changes: 28 additions & 0 deletions src/Util/Tty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);

namespace DrupalCheck\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()
{
// Start off by checking STDIN with `posix_isatty`, as that appears to be more reliable
if (function_exists('posix_isatty')) {
return posix_isatty(STDIN);
}
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 3ec4b60

Please sign in to comment.