diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 0d24dfe7c..368af21a0 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -15,10 +15,10 @@ namespace Composer\Console; use Symfony\Component\Console\Application as BaseApplication; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Finder\Finder; +use Composer\Console\Output\ConsoleOutput; use Composer\Command; use Composer\Composer; use Composer\Installer; diff --git a/src/Composer/Console/Output/ConsoleOutput.php b/src/Composer/Console/Output/ConsoleOutput.php new file mode 100644 index 000000000..0a8a8bd03 --- /dev/null +++ b/src/Composer/Console/Output/ConsoleOutput.php @@ -0,0 +1,104 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Console\Output; + +use Symfony\Component\Console\Output\ConsoleOutput as BaseConsoleOutput; + +/** + * ConsoleOutput is the default class for all CLI output. + * + * @author François Pluchino + */ +class ConsoleOutput extends BaseConsoleOutput +{ + /** + * Overwrites a previous message to the output. + * + * @param string|array $messages The message as an array of lines of a single string + * @param integer $size The size of line + * @param Boolean $newline Whether to add a newline or not + * @param integer $type The type of output + */ + public function overwrite($messages, $size = 80, $newline = false, $type = 0) + { + for ($place = $size; $place > 0; $place--) { + $this->write("\x08"); + } + + $this->write($messages, false, $type); + + for ($place = ($size - strlen($line)); $place > 0; $place--) { + $this->write(' '); + } + + // clean up the end line + for ($place = ($size - strlen($messages)); $place > 0; $place--) { + $this->write("\x08"); + } + + if ($newline) { + $this->writeln(''); + } + } + + /** + * Overwrites a previous message to the output and adds a newline at the end. + * + * @param string|array $messages The message as an array of lines of a single string + * @param integer $size The size of line + * @param integer $type The type of output + */ + public function overwriteln($messages, $size = 80, $type = 0) + { + $this->write($messages, $size, true, $type); + } + + /** + * Interactively prompts for input without echoing to the terminal. + * Requires a bash shell or Windows and won't work with safe_mode + * settings (Uses `shell_exec`). + * + * @param string $title The title of prompt (only for windows) + * + * @return string The value + */ + public function promptSilent($title = '') + { + if (preg_match('/^win/i', PHP_OS)) { + $vbscript = sys_get_temp_dir() . '/prompt_password.vbs'; + file_put_contents($vbscript, + 'wscript.echo(Inputbox("' . addslashes($title) . '","' + . addslashes($title) . '", ""))'); + $command = "cscript //nologo " . escapeshellarg($vbscript); + $value = rtrim(shell_exec($command)); + unlink($vbscript); + $this->writeln(''); + + return $value; + + } else { + $command = "/usr/bin/env bash -c 'echo OK'"; + + if (rtrim(shell_exec($command)) !== 'OK') { + trigger_error("Can't invoke bash"); + return; + } + + $command = "/usr/bin/env bash -c 'read -s mypassword && echo \$mypassword'"; + $value = rtrim(shell_exec($command)); + $this->writeln(''); + + return $value; + } + } +} diff --git a/src/Composer/Downloader/FileDownloader.php b/src/Composer/Downloader/FileDownloader.php index 08769ff60..dc4769408 100644 --- a/src/Composer/Downloader/FileDownloader.php +++ b/src/Composer/Downloader/FileDownloader.php @@ -20,6 +20,7 @@ use Symfony\Component\Console\Input\InputInterface; * * @author Kirill chEbba Chebunin * @author Jordi Boggiano + * @author François Pluchino */ abstract class FileDownloader implements DownloaderInterface { @@ -65,7 +66,8 @@ abstract class FileDownloader implements DownloaderInterface $fileName = rtrim($path.'/'.md5(time().rand()).'.'.pathinfo($url, PATHINFO_EXTENSION), '.'); - echo 'Downloading '.$url.' to '.$fileName.PHP_EOL; + //echo 'Downloading '.$url.' to '.$fileName.PHP_EOL; + $this->output->writeln(" - Downloading " . $package->getName() . " (" . $package->getPrettyVersion() . ")"); if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) { // bypass https for github if openssl is disabled @@ -106,11 +108,11 @@ abstract class FileDownloader implements DownloaderInterface throw new \UnexpectedValueException('The checksum verification of the archive failed (downloaded from '.$url.')'); } - echo 'Unpacking archive'.PHP_EOL; + $this->output->writeln(' Unpacking archive'); $this->extract($fileName, $path); - echo 'Cleaning up'.PHP_EOL; + $this->output->writeln(' Cleaning up'); unlink($fileName); // If we have only a one dir inside it suppose to be a package itself