Add signal handler to show cursor after ^C

This commit is contained in:
Bob Polis 2023-10-05 16:41:01 +02:00
parent ab7e3c1d32
commit 2fb1c801a0

View File

@ -14,11 +14,17 @@
#include <memory> #include <memory>
#include <thread> #include <thread>
#include <getopt.h> #include <getopt.h>
#include <signal.h>
#include <sqlite3.h> #include <sqlite3.h>
#include <sc/integer_locale.hpp> #include <sc/integer_locale.hpp>
#include "robinsonizer_mode.hpp" #include "robinsonizer_mode.hpp"
#include "engine.hpp" #include "engine.hpp"
void reset_term(int sig) {
std::cerr << "\nbreak\n\x1b[?25h"; // show cursor again
exit(0);
}
void print_help() { void print_help() {
std::cout << "usage: autogram [-h|--version] "; std::cout << "usage: autogram [-h|--version] ";
std::cout << "[-a <relaxed|strict|pangram] "; std::cout << "[-a <relaxed|strict|pangram] ";
@ -67,6 +73,11 @@ void read_nums_from_db(std::vector<std::string>& numerals, const std::string& db
int main(int argc, const char * argv[]) { int main(int argc, const char * argv[]) {
try { try {
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = reset_term;
(void) sigaction(SIGINT, &sa, NULL);
robinsonizer_mode mode {robinsonizer_mode::lax_autogram}; robinsonizer_mode mode {robinsonizer_mode::lax_autogram};
std::string lang {"en"}; std::string lang {"en"};
std::string start; std::string start;