basecmds.cc 8.6 KB

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