Skip to content
Snippets Groups Projects
Commit 67d07faf authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Added a pause-on-error option

pause is activated automatically if output runs in a terminal
parent d78598cd
No related branches found
No related tags found
No related merge requests found
......@@ -129,16 +129,20 @@ int main(int argc, char *argv[])
CLI::App app{"Pastis help"};
app.add_option("number,-n,--number", number, "Number of cells");//->required();
int threads=-1;
app.add_option("--threads", threads, "Number of Kokkos threads")->check(CLI::Range(1,std::numeric_limits<decltype(threads)>::max()));
std::string colorize="auto";
app.add_set("--colorize", colorize, {"auto", "yes", "no"}, "Colorize console output", true);
bool disable_fpe = false;
app.add_flag("--no-fpe", disable_fpe, "Do not trap floating point exceptions");
bool disable_signals = false;
app.add_flag("--no-signal", disable_signals, "Do not catches signals");
std::string colorize="auto";
app.add_set("--colorize", colorize, {"auto", "yes", "no"}, "Colorize console output", true);
int threads=-1;
app.add_option("--threads", threads, "Number of Kokkos threads")->check(CLI::Range(1,std::numeric_limits<decltype(threads)>::max()));
std::string pause_on_error="auto";
app.add_set("--pause-on-error", pause_on_error, {"auto", "yes", "no"}, "Pause for debugging on unexpected error", true);
std::atexit([](){std::cout << rang::style::reset;});
try {
......@@ -149,6 +153,7 @@ int main(int argc, char *argv[])
ConsoleManager::init(colorize);
FPEManager::init(not disable_fpe);
SignalManager::setPauseForDebug(pause_on_error);
SignalManager::init(not disable_signals);
}
......
#include <SignalManager.hpp>
#include <ConsoleManager.hpp>
#include <csignal>
#include <rang.hpp>
#include <iomanip>
#warning must create a specific class for pausing and use enum class
#include <string>
std::string SignalManager::s_pause_on_error = "auto";
void SignalManager::setPauseForDebug(const std::string& pause_on_error)
{
s_pause_on_error = pause_on_error;
}
std::string SignalManager::signalName(int s)
{
switch (s) {
......@@ -53,8 +62,14 @@ void SignalManager::handler(int s)
<< rang::style::reset
<< " ***\n";
if ((ConsoleManager::isTerminal(std::cout) and
(s_pause_on_error == "auto")) or
(s_pause_on_error == "yes")) {
std::signal(SIGINT, SIG_DFL);
SignalManager::pauseForDebug();
} else {
std::exit(0);
}
}
void SignalManager::init(const bool& enable)
......
......@@ -6,10 +6,12 @@
struct SignalManager
{
private:
static std::string s_pause_on_error;
static std::string signalName(int signal);
static void pauseForDebug();
static void handler(int signal);
public:
static void setPauseForDebug(const std::string& pause_on_error);
static void init(const bool& enable);
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment