Skip to content

Commit

Permalink
Fixes #1734: Be smarter about selecting the right value for 'useTty' (#…
Browse files Browse the repository at this point in the history
…1736)

* Fixes #1734: Be smarter about selecting the right value for 'useTty' when redirecting stdout in 'terminus drush' and 'terminus wp'.

* DRY up the tty check.
  • Loading branch information
greg-1-anderson authored Jul 11, 2017
1 parent c087651 commit deb495a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/Commands/Remote/SSHBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ protected function executeCommand(array $command_args)
$command_summary = $this->getCommandSummary($command_args);
$command_line = $this->getCommandLine($command_args);

$input = $this->input();
$useTty = $input->isInteractive() ? null : false;
$useTty = $this->useTty($this->input());

$output = $this->output();
$echoOutputFn = function ($type, $buffer) {
Expand All @@ -83,6 +82,25 @@ protected function executeCommand(array $command_args)
}
}

/**
* Determine whether the use of a tty is appropriate for the current command.
*/
protected function useTty($input)
{
// If we are not in interactive mode, then never use a tty.
if (!$input->isInteractive()) {
return false;
}
// If we are in interactive mode (or at least the user did not
// specify -n / --no-interaction), then also prevent the use
// of a tty if stdout is redirected.
if (function_exists('posix_isatty') && !posix_isatty(STDOUT)) {
return false;
}
// Otherwise, let the local machine helper decide whether to use a tty.
return null;
}

/**
* Validates that the environment's connection mode is appropriately set
*
Expand Down

0 comments on commit deb495a

Please sign in to comment.