ccurses.cxx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. if ( argc == 2 )
  50. {
  51. myform = new cmCursesMainForm(argv[1], newCache);
  52. }
  53. else
  54. {
  55. myform = new cmCursesMainForm("", newCache);
  56. }
  57. myform->InitializeUI(w);
  58. myform->Render(1, 1, x, y);
  59. myform->HandleInput();
  60. // Need to clean-up better
  61. endwin();
  62. delete myform;
  63. return 0;
  64. }