summaryrefslogtreecommitdiff
path: root/tools/perf/util/ui/setup.c
blob: 1e6ba06980c4093248915077bdeb437d05098feb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <newt.h>
#include <signal.h>
#include <stdbool.h>

#include "../cache.h"
#include "../debug.h"
#include "browser.h"
#include "helpline.h"
#include "ui.h"
#include "libslang.h"

pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;

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

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;
}

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);
}

void setup_browser(bool fallback_to_pager)
{
	if (!isatty(1) || !use_browser || dump_trace) {
		use_browser = 0;
		if (fallback_to_pager)
			setup_pager();
		return;
	}

	use_browser = 1;
	newtInit();
	ui__init();
	newtSetSuspendCallback(newt_suspend, NULL);
	ui_helpline__init();
	ui_browser__init();

	signal(SIGSEGV, ui__signal);
	signal(SIGFPE, ui__signal);
	signal(SIGINT, ui__signal);
	signal(SIGQUIT, ui__signal);
	signal(SIGTERM, ui__signal);
}

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