Extract xmessage/MessageBox support in a notify_fatal_error function
This commit is contained in:
parent
336df38237
commit
3c86484c4e
|
@ -25,6 +25,26 @@ private:
|
|||
String m_message;
|
||||
};
|
||||
|
||||
bool notify_fatal_error(const String& msg)
|
||||
{
|
||||
#if defined(__CYGWIN__)
|
||||
int res = MessageBox(NULL, msg.c_str(), "Kakoune: assert failed",
|
||||
MB_OKCANCEL | MB_ICONERROR);
|
||||
switch (res)
|
||||
{
|
||||
case IDCANCEL:
|
||||
return false;
|
||||
case IDOK:
|
||||
return true;
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
auto cmd = "xmessage -buttons 'quit:0,ignore:1' '" + msg + "'";
|
||||
if (system(cmd.c_str()) == 1)
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void on_assert_failed(const char* message)
|
||||
{
|
||||
char* callstack = Backtrace{}.desc();
|
||||
|
@ -33,23 +53,8 @@ void on_assert_failed(const char* message)
|
|||
write_debug(format("assert failed: '{}'\n{}", message, debug_info));
|
||||
|
||||
const auto msg = format("{}\n[Debug Infos]\n{}", message, debug_info);
|
||||
#if defined(__CYGWIN__)
|
||||
int res = MessageBox(NULL, msg.c_str(), "Kakoune: assert failed",
|
||||
MB_OKCANCEL | MB_ICONERROR);
|
||||
switch (res)
|
||||
{
|
||||
case IDCANCEL:
|
||||
throw assert_failed(message);
|
||||
case IDOK:
|
||||
return;
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
auto cmd = "xmessage -buttons 'quit:0,ignore:1' '" + msg + "'";
|
||||
if (system(cmd.c_str()) != 1)
|
||||
if (not notify_fatal_error(msg))
|
||||
throw assert_failed(msg);
|
||||
#else
|
||||
throw assert_failed(msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,11 @@
|
|||
namespace Kakoune
|
||||
{
|
||||
|
||||
class String;
|
||||
|
||||
// return true if user asked to ignore the error
|
||||
bool notify_fatal_error(const String& message);
|
||||
|
||||
void on_assert_failed(const char* message);
|
||||
|
||||
}
|
||||
|
|
|
@ -284,8 +284,10 @@ void signal_handler(int signal)
|
|||
if (signal != SIGTERM)
|
||||
{
|
||||
char* callstack = Backtrace{}.desc();
|
||||
write_stderr(format("Received {}, exiting.\nCallstack:\n{}", text, callstack));
|
||||
auto msg = format("Received {}, exiting.\nCallstack:\n{}", text, callstack);
|
||||
free(callstack);
|
||||
write_stderr(msg);
|
||||
notify_fatal_error(msg);
|
||||
}
|
||||
|
||||
if (Server::has_instance())
|
||||
|
|
Loading…
Reference in New Issue
Block a user