basecmds.cc 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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 <dpkg/dpkg.h>
  28. #include <dpkg/dpkg-db.h>
  29. #include "dselect.h"
  30. #include "helpmsgs.h"
  31. void baselist::kd_scrollon() {
  32. topofscreen += list_height;
  33. if (topofscreen > nitems - list_height) topofscreen= nitems - list_height;
  34. if (topofscreen < 0) topofscreen= 0;
  35. if (cursorline < topofscreen)
  36. setcursor(topofscreen);
  37. refreshlist();
  38. }
  39. void baselist::kd_scrollon1() {
  40. if (topofscreen >= nitems - list_height) return;
  41. topofscreen++;
  42. if (cursorline < topofscreen)
  43. setcursor(topofscreen);
  44. refreshlist();
  45. }
  46. void baselist::kd_scrollback() {
  47. topofscreen -= list_height;
  48. if (topofscreen < 0) topofscreen= 0;
  49. if (cursorline >= topofscreen + list_height)
  50. setcursor(topofscreen + list_height - 1);
  51. refreshlist();
  52. }
  53. void baselist::kd_scrollback1() {
  54. if (topofscreen <= 0) return;
  55. topofscreen--;
  56. if (cursorline >= topofscreen + list_height)
  57. setcursor(topofscreen + list_height - 1);
  58. refreshlist();
  59. }
  60. void baselist::kd_top() {
  61. topofscreen= 0; setcursor(0);
  62. }
  63. void baselist::kd_bottom() {
  64. topofscreen= nitems - list_height;
  65. if (topofscreen < 0) topofscreen= 0;
  66. setcursor(lesserint(topofscreen + list_height - 1, nitems-1));
  67. }
  68. void baselist::kd_redraw() {
  69. //#define RFSH(x) werase(x); redrawwin(x)
  70. // RFSH(listpad);
  71. // RFSH(infopad);
  72. // RFSH(colheadspad);
  73. // RFSH(thisstatepad);
  74. // RFSH(titlewin);
  75. // RFSH(whatinfowin); /* FIXME: why does ncurses need this? */
  76. clearok(curscr,TRUE);
  77. redrawall();
  78. if (debug) fprintf(debug,"baselist[%p]::kd_redraw() done\n",this);
  79. }
  80. void baselist::kd_searchagain() {
  81. if (!searchstring[0]) { beep(); return; }
  82. dosearch();
  83. }
  84. int baselist::checksearch(char* str) {
  85. return 1;
  86. }
  87. int baselist::matchsearch(int index) {
  88. int lendiff, searchlen, i;
  89. const char* thisname;
  90. thisname=itemname(index);
  91. if (!thisname) return 0; /* Skip things without a name (seperators) */
  92. searchlen=strlen(searchstring);
  93. lendiff= strlen(thisname) - searchlen;
  94. for (i=0; i<=lendiff; i++)
  95. if (!strncasecmp(thisname + i, searchstring, searchlen))
  96. return 1;
  97. return 0;
  98. }
  99. void baselist::kd_search() {
  100. char newsearchstring[128];
  101. strcpy(newsearchstring,searchstring);
  102. werase(querywin);
  103. mvwaddstr(querywin,0,0, _("Search for ? "));
  104. echo(); /* FIXME: ncurses documentation or implementation. */
  105. if (wgetnstr(querywin,newsearchstring,sizeof(newsearchstring)-1) == ERR)
  106. searchstring[0]= 0;
  107. raise(SIGWINCH); /* FIXME: ncurses and xterm arrow keys. */
  108. noecho(); /* FIXME: ncurses. */
  109. if (whatinfo_height) { touchwin(whatinfowin); refreshinfo(); }
  110. else if (info_height) { touchwin(infopad); refreshinfo(); }
  111. else if (thisstate_height) redrawthisstate();
  112. else { touchwin(listpad); refreshlist(); }
  113. if (newsearchstring[0]) {
  114. if (!checksearch(newsearchstring)) {
  115. beep();
  116. return;
  117. }
  118. strcpy(searchstring,newsearchstring);
  119. dosearch();
  120. } else
  121. kd_searchagain();
  122. }
  123. void baselist::displayerror(const char* str) {
  124. const char* pr = _("Error: ");
  125. int prlen=strlen(pr);
  126. beep();
  127. werase(querywin);
  128. mvwaddstr(querywin,0,0,pr);
  129. mvwaddstr(querywin,0,prlen,str);
  130. wgetch(querywin);
  131. if (whatinfo_height) { touchwin(whatinfowin); refreshinfo(); }
  132. else if (info_height) { touchwin(infopad); refreshinfo(); }
  133. else if (thisstate_height) redrawthisstate();
  134. }
  135. void baselist::displayhelp(const struct helpmenuentry *helpmenu, int key) {
  136. int maxx, maxy, i, y, x, nextkey;
  137. getmaxyx(stdscr,maxy,maxx);
  138. wbkgdset(stdscr, ' ' | helpscreen_attr);
  139. clearok(stdscr,TRUE);
  140. for (;;) {
  141. werase(stdscr);
  142. const struct helpmenuentry *hme = helpmenu;
  143. while (hme->key && hme->key != key)
  144. 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, . for next topic, <space> 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, <space> or `q' to exit help,\n"
  171. " or `.' (full stop) 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 == ' ' || key == 'q') {
  178. break;
  179. } else if (key == '?' || key == 'h') {
  180. key= 0;
  181. } else if (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. }