From 51357e58f091a68f2950513604cc7633d7416747 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 8 May 2013 12:46:54 +0200 Subject: [PATCH] more console helper and controller refactoring changed name of ansi switch to --colors https://github.com/yiisoft/yii2/commit/69cad905dd049be9d9b35d8103cd60591e13c6ae#commitcomment-3168489 issue #33 --- framework/console/Controller.php | 55 ++++++++-------------------------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/framework/console/Controller.php b/framework/console/Controller.php index 9f34046..c07d92d 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -36,10 +36,12 @@ class Controller extends \yii\base\Controller public $interactive = true; /** - * @var bool whether to enable ANSI style in output. If not set it will be auto detected. - * Default is disabled on Windows systems and enabled on linux. + * @var bool whether to enable ANSI style in output. + * Setting this will affect [[ansiFormat()]], [[stdout()]] and [[stderr()]]. + * If not set it will be auto detected using [[yii\helpers\Console::streamSupportsAnsiColors()]] with STDOUT + * for [[ansiFormat()]] and [[stdout()]] and STDERR for [[stderr()]]. */ - public $ansi; + public $colors; /** * Runs an action with the specified action ID and parameters. @@ -193,47 +195,6 @@ class Controller extends \yii\base\Controller } /** - * Asks the user for input. Ends when the user types a carriage return (PHP_EOL). Optionally, It also provides a - * prompt. - * - * @param string $prompt the prompt (optional) - * @return string the user's input - */ - public function input($prompt = null) - { - if (isset($prompt)) { - $this->stdout($prompt); - } - return Console::stdin(); - } - - /** - * Prints text to STDOUT appended with a carriage return (PHP_EOL). - * - * @param string $text - * @param bool $raw - * - * @return mixed Number of bytes printed or bool false on error - */ - public function output($text = null) - { - return $this->stdout($text . PHP_EOL); - } - - /** - * Prints text to STDERR appended with a carriage return (PHP_EOL). - * - * @param string $text - * @param bool $raw - * - * @return mixed Number of bytes printed or false on error - */ - public function error($text = null) - { - return $this->stderr($text . PHP_EOL); - } - - /** * Prompts the user for input and validates it * * @param string $text prompt string @@ -248,7 +209,11 @@ class Controller extends \yii\base\Controller */ public function prompt($text, $options = array()) { - return Console::prompt($text, $options); + if ($this->interactive) { + return Console::prompt($text, $options); + } else { + return isset($options['default']) ? $options['default'] : ''; + } } /**