basecmds.cc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * dselect - Debian GNU/Linux package maintenance user interface
  3. * bcommands.cc - base list keyboard commands display
  4. *
  5. * Copyright (C) 1994,1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with this; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <curses.h>
  24. #include <assert.h>
  25. #include <signal.h>
  26. extern "C" {
  27. #include <config.h>
  28. #include <dpkg.h>
  29. #include <dpkg-db.h>
  30. }
  31. #include "dselect.h"
  32. #include "helpmsgs.h"
  33. void baselist::kd_scrollon() {
  34. topofscreen += list_height;
  35. if (topofscreen > nitems - list_height) topofscreen= nitems - list_height;
  36. if (topofscreen < 0) topofscreen= 0;
  37. if (cursorline < topofscreen)
  38. setcursor(topofscreen);
  39. refreshlist();
  40. }
  41. void baselist::kd_scrollon1() {
  42. if (topofscreen >= nitems - list_height) return;
  43. topofscreen++;
  44. if (cursorline < topofscreen)
  45. setcursor(topofscreen);
  46. refreshlist();
  47. }
  48. void baselist::kd_scrollback() {
  49. topofscreen -= list_height;
  50. if (topofscreen < 0) topofscreen= 0;
  51. if (cursorline >= topofscreen + list_height)
  52. setcursor(topofscreen + list_height - 1);
  53. refreshlist();
  54. }
  55. void baselist::kd_scrollback1() {
  56. if (topofscreen <= 0) return;
  57. topofscreen--;
  58. if (cursorline >= topofscreen + list_height)
  59. setcursor(topofscreen + list_height - 1);
  60. refreshlist();
  61. }
  62. void baselist::kd_top() {
  63. topofscreen= 0; setcursor(0);
  64. }
  65. void baselist::kd_bottom() {
  66. topofscreen= nitems - list_height;
  67. if (topofscreen < 0) topofscreen= 0;
  68. setcursor(lesserint(topofscreen + list_height - 1, nitems-1));
  69. }
  70. void baselist::kd_redraw() {
  71. //#define RFSH(x) werase(x); redrawwin(x)
  72. // RFSH(listpad);
  73. // RFSH(infopad);
  74. // RFSH(colheadspad);
  75. // RFSH(thisstatepad);
  76. // RFSH(titlewin);
  77. // RFSH(whatinfowin); /* fixme-ncurses: why does ncurses need this ? */
  78. clearok(curscr,TRUE);
  79. redrawall();
  80. if (debug) fprintf(debug,"baselist[%p]::kd_redraw() done\n",this);
  81. }
  82. void baselist::kd_searchagain() {
  83. if (!searchstring[0]) { beep(); return; }
  84. dosearch();
  85. }
  86. void baselist::kd_search() {
  87. werase(querywin);
  88. mvwaddstr(querywin,0,0, "Search for ? ");
  89. echo(); /* fixme: ncurses documentation or implementation */
  90. /* fixme: make / RET do `search again' and / DEL to abort */
  91. if (wgetnstr(querywin,searchstring,sizeof(searchstring)-1) == ERR)
  92. searchstring[0]= 0;
  93. raise(SIGWINCH); /* fixme: ncurses and xterm arrow keys */
  94. noecho(); /* fixme: ncurses */
  95. if (whatinfo_height) { touchwin(whatinfowin); refreshinfo(); }
  96. else if (info_height) { touchwin(infopad); refreshinfo(); }
  97. else if (thisstate_height) redrawthisstate();
  98. else { touchwin(listpad); refreshlist(); }
  99. if (searchstring[0]) dosearch();
  100. }
  101. void baselist::displayhelp(const struct helpmenuentry *helpmenu, int key) {
  102. const struct helpmenuentry *hme;
  103. int maxx, maxy, i, y, x, nextkey;
  104. getmaxyx(stdscr,maxy,maxx);
  105. clearok(stdscr,TRUE);
  106. for (;;) {
  107. werase(stdscr);
  108. for (hme= helpmenu; hme->key && hme->key != key; hme++);
  109. if (hme->key) {
  110. attrset(list_attr);
  111. mvaddstr(1,0, hme->msg->text);
  112. attrset(title_attr);
  113. mvaddstr(0,0, "Help: ");
  114. addstr(hme->msg->title);
  115. getyx(stdscr,y,x);
  116. while (++x<maxx) addch(' ');
  117. attrset(thisstate_attr);
  118. mvaddstr(maxy-1,0,
  119. "? = help menu Space = exit help . = next help or a help page key "
  120. );
  121. getyx(stdscr,y,x);
  122. while (++x<maxx) addch(' ');
  123. move(maxy,maxx);
  124. attrset(A_NORMAL);
  125. nextkey= hme[1].key;
  126. } else {
  127. mvaddstr(1,1, "Help information is available under the following topics:");
  128. for (i=0, hme=helpmenu; hme->key; hme++,i++) {
  129. attrset(A_BOLD);
  130. mvaddch(i+3,3, hme->key);
  131. attrset(A_NORMAL);
  132. mvaddstr(i+3,6, hme->msg->title);
  133. }
  134. mvaddstr(i+4,1,
  135. "Press a key from the list above, Space to exit help,\n"
  136. " or `.' (full stop) to read each help page in turn. ");
  137. nextkey= helpmenu[0].key;
  138. }
  139. refresh();
  140. key= getch();
  141. if (key == EOF) ohshite("error reading keyboard in help");
  142. if (key == ' ') {
  143. break;
  144. } else if (key == '?') {
  145. key= 0;
  146. } else if (key == '.') {
  147. key= nextkey;
  148. }
  149. }
  150. werase(stdscr);
  151. clearok(stdscr,TRUE);
  152. wnoutrefresh(stdscr);
  153. redrawtitle();
  154. refreshcolheads();
  155. refreshlist();
  156. redrawthisstate();
  157. refreshinfo();
  158. wnoutrefresh(whatinfowin);
  159. }
  160. void baselist::kd_help() {
  161. displayhelp(helpmenulist(),0);
  162. }
  163. void baselist::setcursor(int index) {
  164. if (listpad && cursorline != -1) {
  165. redrawitemsrange(cursorline,cursorline+1);
  166. redraw1itemsel(cursorline,0);
  167. }
  168. if (cursorline != index) infotopofscreen= 0;
  169. cursorline= index;
  170. if (listpad) {
  171. redrawitemsrange(cursorline,cursorline+1);
  172. redraw1itemsel(cursorline,1);
  173. refreshlist();
  174. redrawthisstate();
  175. }
  176. redrawinfo();
  177. }
  178. void baselist::kd_down() {
  179. int ncursor= cursorline;
  180. // scroll by one line unless the bottom is already visible
  181. // or we're in the top half of the screen ...
  182. if (topofscreen < nitems - list_height &&
  183. ncursor >= topofscreen + list_height - 3) topofscreen++;
  184. // move cursor if there are any more ...
  185. if (cursorline+1 < nitems) ncursor++;
  186. setcursor(ncursor);
  187. }
  188. void baselist::kd_up() {
  189. int ncursor= cursorline;
  190. // scroll by one line if there are any lines not shown yet
  191. // and we're not in the bottom half the screen ...
  192. if (topofscreen > 0 &&
  193. ncursor <= topofscreen + 2) topofscreen--;
  194. // move cursor if there are any to move it to ...
  195. if (cursorline > 0) ncursor--;
  196. setcursor(ncursor);
  197. }
  198. void baselist::kd_iscrollon() {
  199. infotopofscreen += info_height;
  200. if (infotopofscreen > infolines - info_height)
  201. infotopofscreen= infolines - info_height;
  202. if (infotopofscreen < 0) infotopofscreen= 0;
  203. refreshinfo();
  204. }
  205. void baselist::kd_iscrollback() {
  206. infotopofscreen -= info_height;
  207. if (infotopofscreen < 0) infotopofscreen= 0;
  208. refreshinfo();
  209. }
  210. void baselist::kd_iscrollon1() {
  211. if (infotopofscreen >= infolines - info_height) return;
  212. infotopofscreen++; refreshinfo();
  213. }
  214. void baselist::kd_iscrollback1() {
  215. if (infotopofscreen <= 0) return;
  216. infotopofscreen--; refreshinfo();
  217. }
  218. void baselist::kd_panon() {
  219. leftofscreen += xmax/3;
  220. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  221. if (leftofscreen < 0) leftofscreen= 0;
  222. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  223. }
  224. void baselist::kd_panback() {
  225. leftofscreen -= xmax/3;
  226. if (leftofscreen < 0) leftofscreen= 0;
  227. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  228. }
  229. void baselist::kd_panon1() {
  230. leftofscreen++;
  231. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  232. if (leftofscreen < 0) leftofscreen= 0;
  233. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  234. }
  235. void baselist::kd_panback1() {
  236. leftofscreen--;
  237. if (leftofscreen < 0) leftofscreen= 0;
  238. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  239. }