mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
util: Removed confirm
This commit is contained in:
parent
c12deb535e
commit
6cdb0d4b95
6 changed files with 4 additions and 36 deletions
|
@ -29,7 +29,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Filter.h>
|
#include <Filter.h>
|
||||||
#include <util.h>
|
#include <shared.h>
|
||||||
#include <format.h>
|
#include <format.h>
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include <Filter.h>
|
#include <Filter.h>
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
#include <format.h>
|
#include <format.h>
|
||||||
#include <util.h>
|
#include <shared.h>
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Filter.h>
|
#include <Filter.h>
|
||||||
#include <util.h>
|
#include <shared.h>
|
||||||
#include <format.h>
|
#include <format.h>
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
#include <format.h>
|
#include <format.h>
|
||||||
#include <util.h>
|
#include <shared.h>
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
|
||||||
|
|
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
|
// 0 = no
|
||||||
// 1 = yes
|
// 1 = yes
|
||||||
|
|
|
@ -40,7 +40,6 @@
|
||||||
#include <Task.h>
|
#include <Task.h>
|
||||||
|
|
||||||
// util.cpp
|
// util.cpp
|
||||||
bool confirm (const std::string&);
|
|
||||||
int confirm4 (const std::string&);
|
int confirm4 (const std::string&);
|
||||||
|
|
||||||
#ifndef HAVE_UUID_UNPARSE_LOWER
|
#ifndef HAVE_UUID_UNPARSE_LOWER
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue