ccurses.cxx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "cmCursesMainForm.h"
  2. #include "../cmCacheManager.h"
  3. #include "../cmSystemTools.h"
  4. #include <curses.h>
  5. #include <form.h>
  6. #include <signal.h>
  7. #include <sys/ioctl.h>
  8. static cmCursesMainForm* myform=0;
  9. void onsig(int sig)
  10. {
  11. if (myform)
  12. {
  13. endwin();
  14. WINDOW* w= initscr(); /* Initialization */
  15. noecho(); /* Echo off */
  16. cbreak(); /* nl- or cr not needed */
  17. keypad(stdscr,TRUE); /* Use key symbols as
  18. KEY_DOWN*/
  19. refresh();
  20. int x,y;
  21. getmaxyx(w, y, x);
  22. myform->SetWindow(w);
  23. myform->Render(1,1,x,y);
  24. myform->UpdateStatusBar();
  25. }
  26. signal(SIGWINCH, onsig);
  27. }
  28. int main(int argc, char** argv)
  29. {
  30. if ( argc > 2 )
  31. {
  32. std::cerr << "Usage: " << argv[0] << " source_directory."
  33. << std::endl;
  34. return -1;
  35. }
  36. int newCache = false;
  37. if (!cmCacheManager::GetInstance()->LoadCache(cmSystemTools::GetCurrentWorkingDirectory().c_str()))
  38. {
  39. newCache = true;
  40. }
  41. WINDOW* w=initscr(); /* Initialization */
  42. noecho(); /* Echo off */
  43. cbreak(); /* nl- or cr not needed */
  44. keypad(stdscr,TRUE); /* Use key symbols as
  45. KEY_DOWN*/
  46. signal(SIGWINCH, onsig);
  47. int x,y;
  48. getmaxyx(w, y, x);
  49. std::string whereCMake = cmSystemTools::GetProgramPath(argv[0]);
  50. whereCMake += "/cmake";
  51. if ( argc == 2 )
  52. {
  53. myform = new cmCursesMainForm(argv[1], whereCMake.c_str(), newCache);
  54. }
  55. else
  56. {
  57. myform = new cmCursesMainForm("", whereCMake.c_str(), newCache);
  58. }
  59. myform->InitializeUI(w);
  60. myform->Render(1, 1, x, y);
  61. myform->HandleInput();
  62. // Need to clean-up better
  63. endwin();
  64. delete myform;
  65. return 0;
  66. }