const std::string & prompt,
const PromptOptions & poptions,
const std::string & startdesc = "") = 0;
+
+ virtual void promptHelp(const PromptOptions & poptions) = 0;
public:
/** Get current verbosity. */
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;
}
const PromptOptions & poptions,
const std::string & startdesc = "");
+ virtual void promptHelp(const PromptOptions & poptions);
+
protected:
virtual bool mine(Type type);
cout << "<text>" << xml_encode(prompt) << "</text>" << 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 << "<option";
if (poptions.defaultOpt() == i)
cout << " default=\"1\"";
cout << " value=\"" << xml_encode(option) << "\"";
+ cout << " desc=\"" << xml_encode(poptions.optionHelp(i)) << "\"";
cout << "/>" << endl;
}
cout << "</prompt>" << endl;
}
+
+void OutXML::promptHelp(const PromptOptions & poptions)
+{
+ // nothing to do here
+}
const PromptOptions & poptions,
const std::string & startdesc = "");
+ virtual void promptHelp(const PromptOptions & poptions);
+
protected:
virtual bool mine(Type type);
// 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);
_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"))};
default_action = 0;
}
- out.info (_("Abort,retry, ignore?\n"));
+ out.info (_("Abort, retry, ignore?\n"));
//FIXME XML output
cout << endl;
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()))
}
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;
class PromptOptions
{
public:
- typedef std::vector<std::string> OptionList;
+ typedef std::vector<std::string> StrVector;
/**
* Default c-tor.
/** 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;
};