mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-27 00:57:19 +02:00
TW-1655: Inform "No changes made." when quitting early due to signal
- Thanks to Daniel Shahaf.
This commit is contained in:
parent
5059897b50
commit
27fd8910ae
11 changed files with 30 additions and 0 deletions
18
src/util.cpp
18
src/util.cpp
|
@ -45,6 +45,7 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <pwd.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
@ -58,6 +59,16 @@
|
|||
|
||||
extern Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void signal_handler (int s)
|
||||
{
|
||||
if (s == SIGINT)
|
||||
{
|
||||
std::cout << "\n\n" << STRING_ERROR_CONFIRM_SIGINT << "\n";
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
|
@ -69,6 +80,8 @@ bool confirm (const std::string& question)
|
|||
STRING_UTIL_CONFIRM_NO};
|
||||
std::vector <std::string> matches;
|
||||
|
||||
signal (SIGINT, signal_handler);
|
||||
|
||||
do
|
||||
{
|
||||
std::cout << question
|
||||
|
@ -83,6 +96,7 @@ bool confirm (const std::string& question)
|
|||
}
|
||||
while (! std::cin.eof () && matches.size () != 1);
|
||||
|
||||
signal (SIGINT, SIG_DFL);
|
||||
return matches.size () == 1 && matches[0] == STRING_UTIL_CONFIRM_YES ? true : false;
|
||||
}
|
||||
|
||||
|
@ -101,6 +115,8 @@ int confirm4 (const std::string& question)
|
|||
STRING_UTIL_CONFIRM_QUIT};
|
||||
std::vector <std::string> matches;
|
||||
|
||||
signal (SIGINT, signal_handler);
|
||||
|
||||
do
|
||||
{
|
||||
std::cout << question
|
||||
|
@ -119,6 +135,8 @@ int confirm4 (const std::string& question)
|
|||
}
|
||||
while (! std::cin.eof () && matches.size () != 1);
|
||||
|
||||
signal (SIGINT, SIG_DFL);
|
||||
|
||||
if (matches.size () == 1)
|
||||
{
|
||||
if (matches[0] == STRING_UTIL_CONFIRM_YES_U) return 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue