basecmds.cc 8.5 KB

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