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.

198 lines
5.6 KiB

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