basecmds.cc 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * bcommands.cc - base list keyboard commands display
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 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 <config.h>
  23. #include <compat.h>
  24. #include <dpkg-i18n.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <assert.h>
  28. #include <dpkg.h>
  29. #include <dpkg-db.h>
  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: 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. int maxx, maxy, i, y, x, nextkey;
  138. getmaxyx(stdscr,maxy,maxx);
  139. wbkgdset(stdscr, ' ' | helpscreen_attr);
  140. clearok(stdscr,TRUE);
  141. for (;;) {
  142. werase(stdscr);
  143. const struct helpmenuentry *hme = helpmenu;
  144. while (hme->key && hme->key != key)
  145. hme++;
  146. if (hme->key) {
  147. attrset(helpscreen_attr);
  148. mvaddstr(1,0, gettext(hme->msg->text));
  149. attrset(title_attr);
  150. mvaddstr(0,0, _("Help: "));
  151. addstr(gettext(hme->msg->title));
  152. getyx(stdscr,y,x);
  153. while (++x<maxx) addch(' ');
  154. attrset(thisstate_attr);
  155. mvaddstr(maxy-1,0,
  156. _("Press ? for help menu, . for next topic, <space> to exit help."));
  157. getyx(stdscr,y,x);
  158. while (++x<maxx) addch(' ');
  159. move(maxy,maxx);
  160. attrset(A_NORMAL);
  161. nextkey= hme[1].key;
  162. } else {
  163. mvaddstr(1,1, _("Help information is available under the following topics:"));
  164. for (i=0, hme=helpmenu; hme->key; hme++,i++) {
  165. attrset(A_BOLD);
  166. mvaddch(i+3,3, hme->key);
  167. attrset(A_NORMAL);
  168. mvaddstr(i+3,6, gettext(hme->msg->title));
  169. }
  170. mvaddstr(i+4,1,
  171. _("Press a key from the list above, <space> or `q' to exit help,\n"
  172. " or `.' (full stop) to read each help page in turn. "));
  173. nextkey= helpmenu[0].key;
  174. }
  175. refresh();
  176. key= getch();
  177. if (key == EOF) ohshite(_("error reading keyboard in help"));
  178. if (key == ' ' || key == 'q') {
  179. break;
  180. } else if (key == '?' || key == 'h') {
  181. key= 0;
  182. } else if (key == '.') {
  183. key= nextkey;
  184. }
  185. }
  186. werase(stdscr);
  187. clearok(stdscr,TRUE);
  188. wnoutrefresh(stdscr);
  189. redrawtitle();
  190. refreshcolheads();
  191. refreshlist();
  192. redrawthisstate();
  193. refreshinfo();
  194. wnoutrefresh(whatinfowin);
  195. }
  196. void baselist::kd_help() {
  197. displayhelp(helpmenulist(),0);
  198. }
  199. void baselist::setcursor(int index) {
  200. if (listpad && cursorline != -1) {
  201. redrawitemsrange(cursorline,cursorline+1);
  202. redraw1itemsel(cursorline,0);
  203. }
  204. if (cursorline != index) infotopofscreen= 0;
  205. cursorline= index;
  206. if (listpad) {
  207. redrawitemsrange(cursorline,cursorline+1);
  208. redraw1itemsel(cursorline,1);
  209. refreshlist();
  210. redrawthisstate();
  211. }
  212. redrawinfo();
  213. }
  214. void baselist::kd_down() {
  215. int ncursor= cursorline;
  216. // scroll by one line unless the bottom is already visible
  217. // or we're in the top half of the screen ...
  218. if (topofscreen < nitems - list_height &&
  219. ncursor >= topofscreen + list_height - 3) topofscreen++;
  220. // move cursor if there are any more ...
  221. if (cursorline+1 < nitems) ncursor++;
  222. setcursor(ncursor);
  223. }
  224. void baselist::kd_up() {
  225. int ncursor= cursorline;
  226. // scroll by one line if there are any lines not shown yet
  227. // and we're not in the bottom half the screen ...
  228. if (topofscreen > 0 &&
  229. ncursor <= topofscreen + 2) topofscreen--;
  230. // move cursor if there are any to move it to ...
  231. if (cursorline > 0) ncursor--;
  232. setcursor(ncursor);
  233. }
  234. void baselist::kd_iscrollon() {
  235. infotopofscreen += info_height;
  236. if (infotopofscreen > infolines - info_height)
  237. infotopofscreen= infolines - info_height;
  238. if (infotopofscreen < 0) infotopofscreen= 0;
  239. refreshinfo();
  240. }
  241. void baselist::kd_iscrollback() {
  242. infotopofscreen -= info_height;
  243. if (infotopofscreen < 0) infotopofscreen= 0;
  244. refreshinfo();
  245. }
  246. void baselist::kd_iscrollon1() {
  247. if (infotopofscreen >= infolines - info_height) return;
  248. infotopofscreen++; refreshinfo();
  249. }
  250. void baselist::kd_iscrollback1() {
  251. if (infotopofscreen <= 0) return;
  252. infotopofscreen--; refreshinfo();
  253. }
  254. void baselist::kd_panon() {
  255. leftofscreen += xmax/3;
  256. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  257. if (leftofscreen < 0) leftofscreen= 0;
  258. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  259. }
  260. void baselist::kd_panback() {
  261. leftofscreen -= xmax/3;
  262. if (leftofscreen < 0) leftofscreen= 0;
  263. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  264. }
  265. void baselist::kd_panon1() {
  266. leftofscreen++;
  267. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  268. if (leftofscreen < 0) leftofscreen= 0;
  269. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  270. }
  271. void baselist::kd_panback1() {
  272. leftofscreen--;
  273. if (leftofscreen < 0) leftofscreen= 0;
  274. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  275. }