blob: 8b8a57b455601805d31f36eca7f1ae332be5b412 [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 Melo3f7247e2011-10-18 13:45:16 -020021static void ui__exit(void)
22{
23 SLtt_set_cursor_visibility(1);
24 SLsmg_refresh();
25 SLsmg_reset_smg();
26 SLang_reset_tty();
27}
28
29static void ui__signal(int sig)
30{
31 ui__exit();
32 psignal(sig, "perf");
33 exit(0);
34}
35
Arnaldo Carvalho de Melo229ade92011-01-31 18:08:39 -020036void setup_browser(bool fallback_to_pager)
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030037{
38 if (!isatty(1) || !use_browser || dump_trace) {
39 use_browser = 0;
Arnaldo Carvalho de Melo229ade92011-01-31 18:08:39 -020040 if (fallback_to_pager)
41 setup_pager();
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030042 return;
43 }
44
45 use_browser = 1;
46 newtInit();
47 newtCls();
48 newtSetSuspendCallback(newt_suspend, NULL);
49 ui_helpline__init();
50 ui_browser__init();
Arnaldo Carvalho de Melo3f7247e2011-10-18 13:45:16 -020051
52 signal(SIGSEGV, ui__signal);
53 signal(SIGFPE, ui__signal);
54 signal(SIGINT, ui__signal);
55 signal(SIGQUIT, ui__signal);
56 signal(SIGTERM, ui__signal);
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030057}
58
59void exit_browser(bool wait_for_ok)
60{
61 if (use_browser > 0) {
62 if (wait_for_ok) {
63 char title[] = "Fatal Error", ok[] = "Ok";
64 newtWinMessage(title, ok, ui_helpline__last_msg);
65 }
Arnaldo Carvalho de Melo3f7247e2011-10-18 13:45:16 -020066 ui__exit();
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030067 }
68}