basecmds.cc 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * basecmds.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 published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but 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(min(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. debug(dbg_general, "baselist[%p]::kd_redraw() done", this);
  78. }
  79. void baselist::kd_searchagain() {
  80. if (!searchstring[0]) { beep(); return; }
  81. dosearch();
  82. }
  83. bool
  84. baselist::checksearch(char *str)
  85. {
  86. return true;
  87. }
  88. bool
  89. baselist::matchsearch(int index)
  90. {
  91. int lendiff, searchlen, i;
  92. const char *name;
  93. name = itemname(index);
  94. if (!name)
  95. return false; /* Skip things without a name (seperators). */
  96. searchlen=strlen(searchstring);
  97. lendiff = strlen(name) - searchlen;
  98. for (i=0; i<=lendiff; i++)
  99. if (!strncasecmp(name + i, searchstring, searchlen))
  100. return true;
  101. return false;
  102. }
  103. void baselist::kd_search() {
  104. char newsearchstring[128];
  105. strcpy(newsearchstring,searchstring);
  106. werase(querywin);
  107. mvwaddstr(querywin,0,0, _("Search for ? "));
  108. echo(); /* FIXME: ncurses documentation or implementation. */
  109. if (wgetnstr(querywin,newsearchstring,sizeof(newsearchstring)-1) == ERR)
  110. searchstring[0]= 0;
  111. raise(SIGWINCH); /* FIXME: ncurses and xterm arrow keys. */
  112. noecho(); /* FIXME: ncurses. */
  113. if (whatinfo_height) { touchwin(whatinfowin); refreshinfo(); }
  114. else if (info_height) { touchwin(infopad); refreshinfo(); }
  115. else if (thisstate_height) redrawthisstate();
  116. else { touchwin(listpad); refreshlist(); }
  117. if (newsearchstring[0]) {
  118. if (!checksearch(newsearchstring)) {
  119. beep();
  120. return;
  121. }
  122. strcpy(searchstring,newsearchstring);
  123. dosearch();
  124. } else
  125. kd_searchagain();
  126. }
  127. void baselist::displayerror(const char* str) {
  128. const char* pr = _("Error: ");
  129. int prlen=strlen(pr);
  130. beep();
  131. werase(querywin);
  132. mvwaddstr(querywin,0,0,pr);
  133. mvwaddstr(querywin,0,prlen,str);
  134. wgetch(querywin);
  135. if (whatinfo_height) { touchwin(whatinfowin); refreshinfo(); }
  136. else if (info_height) { touchwin(infopad); refreshinfo(); }
  137. else if (thisstate_height) redrawthisstate();
  138. }
  139. void baselist::displayhelp(const struct helpmenuentry *helpmenu, int key) {
  140. int maxx, maxy, i, nextkey;
  141. getmaxyx(stdscr,maxy,maxx);
  142. wbkgdset(stdscr, ' ' | part_attr[helpscreen]);
  143. clearok(stdscr,TRUE);
  144. for (;;) {
  145. werase(stdscr);
  146. const struct helpmenuentry *hme = helpmenu;
  147. while (hme->key && hme->key != key)
  148. hme++;
  149. if (hme->key) {
  150. int x, y DPKG_ATTR_UNUSED;
  151. attrset(part_attr[helpscreen]);
  152. mvaddstr(1,0, gettext(hme->msg->text));
  153. attrset(part_attr[title]);
  154. mvaddstr(0,0, _("Help: "));
  155. addstr(gettext(hme->msg->title));
  156. getyx(stdscr,y,x);
  157. while (++x<maxx) addch(' ');
  158. attrset(part_attr[thisstate]);
  159. mvaddstr(maxy-1,0,
  160. _("Press ? for help menu, . for next topic, <space> to exit help."));
  161. getyx(stdscr,y,x);
  162. while (++x<maxx) addch(' ');
  163. move(maxy,maxx);
  164. attrset(A_NORMAL);
  165. nextkey= hme[1].key;
  166. } else {
  167. mvaddstr(1,1, _("Help information is available under the following topics:"));
  168. for (i=0, hme=helpmenu; hme->key; hme++,i++) {
  169. attrset(A_BOLD);
  170. mvaddch(i+3,3, hme->key);
  171. attrset(A_NORMAL);
  172. mvaddstr(i+3,6, gettext(hme->msg->title));
  173. }
  174. mvaddstr(i+4,1,
  175. _("Press a key from the list above, <space> or `q' to exit help,\n"
  176. " or `.' (full stop) to read each help page in turn. "));
  177. nextkey= helpmenu[0].key;
  178. }
  179. refresh();
  180. key= getch();
  181. if (key == EOF) ohshite(_("error reading keyboard in help"));
  182. if (key == ' ' || key == 'q') {
  183. break;
  184. } else if (key == '?' || key == 'h') {
  185. key= 0;
  186. } else if (key == '.') {
  187. key= nextkey;
  188. }
  189. }
  190. werase(stdscr);
  191. clearok(stdscr,TRUE);
  192. wnoutrefresh(stdscr);
  193. redrawtitle();
  194. refreshcolheads();
  195. refreshlist();
  196. redrawthisstate();
  197. refreshinfo();
  198. wnoutrefresh(whatinfowin);
  199. }
  200. void baselist::kd_help() {
  201. displayhelp(helpmenulist(),0);
  202. }
  203. void baselist::setcursor(int index) {
  204. if (listpad && cursorline != -1) {
  205. redrawitemsrange(cursorline,cursorline+1);
  206. redraw1itemsel(cursorline,0);
  207. }
  208. if (cursorline != index) infotopofscreen= 0;
  209. cursorline= index;
  210. if (listpad) {
  211. redrawitemsrange(cursorline,cursorline+1);
  212. redraw1itemsel(cursorline,1);
  213. refreshlist();
  214. redrawthisstate();
  215. }
  216. redrawinfo();
  217. }
  218. void baselist::kd_down() {
  219. int ncursor= cursorline;
  220. // scroll by one line unless the bottom is already visible
  221. // or we're in the top half of the screen ...
  222. if (topofscreen < nitems - list_height &&
  223. ncursor >= topofscreen + list_height - 3) topofscreen++;
  224. // move cursor if there are any more ...
  225. if (cursorline+1 < nitems) ncursor++;
  226. setcursor(ncursor);
  227. }
  228. void baselist::kd_up() {
  229. int ncursor= cursorline;
  230. // scroll by one line if there are any lines not shown yet
  231. // and we're not in the bottom half the screen ...
  232. if (topofscreen > 0 &&
  233. ncursor <= topofscreen + 2) topofscreen--;
  234. // move cursor if there are any to move it to ...
  235. if (cursorline > 0) ncursor--;
  236. setcursor(ncursor);
  237. }
  238. void baselist::kd_iscrollon() {
  239. infotopofscreen += info_height;
  240. if (infotopofscreen > infolines - info_height)
  241. infotopofscreen= infolines - info_height;
  242. if (infotopofscreen < 0) infotopofscreen= 0;
  243. refreshinfo();
  244. }
  245. void baselist::kd_iscrollback() {
  246. infotopofscreen -= info_height;
  247. if (infotopofscreen < 0) infotopofscreen= 0;
  248. refreshinfo();
  249. }
  250. void baselist::kd_iscrollon1() {
  251. if (infotopofscreen >= infolines - info_height) return;
  252. infotopofscreen++; refreshinfo();
  253. }
  254. void baselist::kd_iscrollback1() {
  255. if (infotopofscreen <= 0) return;
  256. infotopofscreen--; refreshinfo();
  257. }
  258. void baselist::kd_panon() {
  259. leftofscreen += xmax/3;
  260. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  261. if (leftofscreen < 0) leftofscreen= 0;
  262. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  263. }
  264. void baselist::kd_panback() {
  265. leftofscreen -= xmax/3;
  266. if (leftofscreen < 0) leftofscreen= 0;
  267. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  268. }
  269. void baselist::kd_panon1() {
  270. leftofscreen++;
  271. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  272. if (leftofscreen < 0) leftofscreen= 0;
  273. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  274. }
  275. void baselist::kd_panback1() {
  276. leftofscreen--;
  277. if (leftofscreen < 0) leftofscreen= 0;
  278. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  279. }