From: Jan Kupec Date: Sat, 26 Apr 2008 20:40:58 +0000 (+0000) Subject: - added support for prompt help X-Git-Tag: BASE-SuSE-Linux-11_0-Branch~123 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=47537a111a1d36b83e90d28fd9f586e8cea4b40f;p=platform%2Fupstream%2Fzypper.git - added support for prompt help - added help for Continue? [y/n/p/?] prompt --- diff --git a/src/output/Out.h b/src/output/Out.h index 98b23ee..6c0c05d 100644 --- a/src/output/Out.h +++ b/src/output/Out.h @@ -225,6 +225,8 @@ public: const std::string & prompt, const PromptOptions & poptions, const std::string & startdesc = "") = 0; + + virtual void promptHelp(const PromptOptions & poptions) = 0; public: /** Get current verbosity. */ diff --git a/src/output/OutNormal.cc b/src/output/OutNormal.cc index 261c270..63b5660 100644 --- a/src/output/OutNormal.cc +++ b/src/output/OutNormal.cc @@ -235,19 +235,33 @@ void OutNormal::prompt(PromptId id, const PromptOptions & poptions, const std::string & startdesc) { - string option_str; - PromptOptions::OptionList::const_iterator it; - if ((it = poptions.options().begin()) != poptions.options().end()) - { - option_str += (poptions.defaultOpt() == 0 ? zypp::str::toUpper(*it) : *it); - ++it; - } - for (unsigned int i = 1; it != poptions.options().end(); ++it, i++) - option_str += "/" + (poptions.defaultOpt() == i ? zypp::str::toUpper(*it) : *it); - if (startdesc.empty()) cout << CLEARLN; else cout << startdesc << endl; - cout << prompt << " [" << option_str << "]: " << std::flush; + cout << prompt << " [" << poptions.optionString() << "]: " << std::flush; +} + +void OutNormal::promptHelp(const PromptOptions & poptions) +{ + cout << endl; + if (poptions.helpEmpty()) + cout << _("No help available for this prompt.") << endl; + else + { + unsigned int pos = 0; + for(PromptOptions::StrVector::const_iterator it = poptions.options().begin(); + it != poptions.options().end(); ++it, ++pos) + { + cout << *it << " - "; + const string & hs_r = poptions.optionHelp(pos); + if (hs_r.empty()) + cout << "(" << _("no help available for this option") << ")"; + else + cout << hs_r; + cout << endl; + } + } + + cout << endl << "[" << poptions.optionString() << "]: " << std::flush; } diff --git a/src/output/OutNormal.h b/src/output/OutNormal.h index 2f3a7e7..1285295 100644 --- a/src/output/OutNormal.h +++ b/src/output/OutNormal.h @@ -58,6 +58,8 @@ public: const PromptOptions & poptions, const std::string & startdesc = ""); + virtual void promptHelp(const PromptOptions & poptions); + protected: virtual bool mine(Type type); diff --git a/src/output/OutXML.cc b/src/output/OutXML.cc index a59edea..c6f633e 100644 --- a/src/output/OutXML.cc +++ b/src/output/OutXML.cc @@ -197,15 +197,21 @@ void OutXML::prompt(PromptId id, cout << "" << xml_encode(prompt) << "" << endl; unsigned int i = 0; - for (PromptOptions::OptionList::const_iterator it = poptions.options().begin(); - it != poptions.options().end(); ++it, i++) + for (PromptOptions::StrVector::const_iterator it = poptions.options().begin(); + it != poptions.options().end(); ++it, ++i) { string option = *it; cout << "" << endl; } cout << "" << endl; } + +void OutXML::promptHelp(const PromptOptions & poptions) +{ + // nothing to do here +} diff --git a/src/output/OutXML.h b/src/output/OutXML.h index 97fd38a..45763e6 100644 --- a/src/output/OutXML.h +++ b/src/output/OutXML.h @@ -42,6 +42,8 @@ public: const PromptOptions & poptions, const std::string & startdesc = ""); + virtual void promptHelp(const PromptOptions & poptions); + protected: virtual bool mine(Type type); diff --git a/src/zypper-misc.cc b/src/zypper-misc.cc index f5dcca3..a7f5af2 100644 --- a/src/zypper-misc.cc +++ b/src/zypper-misc.cc @@ -2208,8 +2208,11 @@ void solve_and_commit (Zypper & zypper) // after install/update command summary if there will be any package // to-be-removed automatically to show why, if asked. popts.setOptions(_("y/n/p"), 0); + popts.setOptionHelp(0, _("Accept the summary and proceed with installation/removal of packages.")); + popts.setOptionHelp(1, _("Cancel the operation.")); + popts.setOptionHelp(2, _("Restart solver in no-force-resolution mode in order to show dependency problems.")); // translators: Translate 'p' to whathever you translated it in the y/n/p prompt text. - string prompt_text = _("Continue? (Choose 'p' to show dependency problems.)"); + string prompt_text = _("Continue?"); zypper.out().prompt(PROMPT_YN_INST_REMOVE_CONTINUE, prompt_text, popts); unsigned int reply = get_prompt_reply(zypper, PROMPT_YN_INST_REMOVE_CONTINUE, popts); diff --git a/src/zypper-prompt.cc b/src/zypper-prompt.cc index 8c7b7a9..9445928 100644 --- a/src/zypper-prompt.cc +++ b/src/zypper-prompt.cc @@ -40,6 +40,44 @@ void PromptOptions::setOptions(const std::string & option_str, unsigned int defa _default = default_opt; } +const string PromptOptions::optionString() const +{ + string option_str; + StrVector::const_iterator it; + if ((it = options().begin()) != options().end()) + { + option_str += (defaultOpt() == 0 ? zypp::str::toUpper(*it) : *it); + ++it; + } + for (unsigned int i = 1; it != options().end(); ++it, i++) + option_str += "/" + (defaultOpt() == i ? zypp::str::toUpper(*it) : *it); + + if (!_opt_help.empty()) + option_str += "/?"; + + return option_str; +} + +void PromptOptions::setOptionHelp(unsigned int opt, const std::string & help_str) +{ + if (help_str.empty()) + return; + + if (opt >= _options.size()) + { + WAR << "attempt to set option help for non-existing option." + << " text: " << help_str << endl; + return; + } + + if (opt >= _opt_help.capacity()) + _opt_help.reserve(_options.size()); + if (opt >= _opt_help.size()) + _opt_help.resize(_options.size()); + + _opt_help[opt] = help_str; +} + // ---------------------------------------------------------------------------- const std::string ari_mapping[] = { string(_("abort")),string(_("retry")),string(_("ignore"))}; @@ -54,7 +92,7 @@ int read_action_ari_with_timeout (PromptId pid, unsigned timeout, default_action = 0; } - out.info (_("Abort,retry, ignore?\n")); + out.info (_("Abort, retry, ignore?\n")); //FIXME XML output cout << endl; @@ -162,6 +200,12 @@ unsigned int get_prompt_reply(Zypper & zypper, if (reply.empty()) break; + if (reply == "?") + { + zypper.out().promptHelp(poptions); + continue; + } + if (is_yn_prompt && rpmatch(reply.c_str()) >= 0) { if (rpmatch(reply.c_str())) @@ -172,12 +216,12 @@ unsigned int get_prompt_reply(Zypper & zypper, } else { + DBG << " reply: " << reply << " (" << zypp::str::toLower(reply) << " lowercase)" << endl; bool got_valid_reply = false; for (unsigned int i = 0; i < poptions.options().size(); i++) { DBG << "index: " << i << " option: " - << poptions.options()[i] << " reply: " << reply - << " (" << zypp::str::toLower(reply) << " lowercase)" << endl; + << poptions.options()[i] << endl; if (poptions.options()[i] == zypp::str::toLower(reply)) { reply_int = i; diff --git a/src/zypper-prompt.h b/src/zypper-prompt.h index e775b60..c0f239d 100644 --- a/src/zypper-prompt.h +++ b/src/zypper-prompt.h @@ -7,7 +7,7 @@ class PromptOptions { public: - typedef std::vector OptionList; + typedef std::vector StrVector; /** * Default c-tor. @@ -27,13 +27,21 @@ public: /** D-tor */ ~PromptOptions(); - const OptionList & options() const { return _options; } + const StrVector & options() const { return _options; } void setOptions(const std::string & option_str, unsigned int default_opt); unsigned int defaultOpt() const { return _default; } + const std::string optionString() const; + + const std::string optionHelp(unsigned int opt) const + { static std::string empty; return opt < _opt_help.size() ? _opt_help[opt] : empty; } + //const std::string getOptionHelp(const std::string & opt_str); + void setOptionHelp(unsigned int opt, const std::string & help_str); + bool helpEmpty() const { return _opt_help.empty(); } private: - OptionList _options; + StrVector _options; unsigned int _default; + StrVector _opt_help; };