Enhancement - confirm3
- Added a tri-state confirmation function for confirming bulk operations allowing the user to answer yes/no/all to and optionally allow, disallow or bulk-allow big changes.
This commit is contained in:
34
src/util.cpp
34
src/util.cpp
@@ -74,6 +74,40 @@ bool confirm (const std::string& question)
|
|||||||
return (answer == "y" || answer == "ye" || answer == "yes") ? true : false; // TODO i18n
|
return (answer == "y" || answer == "ye" || answer == "yes") ? true : false; // TODO i18n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 0 = no
|
||||||
|
// 1 = yes
|
||||||
|
// 2 = all
|
||||||
|
int confirm3 (const std::string& question)
|
||||||
|
{
|
||||||
|
std::vector <std::string> options;
|
||||||
|
options.push_back ("yes");
|
||||||
|
options.push_back ("no");
|
||||||
|
options.push_back ("all");
|
||||||
|
|
||||||
|
std::string answer;
|
||||||
|
std::vector <std::string> matches;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
std::cout << question
|
||||||
|
<< " ("
|
||||||
|
<< options[0] << "/"
|
||||||
|
<< options[1] << "/"
|
||||||
|
<< options[2]
|
||||||
|
<< ") ";
|
||||||
|
|
||||||
|
std::getline (std::cin, answer);
|
||||||
|
answer = trim (answer);
|
||||||
|
autoComplete (answer, options, matches);
|
||||||
|
}
|
||||||
|
while (matches.size () != 1);
|
||||||
|
|
||||||
|
if (matches[0] == "yes") return 1;
|
||||||
|
else if (matches[0] == "all") return 2;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void delay (float f)
|
void delay (float f)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ for (typeof (c) *foreach_p = & (c); \
|
|||||||
|
|
||||||
// util.cpp
|
// util.cpp
|
||||||
bool confirm (const std::string&);
|
bool confirm (const std::string&);
|
||||||
|
int confirm3 (const std::string&);
|
||||||
void delay (float);
|
void delay (float);
|
||||||
std::string formatSeconds (time_t);
|
std::string formatSeconds (time_t);
|
||||||
std::string formatSecondsCompact (time_t);
|
std::string formatSecondsCompact (time_t);
|
||||||
|
|||||||
Reference in New Issue
Block a user