From 6d17e04fdce7b47b67ca3b9f7562b9fd9becc59a Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Tue, 7 Aug 2007 14:04:33 +0000 Subject: [PATCH] - fixed zypper to complain when given an invalid answer in y/n prompt (#232250) plus made the answer translatable. --- src/zypper-callbacks.cc | 40 +++++++++++++++++++++++++++++++++------- src/zypper-callbacks.h | 4 +--- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/zypper-callbacks.cc b/src/zypper-callbacks.cc index a46ce3a..7f84607 100644 --- a/src/zypper-callbacks.cc +++ b/src/zypper-callbacks.cc @@ -1,10 +1,13 @@ -#include "AliveCursor.h" -#include "zypper.h" - #include #include +#include + +#include "AliveCursor.h" +#include "zypper.h" + using namespace std; +using namespace boost; void display_progress ( const std::string &id, ostream & out, const string& s, int percent) { static AliveCursor cursor; @@ -120,7 +123,6 @@ int read_action_ari (int default_action) { // ---------------------------------------------------------------------------- -// Read an answer (ynYN) bool read_bool_answer(const string & question, bool default_answer) { if (!gSettings.machine_readable) @@ -138,13 +140,37 @@ bool read_bool_answer(const string & question, bool default_answer) istream & stm = cin; string c = ""; - while (stm.good () && c != "y" && c != "Y" && c != "N" && c != "n") + bool been_here_before = false; + while (stm.good () + // TranslatorExplanation This is a Lowercase 'y' for "yes" used as an + // answer in y/n prompts. Translate to the same letter as you translated + // it in the "[y/n]" string!. + && c != _("y") + // TranslatorExplanation Uppercase 'Y' for "yes" used as an + // answer in y/n prompts. Translate to the same letter as you translated + // it in the "[y/n]" string!. + && c != _("Y") + // TranslatorExplanation Lowercase 'n' for "no" used as an + // answer in y/n prompts. Translate to the same letter as you translated + // it in the "[y/n]" string!. + && c != _("n") + // TranslatorExplanation Uppercase 'N' for "no" used as an + // answer in y/n prompts. Translate to the same letter as you translated + // it in the "[y/n]" string!. + && c != _("N")) + { + if (been_here_before) + // TranslatorExplanation Example: Invalid answer 'x', enter 'y' or 'n': + cerr << format(_("Invalid answer '%s', enter '%s' or '%s':")) + % c % _("y") % _("n") << " "; c = zypp::str::getline (stm, zypp::str::TRIM); + been_here_before = true; + } MIL << "answer: " << c << endl; - if (c == "y" || c == "Y") + if (c == _("y") || c == _("Y")) return true; - else if (c == "n" || c == "N") + else if (c == _("n") || c == _("N")) return false; else { diff --git a/src/zypper-callbacks.h b/src/zypper-callbacks.h index 500c081..396a9ad 100644 --- a/src/zypper-callbacks.h +++ b/src/zypper-callbacks.h @@ -56,13 +56,11 @@ void display_error (Error error, const std::string& reason) { int read_action_ari (int default_action = -1); /** - * Prompt for Yes/No answer from stdin. + * Prompt for y/n answer (localized) from stdin. * * \param question Question to be printed on prompt. * \param default_answer Value to be returned in non-interactive mode or on * input failure. - * - * \todo make this localized */ bool read_bool_answer(const string & question, bool default_answer); -- 2.7.4