setup.c 1.3 KB
Newer Older
1 2 3 4 5 6 7 8
#include <newt.h>
#include <signal.h>
#include <stdbool.h>

#include "../cache.h"
#include "../debug.h"
#include "browser.h"
#include "helpline.h"
9
#include "ui.h"
10
#include "libslang.h"
11 12

pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
13 14 15 16 17 18 19 20

static void newt_suspend(void *d __used)
{
	newtSuspend();
	raise(SIGTSTP);
	newtResume();
}

21 22 23 24 25 26 27 28 29 30 31 32
static int ui__init(void)
{
	int err = SLkp_init();

	if (err < 0)
		goto out;

	SLkp_define_keysym((char *)"^(kB)", SL_KEY_UNTAB);
out:
	return err;
}

33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
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);
}

48
void setup_browser(bool fallback_to_pager)
49 50 51
{
	if (!isatty(1) || !use_browser || dump_trace) {
		use_browser = 0;
52 53
		if (fallback_to_pager)
			setup_pager();
54 55 56 57 58
		return;
	}

	use_browser = 1;
	newtInit();
59
	ui__init();
60 61 62
	newtSetSuspendCallback(newt_suspend, NULL);
	ui_helpline__init();
	ui_browser__init();
63 64 65 66 67 68

	signal(SIGSEGV, ui__signal);
	signal(SIGFPE, ui__signal);
	signal(SIGINT, ui__signal);
	signal(SIGQUIT, ui__signal);
	signal(SIGTERM, ui__signal);
69 70 71 72 73 74 75 76 77
}

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);
		}
78
		ui__exit();
79 80
	}
}