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"
9#include "ui.h"
10
11pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
12
13static void newt_suspend(void *d __used)
14{
15	newtSuspend();
16	raise(SIGTSTP);
17	newtResume();
18}
19
20void setup_browser(bool fallback_to_pager)
21{
22	if (!isatty(1) || !use_browser || dump_trace) {
23		use_browser = 0;
24		if (fallback_to_pager)
25			setup_pager();
26		return;
27	}
28
29	use_browser = 1;
30	newtInit();
31	newtCls();
32	newtSetSuspendCallback(newt_suspend, NULL);
33	ui_helpline__init();
34	ui_browser__init();
35}
36
37void exit_browser(bool wait_for_ok)
38{
39	if (use_browser > 0) {
40		if (wait_for_ok) {
41			char title[] = "Fatal Error", ok[] = "Ok";
42			newtWinMessage(title, ok, ui_helpline__last_msg);
43		}
44		newtFinished();
45	}
46}
47