cmCursesForm.cxx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCursesForm.h"
  4. #include <cstdlib>
  5. #ifndef _WIN32
  6. # include <unistd.h>
  7. #endif // _WIN32
  8. cmsys::ofstream cmCursesForm::DebugFile;
  9. bool cmCursesForm::Debug = false;
  10. cmCursesForm::cmCursesForm()
  11. {
  12. this->Form = nullptr;
  13. }
  14. cmCursesForm::~cmCursesForm()
  15. {
  16. if (this->Form) {
  17. unpost_form(this->Form);
  18. free_form(this->Form);
  19. this->Form = nullptr;
  20. }
  21. }
  22. void cmCursesForm::DebugStart()
  23. {
  24. cmCursesForm::Debug = true;
  25. cmCursesForm::DebugFile.open("ccmakelog.txt");
  26. }
  27. void cmCursesForm::DebugEnd()
  28. {
  29. if (!cmCursesForm::Debug) {
  30. return;
  31. }
  32. cmCursesForm::Debug = false;
  33. cmCursesForm::DebugFile.close();
  34. }
  35. void cmCursesForm::LogMessage(const char* msg)
  36. {
  37. if (!cmCursesForm::Debug) {
  38. return;
  39. }
  40. cmCursesForm::DebugFile << msg << std::endl;
  41. }
  42. void cmCursesForm::HandleResize()
  43. {
  44. endwin();
  45. if (!initscr()) {
  46. static const char errmsg[] = "Error: ncurses initialization failed\n";
  47. #ifdef _WIN32
  48. fprintf(stderr, "%s", errmsg);
  49. #else
  50. auto r = write(STDERR_FILENO, errmsg, sizeof(errmsg) - 1);
  51. static_cast<void>(r);
  52. #endif // _WIN32
  53. exit(1);
  54. }
  55. noecho(); /* Echo off */
  56. cbreak(); /* nl- or cr not needed */
  57. keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
  58. refresh();
  59. int x;
  60. int y;
  61. getmaxyx(stdscr, y, x);
  62. this->Render(1, 1, x, y);
  63. this->UpdateStatusBar();
  64. }