basecmds.cc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 <assert.h>
  24. extern "C" {
  25. #include <config.h>
  26. #include <dpkg.h>
  27. #include <dpkg-db.h>
  28. }
  29. #include "dselect.h"
  30. #include "helpmsgs.h"
  31. void baselist::kd_scrollon() {
  32. topofscreen += list_height;
  33. if (topofscreen > nitems - list_height) topofscreen= nitems - list_height;
  34. if (topofscreen < 0) topofscreen= 0;
  35. if (cursorline < topofscreen)
  36. setcursor(topofscreen);
  37. refreshlist();
  38. }
  39. void baselist::kd_scrollon1() {
  40. if (topofscreen >= nitems - list_height) return;
  41. topofscreen++;
  42. if (cursorline < topofscreen)
  43. setcursor(topofscreen);
  44. refreshlist();
  45. }
  46. void baselist::kd_scrollback() {
  47. topofscreen -= list_height;
  48. if (topofscreen < 0) topofscreen= 0;
  49. if (cursorline >= topofscreen + list_height)
  50. setcursor(topofscreen + list_height - 1);
  51. refreshlist();
  52. }
  53. void baselist::kd_scrollback1() {
  54. if (topofscreen <= 0) return;
  55. topofscreen--;
  56. if (cursorline >= topofscreen + list_height)
  57. setcursor(topofscreen + list_height - 1);
  58. refreshlist();
  59. }
  60. void baselist::kd_top() {
  61. topofscreen= 0; setcursor(0);
  62. }
  63. void baselist::kd_bottom() {
  64. topofscreen= nitems - list_height;
  65. if (topofscreen < 0) topofscreen= 0;
  66. setcursor(lesserint(topofscreen + list_height - 1, nitems-1));
  67. }
  68. void baselist::kd_redraw() {
  69. //#define RFSH(x) werase(x); redrawwin(x)
  70. // RFSH(listpad);
  71. // RFSH(infopad);
  72. // RFSH(colheadspad);
  73. // RFSH(thisstatepad);
  74. // RFSH(titlewin);
  75. // RFSH(whatinfowin); /* fixme-ncurses: why does ncurses need this ? */
  76. clearok(curscr,TRUE);
  77. redrawall();
  78. if (debug) fprintf(debug,"baselist[%p]::kd_redraw() done\n",this);
  79. }
  80. void baselist::kd_searchagain() {
  81. if (!searchstring[0]) { beep(); return; }
  82. dosearch();
  83. }
  84. void baselist::kd_search() {
  85. char newsearchstring[50];
  86. strcpy(newsearchstring,searchstring);
  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,newsearchstring,sizeof(newsearchstring)-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 (newsearchstring[0]) {
  100. strcpy(searchstring,newsearchstring);
  101. dosearch();
  102. } else
  103. kd_searchagain();
  104. }
  105. void baselist::displayhelp(const struct helpmenuentry *helpmenu, int key) {
  106. const struct helpmenuentry *hme;
  107. int maxx, maxy, i, y, x, nextkey;
  108. getmaxyx(stdscr,maxy,maxx);
  109. clearok(stdscr,TRUE);
  110. for (;;) {
  111. werase(stdscr);
  112. for (hme= helpmenu; hme->key && hme->key != key; hme++);
  113. if (hme->key) {
  114. attrset(list_attr);
  115. mvaddstr(1,0, gettext(hme->msg->text));
  116. attrset(title_attr);
  117. mvaddstr(0,0, _("Help: "));
  118. addstr(gettext(hme->msg->title));
  119. getyx(stdscr,y,x);
  120. while (++x<maxx) addch(' ');
  121. attrset(thisstate_attr);
  122. mvaddstr(maxy-1,0,
  123. _("? = help menu Space = exit help . = next help or a help page key ")
  124. );
  125. getyx(stdscr,y,x);
  126. while (++x<maxx) addch(' ');
  127. move(maxy,maxx);
  128. attrset(A_NORMAL);
  129. nextkey= hme[1].key;
  130. } else {
  131. mvaddstr(1,1, _("Help information is available under the following topics:"));
  132. for (i=0, hme=helpmenu; hme->key; hme++,i++) {
  133. attrset(A_BOLD);
  134. mvaddch(i+3,3, hme->key);
  135. attrset(A_NORMAL);
  136. mvaddstr(i+3,6, gettext(hme->msg->title));
  137. }
  138. mvaddstr(i+4,1,
  139. _("Press a key from the list above, Space to exit help,\n"
  140. " or `.' (full stop) to read each help page in turn. "));
  141. nextkey= helpmenu[0].key;
  142. }
  143. refresh();
  144. key= getch();
  145. if (key == EOF) ohshite(_("error reading keyboard in help"));
  146. if (key == ' ') {
  147. break;
  148. } else if (key == '?') {
  149. key= 0;
  150. } else if (key == '.') {
  151. key= nextkey;
  152. }
  153. }
  154. werase(stdscr);
  155. clearok(stdscr,TRUE);
  156. wnoutrefresh(stdscr);
  157. redrawtitle();
  158. refreshcolheads();
  159. refreshlist();
  160. redrawthisstate();
  161. refreshinfo();
  162. wnoutrefresh(whatinfowin);
  163. }
  164. void baselist::kd_help() {
  165. displayhelp(helpmenulist(),0);
  166. }
  167. void baselist::setcursor(int index) {
  168. if (listpad && cursorline != -1) {
  169. redrawitemsrange(cursorline,cursorline+1);
  170. redraw1itemsel(cursorline,0);
  171. }
  172. if (cursorline != index) infotopofscreen= 0;
  173. cursorline= index;
  174. if (listpad) {
  175. redrawitemsrange(cursorline,cursorline+1);
  176. redraw1itemsel(cursorline,1);
  177. refreshlist();
  178. redrawthisstate();
  179. }
  180. redrawinfo();
  181. }
  182. void baselist::kd_down() {
  183. int ncursor= cursorline;
  184. // scroll by one line unless the bottom is already visible
  185. // or we're in the top half of the screen ...
  186. if (topofscreen < nitems - list_height &&
  187. ncursor >= topofscreen + list_height - 3) topofscreen++;
  188. // move cursor if there are any more ...
  189. if (cursorline+1 < nitems) ncursor++;
  190. setcursor(ncursor);
  191. }
  192. void baselist::kd_up() {
  193. int ncursor= cursorline;
  194. // scroll by one line if there are any lines not shown yet
  195. // and we're not in the bottom half the screen ...
  196. if (topofscreen > 0 &&
  197. ncursor <= topofscreen + 2) topofscreen--;
  198. // move cursor if there are any to move it to ...
  199. if (cursorline > 0) ncursor--;
  200. setcursor(ncursor);
  201. }
  202. void baselist::kd_iscrollon() {
  203. infotopofscreen += info_height;
  204. if (infotopofscreen > infolines - info_height)
  205. infotopofscreen= infolines - info_height;
  206. if (infotopofscreen < 0) infotopofscreen= 0;
  207. refreshinfo();
  208. }
  209. void baselist::kd_iscrollback() {
  210. infotopofscreen -= info_height;
  211. if (infotopofscreen < 0) infotopofscreen= 0;
  212. refreshinfo();
  213. }
  214. void baselist::kd_iscrollon1() {
  215. if (infotopofscreen >= infolines - info_height) return;
  216. infotopofscreen++; refreshinfo();
  217. }
  218. void baselist::kd_iscrollback1() {
  219. if (infotopofscreen <= 0) return;
  220. infotopofscreen--; refreshinfo();
  221. }
  222. void baselist::kd_panon() {
  223. leftofscreen += xmax/3;
  224. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  225. if (leftofscreen < 0) leftofscreen= 0;
  226. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  227. }
  228. void baselist::kd_panback() {
  229. leftofscreen -= xmax/3;
  230. if (leftofscreen < 0) leftofscreen= 0;
  231. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  232. }
  233. void baselist::kd_panon1() {
  234. leftofscreen++;
  235. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  236. if (leftofscreen < 0) leftofscreen= 0;
  237. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  238. }
  239. void baselist::kd_panback1() {
  240. leftofscreen--;
  241. if (leftofscreen < 0) leftofscreen= 0;
  242. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  243. }