mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Bug Fix - confirmation not processing newline
- Fixed bug where util.cpp:confirm was eating newlines, and not rewriting the prompt. Consequently, after confirm asked the question, and the user hit <Enter>, nothing was displayed but the newline. Now uses std::getline.
This commit is contained in:
parent
cc2220b406
commit
74ea5b4ef6
1 changed files with 17 additions and 6 deletions
23
src/util.cpp
23
src/util.cpp
|
@ -41,17 +41,28 @@
|
|||
#include "../auto.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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 disply the newline. This way, with
|
||||
// std::getline, the newline can be detected, and the prompt re-written.
|
||||
bool confirm (const std::string& question)
|
||||
{
|
||||
std::cout << question << " (y/n) ";
|
||||
std::string answer;
|
||||
std::cin >> answer;
|
||||
|
||||
answer = trim (answer);
|
||||
if (answer == "y" || answer == "Y")
|
||||
return true;
|
||||
do
|
||||
{
|
||||
std::cout << question << " (y/n) ";
|
||||
std::getline (std::cin, answer);
|
||||
answer = lowerCase (trim (answer));
|
||||
if (answer == "\n") std::cout << "newline\n";
|
||||
}
|
||||
while (answer != "y" &&
|
||||
answer != "ye" &&
|
||||
answer != "yes" &&
|
||||
answer != "n" &&
|
||||
answer != "no");
|
||||
|
||||
return false;
|
||||
return (answer == "y" || answer == "ye" || answer == "yes") ? true : false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue