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:
Paul Beckingham 2009-06-23 14:56:15 -04:00
parent acb6e3cfdc
commit b6bc72c449
2 changed files with 35 additions and 0 deletions

View file

@ -74,6 +74,40 @@ bool confirm (const std::string& question)
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)
{