From 0f7bf4155c2b2c1bf5d0aa202b7de1643b85c8e6 Mon Sep 17 00:00:00 2001 From: lenar Date: Fri, 15 Jul 2011 00:10:14 +0300 Subject: [PATCH 1/2] [Console] Detect if interactive mode is possible at all --- src/Symfony/Component/Console/Application.php | 7 +++++++ src/Symfony/Component/Console/Helper/DialogHelper.php | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index fc30e460e9b15..decdcc3b14f39 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -170,6 +170,13 @@ public function doRun(InputInterface $input, OutputInterface $output) $input->setInteractive(false); } + if (function_exists('posix_isatty')) { + $inputStream = $this->getHelperSet()->get('dialog')->getInputStream(); + if (!@posix_isatty($inputStream)) { + $input->setInteractive(false); + } + } + if (true === $input->hasParameterOption(array('--quiet', '-q'))) { $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); } elseif (true === $input->hasParameterOption(array('--verbose', '-v'))) { diff --git a/src/Symfony/Component/Console/Helper/DialogHelper.php b/src/Symfony/Component/Console/Helper/DialogHelper.php index 8d73addcf0e1a..c1dd5813e6aac 100644 --- a/src/Symfony/Component/Console/Helper/DialogHelper.php +++ b/src/Symfony/Component/Console/Helper/DialogHelper.php @@ -117,6 +117,16 @@ public function setInputStream($stream) $this->inputStream = $stream; } + /** + * Returns the helper's input stream + * + * @return string + */ + public function getInputStream() + { + return $this->inputStream; + } + /** * Returns the helper's canonical name */ From fd00ed0be18e420cad775992fcb1c0490c95135e Mon Sep 17 00:00:00 2001 From: lenar Date: Thu, 29 Sep 2011 11:45:17 +0300 Subject: [PATCH 2/2] [Console] Check if dialog helper actually exists --- src/Symfony/Component/Console/Application.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index decdcc3b14f39..9e4dd2d80dc5e 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -170,9 +170,9 @@ public function doRun(InputInterface $input, OutputInterface $output) $input->setInteractive(false); } - if (function_exists('posix_isatty')) { + if (function_exists('posix_isatty') && $this->getHelperSet()->has('dialog')) { $inputStream = $this->getHelperSet()->get('dialog')->getInputStream(); - if (!@posix_isatty($inputStream)) { + if (!posix_isatty($inputStream)) { $input->setInteractive(false); } }