blob: 1e6ba06980c4093248915077bdeb437d05098feb [file] [log] [blame]
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -03001#include <newt.h>
2#include <signal.h>
3#include <stdbool.h>
4
5#include "../cache.h"
6#include "../debug.h"
7#include "browser.h"
8#include "helpline.h"
Arnaldo Carvalho de Melo5c35d692011-02-09 11:38:43 -02009#include "ui.h"
Arnaldo Carvalho de Melo3f7247e2011-10-18 13:45:16 -020010#include "libslang.h"
Arnaldo Carvalho de Melo5c35d692011-02-09 11:38:43 -020011
12pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030013
14static void newt_suspend(void *d __used)
15{
16 newtSuspend();
17 raise(SIGTSTP);
18 newtResume();
19}
20
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -020021static int ui__init(void)
22{
23 int err = SLkp_init();
24
25 if (err < 0)
26 goto out;
27
28 SLkp_define_keysym((char *)"^(kB)", SL_KEY_UNTAB);
29out:
30 return err;
31}
32
Arnaldo Carvalho de Melo3f7247e2011-10-18 13:45:16 -020033static void ui__exit(void)
34{
35 SLtt_set_cursor_visibility(1);
36 SLsmg_refresh();
37 SLsmg_reset_smg();
38 SLang_reset_tty();
39}
40
41static void ui__signal(int sig)
42{
43 ui__exit();
44 psignal(sig, "perf");
45 exit(0);
46}
47
Arnaldo Carvalho de Melo229ade92011-01-31 18:08:39 -020048void setup_browser(bool fallback_to_pager)
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030049{
50 if (!isatty(1) || !use_browser || dump_trace) {
51 use_browser = 0;
Arnaldo Carvalho de Melo229ade92011-01-31 18:08:39 -020052 if (fallback_to_pager)
53 setup_pager();
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030054 return;
55 }
56
57 use_browser = 1;
58 newtInit();
Arnaldo Carvalho de Melocf958002011-10-20 16:59:15 -020059 ui__init();
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030060 newtSetSuspendCallback(newt_suspend, NULL);
61 ui_helpline__init();
62 ui_browser__init();
Arnaldo Carvalho de Melo3f7247e2011-10-18 13:45:16 -020063
64 signal(SIGSEGV, ui__signal);
65 signal(SIGFPE, ui__signal);
66 signal(SIGINT, ui__signal);
67 signal(SIGQUIT, ui__signal);
68 signal(SIGTERM, ui__signal);
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030069}
70
71void exit_browser(bool wait_for_ok)
72{
73 if (use_browser > 0) {
74 if (wait_for_ok) {
75 char title[] = "Fatal Error", ok[] = "Ok";
76 newtWinMessage(title, ok, ui_helpline__last_msg);
77 }
Arnaldo Carvalho de Melo3f7247e2011-10-18 13:45:16 -020078 ui__exit();
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030079 }
80}