From 267a4d7d82743b16d7b4ca92ecbedba26bbc04c9 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Thu, 20 Jan 2011 19:07:48 +0100 Subject: [PATCH] Wrap prompt message, and place default value after the prompt when using multiple choices. --- framework/Cli/lib/Horde/Cli.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/framework/Cli/lib/Horde/Cli.php b/framework/Cli/lib/Horde/Cli.php index 0af8b2c1d..8fc9f0e6d 100644 --- a/framework/Cli/lib/Horde/Cli.php +++ b/framework/Cli/lib/Horde/Cli.php @@ -341,19 +341,19 @@ class Horde_Cli */ public function prompt($prompt, $choices = null, $default = null) { - if ($default !== null) { - $prompt .= ' [' . $default . ']'; - } - // Main event loop to capture top level command. while (true) { // Print out the prompt message. - $this->writeln($prompt . ' ', !is_array($choices)); if (is_array($choices) && !empty($choices)) { + $this->writeln(wordwrap($prompt) . ' ', !is_array($choices)); foreach ($choices as $key => $choice) { $this->writeln($this->indent('(' . $this->bold($key) . ') ' . $choice)); } - $this->writeln(Horde_Cli_Translation::t("Type your choice: "), true); + $question = Horde_Cli_Translation::t("Type your choice"); + if ($default !== null) { + $question .= ' [' . $default . ']'; + } + $this->writeln($question . ': ', true); @ob_flush(); // Get the user choice. @@ -367,6 +367,10 @@ class Horde_Cli $this->writeln($this->red(sprintf(Horde_Cli_Translation::t("\"%s\" is not a valid choice."), $response))); } } else { + if ($default !== null) { + $prompt .= ' [' . $default . ']'; + } + $this->writeln(wordwrap($prompt) . ' ', true); @ob_flush(); $response = trim(fgets(STDIN)); if ($response === '' && $default !== null) { -- 2.11.0