basecmds.cc 8.6 KB

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