From fa2a75c3f11d732e63483150f70ed27fc2bdf825 Mon Sep 17 00:00:00 2001 From: Fitorec Date: Mon, 4 Jun 2012 01:01:22 -0500 Subject: [PATCH] Add the numbers format console menus, showing the validation options in 2 columns. --- .../Console/Command/Task/ControllerTask.php | 3 ++- lib/Cake/Console/Command/Task/ModelTask.php | 27 +++++++++++-------- lib/Cake/Console/ConsoleOutput.php | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index ca68389ad..8feecc1a5 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -397,11 +397,12 @@ class ControllerTask extends BakeTask { if ($this->interactive == true) { $this->out(__d('cake_console', 'Possible Controllers based on your current database:')); + $this->hr(); $this->_controllerNames = array(); $count = count($this->__tables); for ($i = 0; $i < $count; $i++) { $this->_controllerNames[] = $this->_controllerName($this->_modelName($this->__tables[$i])); - $this->out($i + 1 . ". " . $this->_controllerNames[$i]); + $this->out(sprintf("%2d. %s", $i + 1, $this->_controllerNames[$i])); } return $this->_controllerNames; } diff --git a/lib/Cake/Console/Command/Task/ModelTask.php b/lib/Cake/Console/Command/Task/ModelTask.php index 39ada2e3e..1aa5203ab 100644 --- a/lib/Cake/Console/Command/Task/ModelTask.php +++ b/lib/Cake/Console/Command/Task/ModelTask.php @@ -169,8 +169,9 @@ class ModelTask extends BakeTask { $valid = false; $max = count($options); while (!$valid) { + $len = strlen((count($options)+1).''); foreach ($options as $i => $option) { - $this->out($i + 1 . '. ' . $option); + $this->out(sprintf("%${len}d. %s", $i+1, $option)); } if (empty($prompt)) { $prompt = __d('cake_console', 'Make a selection from the choices above'); @@ -403,20 +404,23 @@ class ModelTask extends BakeTask { while ($anotherValidator == 'y') { if ($this->interactive) { $this->out(); - $this->out(__d('cake_console', 'Field: %s', $fieldName)); - $this->out(__d('cake_console', 'Type: %s', $metaData['type'])); + $this->out(__d('cake_console', 'Field: %s', $fieldName)); + $this->out(__d('cake_console', 'Type: %s', $metaData['type'])); $this->hr(); $this->out(__d('cake_console', 'Please select one of the following validation options:')); $this->hr(); + + for ($i = 1, $m=$defaultChoice/2; $i < $m; $i++) { + $str_aux = sprintf("%2d. %s", $i, $this->_validations[$i]); + $str_aux = $str_aux.str_repeat(" ", 31 - strlen($str_aux)); + $str_aux .= sprintf("%2d. %s", $m+$i, $this->_validations[$m+$i]); + $this->out($str_aux); + } + $this->out(__d('cake_console', "%s - Do not do any validation on this field.", $defaultChoice)); + $this->hr(); } - $prompt = ''; - for ($i = 1; $i < $defaultChoice; $i++) { - $prompt .= $i . ' - ' . $this->_validations[$i] . "\n"; - } - $prompt .= __d('cake_console', "%s - Do not do any validation on this field.\n", $defaultChoice); - $prompt .= __d('cake_console', "... or enter in a valid regex validation string.\n"); - + $prompt = __d('cake_console', "... or enter in a valid regex validation string.\n"); $methods = array_flip($this->_validations); $guess = $defaultChoice; if ($metaData['null'] != 1 && !in_array($fieldName, array($primaryKey, 'created', 'modified', 'updated'))) { @@ -842,8 +846,9 @@ class ModelTask extends BakeTask { } if ($this->interactive === true) { $this->out(__d('cake_console', 'Possible Models based on your current database:')); + $len = strlen(($count+1).''); for ($i = 0; $i < $count; $i++) { - $this->out($i + 1 . ". " . $this->_modelNames[$i]); + $this->out(sprintf("%${len}d. %s", $i+1, $this->_modelNames[$i])); } } return $this->_tables; diff --git a/lib/Cake/Console/ConsoleOutput.php b/lib/Cake/Console/ConsoleOutput.php index c3f326445..04ceb9a6e 100644 --- a/lib/Cake/Console/ConsoleOutput.php +++ b/lib/Cake/Console/ConsoleOutput.php @@ -137,7 +137,7 @@ class ConsoleOutput { 'debug' => array('text' => 'yellow'), 'success' => array('text' => 'green'), 'comment' => array('text' => 'blue'), - 'question' => array('text' => "magenta"), + 'question' => array('text' => 'magenta'), ); /**