Display a message on the tty directly on fatal error

Remove the xmessage/MessageBox based implementation.
This commit is contained in:
Maxime Coste 2023-11-02 18:16:43 +11:00
parent a2c41593aa
commit ba0cd553ba

View File

@ -4,13 +4,9 @@
#include "buffer_utils.hh" #include "buffer_utils.hh"
#include "exception.hh" #include "exception.hh"
#if defined(__CYGWIN__)
#include <windows.h>
#endif
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <cstdlib> #include <signal.h>
namespace Kakoune namespace Kakoune
{ {
@ -27,16 +23,17 @@ private:
bool notify_fatal_error(StringView msg) bool notify_fatal_error(StringView msg)
{ {
#if defined(__CYGWIN__) if (not isatty(STDOUT_FILENO) or not isatty(STDIN_FILENO))
return MessageBox(NULL, msg.zstr(), "Kakoune: fatal error", return false;
MB_OKCANCEL | MB_ICONERROR) == IDOK;
#elif defined(__linux__) write(STDOUT_FILENO, format("\033[;31;5;1mKakoune fatal error, q: exit, i: ignore or debug pid {}\033[0m", getpid()));
auto cmd = format("xmessage -buttons 'quit:0,ignore:1' '{}'", replace(msg, "'", "'\\''")); while (true)
int status = system(cmd.c_str()); {
return (WIFEXITED(status)) ? (WEXITSTATUS(status)) == 1 : false; if (unsigned char c = 0; read(STDIN_FILENO, &c, 1) < 0 or c == 'q')
#else return false;
return false; else if (c == 'i')
#endif return true;
}
} }
void on_assert_failed(const char* message) void on_assert_failed(const char* message)