2010-08-11 02:58:50 +08:00
|
|
|
#include <newt.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include "../cache.h"
|
|
|
|
#include "../debug.h"
|
|
|
|
#include "browser.h"
|
|
|
|
#include "helpline.h"
|
2011-02-09 21:38:43 +08:00
|
|
|
#include "ui.h"
|
2011-10-18 23:45:16 +08:00
|
|
|
#include "libslang.h"
|
2011-02-09 21:38:43 +08:00
|
|
|
|
|
|
|
pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
|
2010-08-11 02:58:50 +08:00
|
|
|
|
|
|
|
static void newt_suspend(void *d __used)
|
|
|
|
{
|
|
|
|
newtSuspend();
|
|
|
|
raise(SIGTSTP);
|
|
|
|
newtResume();
|
|
|
|
}
|
|
|
|
|
2011-10-18 23:45:16 +08:00
|
|
|
static void ui__exit(void)
|
|
|
|
{
|
|
|
|
SLtt_set_cursor_visibility(1);
|
|
|
|
SLsmg_refresh();
|
|
|
|
SLsmg_reset_smg();
|
|
|
|
SLang_reset_tty();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui__signal(int sig)
|
|
|
|
{
|
|
|
|
ui__exit();
|
|
|
|
psignal(sig, "perf");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2011-02-01 04:08:39 +08:00
|
|
|
void setup_browser(bool fallback_to_pager)
|
2010-08-11 02:58:50 +08:00
|
|
|
{
|
|
|
|
if (!isatty(1) || !use_browser || dump_trace) {
|
|
|
|
use_browser = 0;
|
2011-02-01 04:08:39 +08:00
|
|
|
if (fallback_to_pager)
|
|
|
|
setup_pager();
|
2010-08-11 02:58:50 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
use_browser = 1;
|
|
|
|
newtInit();
|
|
|
|
newtSetSuspendCallback(newt_suspend, NULL);
|
|
|
|
ui_helpline__init();
|
|
|
|
ui_browser__init();
|
2011-10-18 23:45:16 +08:00
|
|
|
|
|
|
|
signal(SIGSEGV, ui__signal);
|
|
|
|
signal(SIGFPE, ui__signal);
|
|
|
|
signal(SIGINT, ui__signal);
|
|
|
|
signal(SIGQUIT, ui__signal);
|
|
|
|
signal(SIGTERM, ui__signal);
|
2010-08-11 02:58:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void exit_browser(bool wait_for_ok)
|
|
|
|
{
|
|
|
|
if (use_browser > 0) {
|
|
|
|
if (wait_for_ok) {
|
|
|
|
char title[] = "Fatal Error", ok[] = "Ok";
|
|
|
|
newtWinMessage(title, ok, ui_helpline__last_msg);
|
|
|
|
}
|
2011-10-18 23:45:16 +08:00
|
|
|
ui__exit();
|
2010-08-11 02:58:50 +08:00
|
|
|
}
|
|
|
|
}
|