setup.c 826 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <newt.h>
  2. #include <signal.h>
  3. #include <stdbool.h>
  4. #include "../cache.h"
  5. #include "../debug.h"
  6. #include "browser.h"
  7. #include "helpline.h"
  8. #include "ui.h"
  9. pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
  10. static void newt_suspend(void *d __used)
  11. {
  12. newtSuspend();
  13. raise(SIGTSTP);
  14. newtResume();
  15. }
  16. void setup_browser(bool fallback_to_pager)
  17. {
  18. if (!isatty(1) || !use_browser || dump_trace) {
  19. use_browser = 0;
  20. if (fallback_to_pager)
  21. setup_pager();
  22. return;
  23. }
  24. use_browser = 1;
  25. newtInit();
  26. newtCls();
  27. newtSetSuspendCallback(newt_suspend, NULL);
  28. ui_helpline__init();
  29. ui_browser__init();
  30. }
  31. void exit_browser(bool wait_for_ok)
  32. {
  33. if (use_browser > 0) {
  34. if (wait_for_ok) {
  35. char title[] = "Fatal Error", ok[] = "Ok";
  36. newtWinMessage(title, ok, ui_helpline__last_msg);
  37. }
  38. newtFinished();
  39. }
  40. }