basecmds.cc 8.6 KB

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