xref: /linux/tools/perf/ui/setup.c (revision 21f0d423b989284f82004d0f80c75581fec91fb2)
1aca7a94dSNamhyung Kim #include "../cache.h"
2aca7a94dSNamhyung Kim #include "../debug.h"
3aca7a94dSNamhyung Kim 
4aca7a94dSNamhyung Kim 
5aca7a94dSNamhyung Kim void setup_browser(bool fallback_to_pager)
6aca7a94dSNamhyung Kim {
7281ef544SNamhyung Kim 	if (!isatty(1) || dump_trace)
8aca7a94dSNamhyung Kim 		use_browser = 0;
9281ef544SNamhyung Kim 
10281ef544SNamhyung Kim 	/* default to TUI */
11281ef544SNamhyung Kim 	if (use_browser < 0)
12281ef544SNamhyung Kim 		use_browser = 1;
13281ef544SNamhyung Kim 
14281ef544SNamhyung Kim 	switch (use_browser) {
15281ef544SNamhyung Kim 	case 2:
16dc41b9b8SNamhyung Kim 		if (perf_gtk__init() == 0)
17281ef544SNamhyung Kim 			break;
18dc41b9b8SNamhyung Kim 		/* fall through */
19281ef544SNamhyung Kim 	case 1:
20dc41b9b8SNamhyung Kim 		use_browser = 1;
21dc41b9b8SNamhyung Kim 		if (ui__init() == 0)
22281ef544SNamhyung Kim 			break;
23dc41b9b8SNamhyung Kim 		/* fall through */
24281ef544SNamhyung Kim 	default:
25*21f0d423SNamhyung Kim 		use_browser = 0;
26aca7a94dSNamhyung Kim 		if (fallback_to_pager)
27aca7a94dSNamhyung Kim 			setup_pager();
28281ef544SNamhyung Kim 		break;
29aca7a94dSNamhyung Kim 	}
30aca7a94dSNamhyung Kim }
31aca7a94dSNamhyung Kim 
32aca7a94dSNamhyung Kim void exit_browser(bool wait_for_ok)
33aca7a94dSNamhyung Kim {
34281ef544SNamhyung Kim 	switch (use_browser) {
35281ef544SNamhyung Kim 	case 2:
36281ef544SNamhyung Kim 		perf_gtk__exit(wait_for_ok);
37281ef544SNamhyung Kim 		break;
38281ef544SNamhyung Kim 
39281ef544SNamhyung Kim 	case 1:
40281ef544SNamhyung Kim 		ui__exit(wait_for_ok);
41281ef544SNamhyung Kim 		break;
42281ef544SNamhyung Kim 
43281ef544SNamhyung Kim 	default:
44281ef544SNamhyung Kim 		break;
45aca7a94dSNamhyung Kim 	}
46aca7a94dSNamhyung Kim }
47