From 985aad705021b22b5a5d3b64239736d963f2f284 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Wed, 18 Feb 2015 12:41:20 +0100 Subject: [PATCH] [Console] default to stderr if available --- .../Component/Console/Helper/DialogHelper.php | 25 +++++++++++++++++++ .../Console/Helper/ProgressHelper.php | 5 ++++ 2 files changed, 30 insertions(+) diff --git a/src/Symfony/Component/Console/Helper/DialogHelper.php b/src/Symfony/Component/Console/Helper/DialogHelper.php index 3f31c430ca159..8c87368f10462 100644 --- a/src/Symfony/Component/Console/Helper/DialogHelper.php +++ b/src/Symfony/Component/Console/Helper/DialogHelper.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Console\Helper; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Formatter\OutputFormatterStyle; @@ -42,6 +43,10 @@ class DialogHelper extends Helper */ public function select(OutputInterface $output, $question, $choices, $default = null, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false) { + if ($output instanceof ConsoleOutputInterface) { + $output = $output->getErrorOutput(); + } + $width = max(array_map('strlen', array_keys($choices))); $messages = (array) $question; @@ -98,6 +103,10 @@ public function select(OutputInterface $output, $question, $choices, $default = */ public function ask(OutputInterface $output, $question, $default = null, array $autocomplete = null) { + if ($output instanceof ConsoleOutputInterface) { + $output = $output->getErrorOutput(); + } + $output->write($question); $inputStream = $this->inputStream ?: STDIN; @@ -230,6 +239,10 @@ public function ask(OutputInterface $output, $question, $default = null, array $ */ public function askConfirmation(OutputInterface $output, $question, $default = true) { + if ($output instanceof ConsoleOutputInterface) { + $output = $output->getErrorOutput(); + } + $answer = 'z'; while ($answer && !in_array(strtolower($answer[0]), array('y', 'n'))) { $answer = $this->ask($output, $question); @@ -255,6 +268,10 @@ public function askConfirmation(OutputInterface $output, $question, $default = t */ public function askHiddenResponse(OutputInterface $output, $question, $fallback = true) { + if ($output instanceof ConsoleOutputInterface) { + $output = $output->getErrorOutput(); + } + if ('\\' === DIRECTORY_SEPARATOR) { $exe = __DIR__.'/../Resources/bin/hiddeninput.exe'; @@ -332,6 +349,10 @@ public function askHiddenResponse(OutputInterface $output, $question, $fallback */ public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $default = null, array $autocomplete = null) { + if ($output instanceof ConsoleOutputInterface) { + $output = $output->getErrorOutput(); + } + $that = $this; $interviewer = function () use ($output, $question, $default, $autocomplete, $that) { @@ -361,6 +382,10 @@ public function askAndValidate(OutputInterface $output, $question, $validator, $ */ public function askHiddenResponseAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $fallback = true) { + if ($output instanceof ConsoleOutputInterface) { + $output = $output->getErrorOutput(); + } + $that = $this; $interviewer = function () use ($output, $question, $fallback, $that) { diff --git a/src/Symfony/Component/Console/Helper/ProgressHelper.php b/src/Symfony/Component/Console/Helper/ProgressHelper.php index e927fe3b10ed5..a8eea46099fe2 100644 --- a/src/Symfony/Component/Console/Helper/ProgressHelper.php +++ b/src/Symfony/Component/Console/Helper/ProgressHelper.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Console\Helper; +use Symfony\Component\Console\Output\ConsoleOutputInterface; use Symfony\Component\Console\Output\OutputInterface; /** @@ -182,6 +183,10 @@ public function setRedrawFrequency($freq) */ public function start(OutputInterface $output, $max = null) { + if ($output instanceof ConsoleOutputInterface) { + $output = $output->getErrorOutput(); + } + $this->startTime = time(); $this->current = 0; $this->max = (int) $max; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy