mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-27 00:57:19 +02:00
util: Removed confirm
This commit is contained in:
parent
c12deb535e
commit
6cdb0d4b95
6 changed files with 4 additions and 36 deletions
31
src/util.cpp
31
src/util.cpp
|
@ -69,37 +69,6 @@ static void signal_handler (int s)
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Uses std::getline, because std::cin eats leading whitespace, and that means
|
||||
// that if a newline is entered, std::cin eats it and never returns from the
|
||||
// "std::cin >> answer;" line, but it does display the newline. This way, with
|
||||
// std::getline, the newline can be detected, and the prompt re-written.
|
||||
bool confirm (const std::string& question)
|
||||
{
|
||||
std::vector <std::string> options {STRING_UTIL_CONFIRM_YES,
|
||||
STRING_UTIL_CONFIRM_NO};
|
||||
std::vector <std::string> matches;
|
||||
|
||||
signal (SIGINT, signal_handler);
|
||||
|
||||
do
|
||||
{
|
||||
std::cout << question
|
||||
<< STRING_UTIL_CONFIRM_YN;
|
||||
|
||||
std::string answer {""};
|
||||
std::getline (std::cin, answer);
|
||||
context.debug ("STDIN '" + answer + '\'');
|
||||
answer = std::cin.eof () ? STRING_UTIL_CONFIRM_NO : Lexer::lowerCase (Lexer::trim (answer));
|
||||
|
||||
autoComplete (answer, options, matches, 1); // Hard-coded 1.
|
||||
}
|
||||
while (! std::cin.eof () && matches.size () != 1);
|
||||
|
||||
signal (SIGINT, SIG_DFL);
|
||||
return matches.size () == 1 && matches[0] == STRING_UTIL_CONFIRM_YES ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 0 = no
|
||||
// 1 = yes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue