You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
5.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "basicNCursesEngine.h"
  2. basicNCursesEngine * basicNCursesEngine::_instance = NULL;
  3. /**
  4. * Returns the single instance of the object.
  5. */
  6. basicNCursesEngine * basicNCursesEngine::getInstance()
  7. {
  8. // check if the instance has been created yet
  9. if (0 == _instance)
  10. {
  11. // if not, then create it
  12. _instance = new basicNCursesEngine;
  13. }
  14. // return the single instance
  15. return _instance;
  16. }
  17. // Constructor implementation
  18. basicNCursesEngine::basicNCursesEngine()
  19. {
  20. def_shell_mode();
  21. m_pCursesWin = initscr(); // Start curses mode
  22. if (has_colors() == FALSE)
  23. {
  24. endwin();
  25. printf("Your terminal does not support color\n");
  26. return;
  27. };
  28. noecho();
  29. cbreak(); // Line buffering disabled, Pass on everty thing to me
  30. keypad(m_pCursesWin, TRUE); // I need that nifty F1
  31. nodelay(m_pCursesWin, TRUE);
  32. m_pCDKScreen = initCDKScreen(m_pCursesWin);
  33. initCDKColor();
  34. // basicThread::init();
  35. /*
  36. //start_color(); // Start color
  37. //def_prog_mode(); // Save the tty modes
  38. //cbreak(); // Line buffering disabled, Pass on
  39. // everty thing to me
  40. //raw();
  41. //keypad(stdscr, TRUE); // I need that nifty F1
  42. //noecho(); // Don't echo() while we do getch
  43. /*
  44. init_color( COLOR_RED, 700, 0, 0);
  45. init_pair(1, COLOR_RED, COLOR_BLACK );
  46. attron( COLOR_PAIR(1) );
  47. //*/
  48. /*char *rTitles[3]={"","",""};
  49. char *cTitles[3]={"","",""};
  50. char filler=' ';
  51. int arr[3]={7,7,7};
  52. char *buttons[40];
  53. char *message[40];
  54. message[0] = "<C></U>Simple Command Interface";
  55. message[1] = "Pick the command you wish to run.";
  56. message[2] = "<C>Press </R>?<!R> for help.";
  57. buttons[0] = "Who";
  58. buttons[1] = "Time";
  59. buttons[2] = "Date";
  60. buttons[3] = "Quit";
  61. /*m_pCDKMatrix = newCDKMatrix (
  62. m_pCDKScreen,
  63. LEFT,
  64. TOP,
  65. 23,
  66. 23,
  67. 3,
  68. 3,
  69. "PRU Cores",
  70. rTitles,
  71. cTitles,
  72. arr,
  73. arr,
  74. 1,
  75. 1,
  76. filler,
  77. COL,
  78. true,
  79. true,
  80. true );*/
  81. /* Create the dialog box. */
  82. /*question = newCDKDialog( m_pCDKScreen, LEFT, CENTER,
  83. message, 3, buttons, 4, A_REVERSE,
  84. true, true, true);
  85. /* Check if we got a null value back. */
  86. /*if( question == (CDKDIALOG *)NULL)
  87. {
  88. destroyCDKScreen (m_pCDKScreen);
  89. // End curses...
  90. endCDK();
  91. // Spit out a message.
  92. printf ("Oops. Can't seem to create the dialog box. Is the window too small?\n");
  93. exit (1);
  94. } else {
  95. drawCDKDialog( question, true );
  96. }
  97. */
  98. CDKLABEL * demo = NULL;
  99. char * mesg[4];
  100. // cdkscreen = initCDKScreen (NULL);
  101. // if( cdkscreen == NULL ) {
  102. // printf("CDK Screen Youk!\n");
  103. // return;
  104. //}
  105. /* Start CDK Colors */
  106. // initCDKColor();
  107. /* Set the labels up. */
  108. mesg[0] = "</31>This line should have a yellow foreground and a cyan background.<!31>";
  109. mesg[1] = "</05>This line should have a white foreground and a blue background.<!05>";
  110. mesg[2] = "</26>This line should have a yellow foreground and a red background.<!26>";
  111. mesg[3] = "<C>This line should be set to whatever the screen default is.";
  112. /* Set the labels up. */
  113. // mesg[0] = "<C><#UL><#HL(26)><#UR>";
  114. // mesg[1] = "<C><#VL></R>This text should be boxed.<!R><#VL>";
  115. // mesg[2] = "<C><#LL><#HL(26)><#LR>";
  116. // mesg[3] = "<C>While this is not.";
  117. /* Declare the labels. */
  118. // demo = newCDKLabel( m_pCDKScreen, 0, 0, mesg, 4, false, false );
  119. /* Draw the label */
  120. // drawCDKLabel( demo, TRUE);
  121. // waitCDKLabel( demo, ' ');
  122. /* Clean up */
  123. // destroyCDKLabel (demo);
  124. }
  125. // Destructor implementation
  126. basicNCursesEngine::~basicNCursesEngine()
  127. {
  128. // destroyCDKDialog (question);
  129. m_bThreadStatus = TH_ENDED;
  130. destroyCDKScreen(m_pCDKScreen);
  131. m_pCDKScreen = NULL;
  132. endCDK();
  133. delwin(m_pCursesWin);
  134. m_pCursesWin = NULL;
  135. endwin(); // End curses mode
  136. echo();
  137. }
  138. bool basicNCursesEngine::attachWindow(WindowCLI * wnd)
  139. {
  140. m_vWindowPool.push_back(wnd);
  141. wnd->paint();
  142. return true;
  143. }
  144. void basicNCursesEngine::m_fThreadProc(void)
  145. {
  146. int counter = 0;
  147. int ch;
  148. pthread_setname_np(pthread_self(), "basicNCursesEngine");
  149. m_bThreadStatus = TH_WORKING;
  150. while (m_bThreadStatus < TH_ENDED)
  151. {
  152. while ((ch = getch()) != KEY_F(1))
  153. {
  154. switch (ch)
  155. {
  156. case KEY_LEFT:
  157. // MyCurses->destroy_win(my_win);
  158. // my_win = MyCurses->create_win(height, width, starty,--startx);
  159. break;
  160. case KEY_RIGHT:
  161. // MyCurses->destroy_win(my_win);
  162. // my_win = MyCurses->create_win(height, width, starty,++startx);
  163. break;
  164. case KEY_UP:
  165. // MyCurses->destroy_win(my_win);
  166. // my_win = MyCurses->create_win(height, width, --starty,startx);
  167. break;
  168. case KEY_DOWN:
  169. // MyCurses->destroy_win(my_win);
  170. // my_win = MyCurses->create_win(height, width, ++starty,startx);
  171. break;
  172. };
  173. };
  174. if (m_vWindowPool.size() > 0)
  175. {
  176. for (WIN_ITERATOR index = m_vWindowPool.begin(); index < m_vWindowPool.end(); index++)
  177. {
  178. (*index)->paint();
  179. };
  180. };
  181. #ifdef __linux__
  182. usleep(DEFAULT_THREAD_SLEEP_TIME);
  183. #else
  184. Sleep(10);
  185. #endif
  186. mvwprintw(m_pCursesWin, 30, 2, "%d\n", counter++);
  187. };
  188. }
  189. // void basicNCursesEngine::