ref: refs/heads/master
commit 2b79bbe5033fe8288cf43bcbfbd0d14f1ae0477c
Author: Ján Kupec
Date: Fri Mar 6 20:43:17 2009 +0100
Fixed uninitialized _shown_count in prompt.
---
src/utils/prompt.cc | 17 +++++++++++------
src/utils/prompt.h | 8 ++++----
2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/src/utils/prompt.cc b/src/utils/prompt.cc
index 95b8fd9..1e9c4de 100644
--- a/src/utils/prompt.cc
+++ b/src/utils/prompt.cc
@@ -31,6 +31,7 @@ using namespace boost;
// ----------------------------------------------------------------------------
PromptOptions::PromptOptions(const std::string & option_str, unsigned int default_opt)
+ : _shown_count(-1)
{
setOptions(option_str, default_opt);
}
@@ -60,7 +61,9 @@ const string PromptOptions::optionString() const
{
ostringstream option_str;
StrVector::const_iterator it;
- if ((it = options().begin()) != options().end())
+ unsigned int shown_count = _shown_count < 0 ? options().size() : _shown_count;
+
+ if ((it = options().begin()) != options().end() && shown_count > 0)
{
if (defaultOpt() == 0)
option_str << "_" << *it << "_";
@@ -68,7 +71,7 @@ const string PromptOptions::optionString() const
option_str << *it;
++it;
}
- for (unsigned int i = 1; it != options().end() && i < _shown_count; ++it, ++i)
+ for (unsigned int i = 1; it != options().end() && i < shown_count; ++it, ++i)
if (isEnabled(i))
{
option_str << "/";
@@ -79,7 +82,7 @@ const string PromptOptions::optionString() const
}
if (!_opt_help.empty())
- option_str << "/?";
+ option_str << (shown_count > 0 ? "/" : "") << "?";
return option_str.str();
}
@@ -88,7 +91,9 @@ const string PromptOptions::optionStringColored() const
{
ostringstream option_str;
StrVector::const_iterator it;
- if ((it = options().begin()) != options().end())
+ unsigned int shown_count = _shown_count < 0 ? options().size() : _shown_count;
+
+ if ((it = options().begin()) != options().end() && shown_count > 0)
{
if (defaultOpt() == 0)
option_str << COLOR_YELLOW << *it;
@@ -96,7 +101,7 @@ const string PromptOptions::optionStringColored() const
option_str << COLOR_WHITE << *it;
++it;
}
- for (unsigned int i = 1; it != options().end() && i < _shown_count; ++it, ++i)
+ for (unsigned int i = 1; it != options().end() && i < shown_count; ++it, ++i)
if (isEnabled(i))
{
option_str << COLOR_WHITE << "/";
@@ -107,7 +112,7 @@ const string PromptOptions::optionStringColored() const
}
if (!_opt_help.empty())
- option_str << COLOR_WHITE << "/?";
+ option_str << COLOR_WHITE << (shown_count > 0 ? "/" : "") << "?";
option_str << COLOR_RESET;
diff --git a/src/utils/prompt.h b/src/utils/prompt.h
index 6ef5bdc..1e18dac 100644
--- a/src/utils/prompt.h
+++ b/src/utils/prompt.h
@@ -34,7 +34,7 @@ public:
/**
* Default c-tor.
*/
- PromptOptions() {};
+ PromptOptions() : _shown_count(-1) {};
/**
* Constructor.
@@ -91,10 +91,10 @@ private:
/** set of options to ignore */
std::set<unsigned int> _disabled;
/**
- * number of options to show (the rest will still be available and visible
- * through '?' help)
+ * Number of options to show (the rest will still be available and visible
+ * through '?' help). If negative, all options will be shown. Zero is allowed.
*/
- unsigned int _shown_count;
+ int _shown_count;
};
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org