Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 1 | #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 Melo | 5c35d69 | 2011-02-09 11:38:43 -0200 | [diff] [blame] | 9 | #include "ui.h" |
Arnaldo Carvalho de Melo | 3f7247e | 2011-10-18 13:45:16 -0200 | [diff] [blame] | 10 | #include "libslang.h" |
Arnaldo Carvalho de Melo | 5c35d69 | 2011-02-09 11:38:43 -0200 | [diff] [blame] | 11 | |
| 12 | pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER; |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 13 | |
| 14 | static void newt_suspend(void *d __used) |
| 15 | { |
| 16 | newtSuspend(); |
| 17 | raise(SIGTSTP); |
| 18 | newtResume(); |
| 19 | } |
| 20 | |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 21 | static 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); |
| 29 | out: |
| 30 | return err; |
| 31 | } |
| 32 | |
Arnaldo Carvalho de Melo | 3f7247e | 2011-10-18 13:45:16 -0200 | [diff] [blame] | 33 | static void ui__exit(void) |
| 34 | { |
| 35 | SLtt_set_cursor_visibility(1); |
| 36 | SLsmg_refresh(); |
| 37 | SLsmg_reset_smg(); |
| 38 | SLang_reset_tty(); |
| 39 | } |
| 40 | |
| 41 | static void ui__signal(int sig) |
| 42 | { |
| 43 | ui__exit(); |
| 44 | psignal(sig, "perf"); |
| 45 | exit(0); |
| 46 | } |
| 47 | |
Arnaldo Carvalho de Melo | 229ade9 | 2011-01-31 18:08:39 -0200 | [diff] [blame] | 48 | void setup_browser(bool fallback_to_pager) |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 49 | { |
| 50 | if (!isatty(1) || !use_browser || dump_trace) { |
| 51 | use_browser = 0; |
Arnaldo Carvalho de Melo | 229ade9 | 2011-01-31 18:08:39 -0200 | [diff] [blame] | 52 | if (fallback_to_pager) |
| 53 | setup_pager(); |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 54 | return; |
| 55 | } |
| 56 | |
| 57 | use_browser = 1; |
| 58 | newtInit(); |
Arnaldo Carvalho de Melo | cf95800 | 2011-10-20 16:59:15 -0200 | [diff] [blame] | 59 | ui__init(); |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 60 | newtSetSuspendCallback(newt_suspend, NULL); |
| 61 | ui_helpline__init(); |
| 62 | ui_browser__init(); |
Arnaldo Carvalho de Melo | 3f7247e | 2011-10-18 13:45:16 -0200 | [diff] [blame] | 63 | |
| 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 Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void 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 Melo | 3f7247e | 2011-10-18 13:45:16 -0200 | [diff] [blame] | 78 | ui__exit(); |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 79 | } |
| 80 | } |