basecmds.cc 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 <ncurses.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();
  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. noecho();
  94. if (whatinfo_height) { touchwin(whatinfowin); refreshinfo(); }
  95. else if (info_height) { touchwin(infopad); refreshinfo(); }
  96. else if (thisstate_height) redrawthisstate();
  97. else { touchwin(listpad); refreshlist(); }
  98. if (searchstring[0]) dosearch();
  99. }
  100. void baselist::displayhelp(const struct helpmenuentry *helpmenu, int key) {
  101. const struct helpmenuentry *hme;
  102. int maxx, maxy, i, y, x, nextkey;
  103. getmaxyx(stdscr,maxy,maxx);
  104. clearok(stdscr,TRUE);
  105. for (;;) {
  106. werase(stdscr);
  107. for (hme= helpmenu; hme->key && hme->key != key; hme++);
  108. if (hme->key) {
  109. attrset(list_attr);
  110. mvaddstr(1,0, hme->msg->text);
  111. attrset(title_attr);
  112. mvaddstr(0,0, "Help: ");
  113. addstr(hme->msg->title);
  114. getyx(stdscr,y,x);
  115. while (++x<maxx) addch(' ');
  116. attrset(thisstate_attr);
  117. mvaddstr(maxy-1,0,
  118. "? = help menu Space = exit help . = next help or a help page key "
  119. );
  120. getyx(stdscr,y,x);
  121. while (++x<maxx) addch(' ');
  122. move(maxy,maxx);
  123. attrset(A_NORMAL);
  124. nextkey= hme[1].key;
  125. } else {
  126. mvaddstr(1,1, "Help information is available under the following topics:");
  127. for (i=0, hme=helpmenu; hme->key; hme++,i++) {
  128. attrset(A_BOLD);
  129. mvaddch(i+3,3, hme->key);
  130. attrset(A_NORMAL);
  131. mvaddstr(i+3,6, hme->msg->title);
  132. }
  133. mvaddstr(i+4,1,
  134. "Press a key from the list above, Space to exit help,\n"
  135. " or `.' (full stop) to read each help page in turn. ");
  136. nextkey= helpmenu[0].key;
  137. }
  138. refresh();
  139. key= getch();
  140. if (key == EOF) ohshite("error reading keyboard in help");
  141. if (key == ' ') {
  142. break;
  143. } else if (key == '?') {
  144. key= 0;
  145. } else if (key == '.') {
  146. key= nextkey;
  147. }
  148. }
  149. werase(stdscr);
  150. clearok(stdscr,TRUE);
  151. wnoutrefresh(stdscr);
  152. redrawtitle();
  153. refreshcolheads();
  154. refreshlist();
  155. redrawthisstate();
  156. refreshinfo();
  157. wnoutrefresh(whatinfowin);
  158. }
  159. void baselist::kd_help() {
  160. displayhelp(helpmenulist(),0);
  161. }
  162. void baselist::setcursor(int index) {
  163. if (listpad && cursorline != -1) {
  164. redrawitemsrange(cursorline,cursorline+1);
  165. redraw1itemsel(cursorline,0);
  166. }
  167. if (cursorline != index) infotopofscreen= 0;
  168. cursorline= index;
  169. if (listpad) {
  170. redrawitemsrange(cursorline,cursorline+1);
  171. redraw1itemsel(cursorline, showinfo != 2);
  172. refreshlist();
  173. redrawthisstate();
  174. }
  175. redrawinfo();
  176. }
  177. void baselist::kd_down() {
  178. int ncursor= cursorline;
  179. // scroll by one line unless the bottom is already visible
  180. // or we're in the top half of the screen ...
  181. if (topofscreen < nitems - list_height &&
  182. ncursor >= topofscreen + list_height - 3) topofscreen++;
  183. // move cursor if there are any more ...
  184. if (cursorline+1 < nitems) ncursor++;
  185. setcursor(ncursor);
  186. }
  187. void baselist::kd_up() {
  188. int ncursor= cursorline;
  189. // scroll by one line if there are any lines not shown yet
  190. // and we're not in the bottom half the screen ...
  191. if (topofscreen > 0 &&
  192. ncursor <= topofscreen + 2) topofscreen--;
  193. // move cursor if there are any to move it to ...
  194. if (cursorline > 0) ncursor--;
  195. setcursor(ncursor);
  196. }
  197. void baselist::kd_iscrollon() {
  198. infotopofscreen += info_height;
  199. if (infotopofscreen > infolines - info_height)
  200. infotopofscreen= infolines - info_height;
  201. if (infotopofscreen < 0) infotopofscreen= 0;
  202. refreshinfo();
  203. }
  204. void baselist::kd_iscrollback() {
  205. infotopofscreen -= info_height;
  206. if (infotopofscreen < 0) infotopofscreen= 0;
  207. refreshinfo();
  208. }
  209. void baselist::kd_iscrollon1() {
  210. if (infotopofscreen >= infolines - info_height) return;
  211. infotopofscreen++; refreshinfo();
  212. }
  213. void baselist::kd_iscrollback1() {
  214. if (infotopofscreen <= 0) return;
  215. infotopofscreen--; refreshinfo();
  216. }
  217. void baselist::kd_panon() {
  218. leftofscreen += xmax/3;
  219. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  220. if (leftofscreen < 0) leftofscreen= 0;
  221. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  222. }
  223. void baselist::kd_panback() {
  224. leftofscreen -= xmax/3;
  225. if (leftofscreen < 0) leftofscreen= 0;
  226. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  227. }
  228. void baselist::kd_panon1() {
  229. leftofscreen++;
  230. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  231. if (leftofscreen < 0) leftofscreen= 0;
  232. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  233. }
  234. void baselist::kd_panback1() {
  235. leftofscreen--;
  236. if (leftofscreen < 0) leftofscreen= 0;
  237. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  238. }