cmCursesLongMessageForm.cxx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "../cmCacheManager.h"
  14. #include "../cmSystemTools.h"
  15. #include "../cmake.h"
  16. #include "../cmVersion.h"
  17. #include "cmCursesLongMessageForm.h"
  18. #include "cmCursesMainForm.h"
  19. inline int ctrl(int z)
  20. {
  21. return (z&037);
  22. }
  23. cmCursesLongMessageForm::cmCursesLongMessageForm(std::vector<std::string>
  24. const& messages, const char*
  25. title)
  26. {
  27. // Append all messages into on big string
  28. std::vector<std::string>::const_iterator it;
  29. for(it=messages.begin(); it != messages.end(); it++)
  30. {
  31. this->Messages += (*it);
  32. // Add one blank line after each message
  33. this->Messages += "\n\n";
  34. }
  35. this->Title = title;
  36. this->Fields[0] = 0;
  37. this->Fields[1] = 0;
  38. }
  39. cmCursesLongMessageForm::~cmCursesLongMessageForm()
  40. {
  41. if (this->Fields[0])
  42. {
  43. free_field(this->Fields[0]);
  44. }
  45. }
  46. void cmCursesLongMessageForm::UpdateStatusBar()
  47. {
  48. int x,y;
  49. getmaxyx(stdscr, y, x);
  50. char bar[cmCursesMainForm::MAX_WIDTH];
  51. int size = strlen(this->Title.c_str());
  52. if ( size >= cmCursesMainForm::MAX_WIDTH )
  53. {
  54. size = cmCursesMainForm::MAX_WIDTH-1;
  55. }
  56. strncpy(bar, this->Title.c_str(), size);
  57. for(int i=size-1; i<cmCursesMainForm::MAX_WIDTH; i++) bar[i] = ' ';
  58. int width;
  59. if (x < cmCursesMainForm::MAX_WIDTH )
  60. {
  61. width = x;
  62. }
  63. else
  64. {
  65. width = cmCursesMainForm::MAX_WIDTH;
  66. }
  67. bar[width] = '\0';
  68. char version[cmCursesMainForm::MAX_WIDTH];
  69. char vertmp[128];
  70. sprintf(vertmp,"CMake Version %d.%d - %s", cmVersion::GetMajorVersion(),
  71. cmVersion::GetMinorVersion(),cmVersion::GetReleaseVersion());
  72. int sideSpace = (width-strlen(vertmp));
  73. for(int i=0; i<sideSpace; i++) { version[i] = ' '; }
  74. sprintf(version+sideSpace, "%s", vertmp);
  75. version[width] = '\0';
  76. curses_move(y-4,0);
  77. attron(A_STANDOUT);
  78. printw(bar);
  79. attroff(A_STANDOUT);
  80. curses_move(y-3,0);
  81. printw(version);
  82. pos_form_cursor(this->Form);
  83. }
  84. void cmCursesLongMessageForm::PrintKeys()
  85. {
  86. int x,y;
  87. getmaxyx(stdscr, y, x);
  88. if ( x < cmCursesMainForm::MIN_WIDTH ||
  89. y < cmCursesMainForm::MIN_HEIGHT )
  90. {
  91. return;
  92. }
  93. char firstLine[512];
  94. sprintf(firstLine, "Press [e] to exit help");
  95. curses_move(y-2,0);
  96. printw(firstLine);
  97. pos_form_cursor(this->Form);
  98. }
  99. void cmCursesLongMessageForm::Render(int, int, int, int)
  100. {
  101. int x,y;
  102. getmaxyx(stdscr, y, x);
  103. if (this->Form)
  104. {
  105. unpost_form(this->Form);
  106. free_form(this->Form);
  107. this->Form = 0;
  108. }
  109. const char* msg = this->Messages.c_str();
  110. curses_clear();
  111. if (this->Fields[0])
  112. {
  113. free_field(this->Fields[0]);
  114. this->Fields[0] = 0;
  115. }
  116. this->Fields[0] = new_field(y-6, x-2, 1, 1, 0, 0);
  117. field_opts_off(this->Fields[0], O_STATIC);
  118. this->Form = new_form(this->Fields);
  119. post_form(this->Form);
  120. int i=0;
  121. form_driver(this->Form, REQ_BEG_FIELD);
  122. while(msg[i] != '\0' && i < 60000)
  123. {
  124. if (msg[i] == '\n' && msg[i+1] != '\0')
  125. {
  126. form_driver(this->Form, REQ_NEW_LINE);
  127. }
  128. else
  129. {
  130. form_driver(this->Form, msg[i]);
  131. }
  132. i++;
  133. }
  134. form_driver(this->Form, REQ_BEG_FIELD);
  135. this->UpdateStatusBar();
  136. this->PrintKeys();
  137. touchwin(stdscr);
  138. refresh();
  139. }
  140. void cmCursesLongMessageForm::HandleInput()
  141. {
  142. if (!this->Form)
  143. {
  144. return;
  145. }
  146. char debugMessage[128];
  147. for(;;)
  148. {
  149. int key = getch();
  150. sprintf(debugMessage, "Message widget handling input, key: %d", key);
  151. cmCursesForm::LogMessage(debugMessage);
  152. // quit
  153. if ( key == 'o' || key == 'e' )
  154. {
  155. break;
  156. }
  157. else if ( key == KEY_DOWN || key == ctrl('n') )
  158. {
  159. form_driver(this->Form, REQ_SCR_FLINE);
  160. }
  161. else if ( key == KEY_UP || key == ctrl('p') )
  162. {
  163. form_driver(this->Form, REQ_SCR_BLINE);
  164. }
  165. else if ( key == KEY_NPAGE || key == ctrl('d') )
  166. {
  167. form_driver(this->Form, REQ_SCR_FPAGE);
  168. }
  169. else if ( key == KEY_PPAGE || key == ctrl('u') )
  170. {
  171. form_driver(this->Form, REQ_SCR_BPAGE);
  172. }
  173. this->UpdateStatusBar();
  174. this->PrintKeys();
  175. touchwin(stdscr);
  176. wrefresh(stdscr);
  177. }
  178. }