methlist.cc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * dselect - Debian GNU/Linux package maintenance user interface
  3. * methlist.cc - list of access methods and options
  4. *
  5. * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with this; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <curses.h>
  24. #include <assert.h>
  25. #include <signal.h>
  26. #include <errno.h>
  27. extern "C" {
  28. #include <config.h>
  29. #include <dpkg.h>
  30. #include <dpkg-db.h>
  31. }
  32. #include "dselect.h"
  33. #include "bindings.h"
  34. #include "method.h"
  35. #include "helpmsgs.h"
  36. static keybindings methodlistbindings(methodlist_kinterps,methodlist_korgbindings);
  37. const char *methodlist::itemname(int index) {
  38. return table[index]->name;
  39. }
  40. void methodlist::kd_abort() { }
  41. void methodlist::kd_quit() {
  42. if (debug) fprintf(debug,"methodlist[%p]::kd_quit() setting coption=%p\n",
  43. this, table[cursorline]);
  44. coption= table[cursorline];
  45. }
  46. void methodlist::setwidths() {
  47. if (debug) fprintf(debug,"methodlist[%p]::setwidths()\n",this);
  48. status_width= 1;
  49. gap_width= 1;
  50. name_width= 14;
  51. name_column= status_width + gap_width;
  52. description_column= name_column + name_width + gap_width;
  53. total_width= TOTAL_LIST_WIDTH;
  54. description_width= total_width - description_column;
  55. }
  56. void methodlist::redrawtitle() {
  57. if (title_height) {
  58. mywerase(titlewin);
  59. mvwaddnstr(titlewin,0,0,_("dselect - list of access methods"),xmax);
  60. wnoutrefresh(titlewin);
  61. }
  62. }
  63. void methodlist::redrawthisstate() {
  64. if (!thisstate_height) return;
  65. mywerase(thisstatepad);
  66. wprintw(thisstatepad,
  67. _("Access method `%s'."),
  68. table[cursorline]->name);
  69. pnoutrefresh(thisstatepad, 0,0, thisstate_row,0,
  70. thisstate_row, lesserint(total_width - 1, xmax - 1));
  71. }
  72. void methodlist::redraw1itemsel(int index, int selected) {
  73. int i;
  74. const char *p;
  75. wattrset(listpad, selected ? listsel_attr : list_attr);
  76. mvwaddch(listpad,index,0,
  77. table[index] == coption ? '*' : ' ');
  78. wattrset(listpad, selected ? listsel_attr : list_attr);
  79. mvwprintw(listpad,index,name_column-1, " %-*.*s ",
  80. name_width, name_width, table[index]->name);
  81. i= description_width;
  82. p= table[index]->summary ? table[index]->summary : "";
  83. while (i>0 && *p && *p != '\n') {
  84. waddch(listpad,*p);
  85. i--; p++;
  86. }
  87. while (i>0) {
  88. waddch(listpad,' ');
  89. i--;
  90. }
  91. }
  92. void methodlist::redrawcolheads() {
  93. if (colheads_height) {
  94. wattrset(colheadspad,colheads_attr);
  95. mywerase(colheadspad);
  96. mvwaddstr(colheadspad,0,0, " ");
  97. mvwaddnstr(colheadspad,0,name_column, _("Abbrev."), name_width);
  98. mvwaddnstr(colheadspad,0,description_column, _("Description"), description_width);
  99. }
  100. refreshcolheads();
  101. }
  102. methodlist::methodlist() : baselist(&methodlistbindings) {
  103. int newcursor= -1;
  104. if (debug)
  105. fprintf(debug,"methodlist[%p]::methodlist()\n",this);
  106. table= new struct option*[noptions];
  107. struct option *opt, **ip;
  108. for (opt=options, ip=table, nitems=0; opt; opt=opt->next, nitems++) {
  109. if (opt == coption) { assert(newcursor==-1); newcursor= nitems; }
  110. *ip++= opt;
  111. }
  112. assert(nitems==noptions);
  113. if (newcursor==-1) newcursor= 0;
  114. setcursor(newcursor);
  115. if (debug)
  116. fprintf(debug,"methodlist[%p]::methodlist done; noptions=%d\n", this, noptions);
  117. }
  118. methodlist::~methodlist() {
  119. if (debug) fprintf(debug,"methodlist[%p]::~methodlist()\n",this);
  120. delete[] table;
  121. }
  122. quitaction methodlist::display() {
  123. int response;
  124. const keybindings::interpretation *interp;
  125. if (debug) fprintf(debug,"methodlist[%p]::display()\n",this);
  126. setupsigwinch();
  127. startdisplay();
  128. if (debug) fprintf(debug,"methodlist[%p]::display() entering loop\n",this);
  129. for (;;) {
  130. if (whatinfo_height) wcursyncup(whatinfowin);
  131. if (doupdate() == ERR) ohshite(_("doupdate failed"));
  132. signallist= this;
  133. if (sigprocmask(SIG_UNBLOCK,&sigwinchset,0)) ohshite(_("failed to unblock SIGWINCH"));
  134. do
  135. response= getch();
  136. while (response == ERR && errno == EINTR);
  137. if (sigprocmask(SIG_BLOCK,&sigwinchset,0)) ohshite(_("failed to re-block SIGWINCH"));
  138. if (response == ERR) ohshite(_("getch failed"));
  139. interp= (*bindings)(response);
  140. if (debug)
  141. fprintf(debug,"methodlist[%p]::display() response=%d interp=%s\n",
  142. this,response, interp ? interp->action : _("[none]"));
  143. if (!interp) { beep(); continue; }
  144. (this->*(interp->mfn))();
  145. if (interp->qa != qa_noquit) break;
  146. }
  147. pop_cleanup(ehflag_normaltidy); // unset the SIGWINCH handler
  148. enddisplay();
  149. if (debug) fprintf(debug,"methodlist[%p]::display() done\n",this);
  150. return interp->qa;
  151. }
  152. void methodlist::itd_description() {
  153. whatinfovb(_("explanation of "));
  154. whatinfovb(table[cursorline]->name);
  155. wattrset(infopad,info_headattr);
  156. waddstr(infopad, table[cursorline]->name);
  157. waddstr(infopad," - ");
  158. waddstr(infopad, table[cursorline]->summary);
  159. wattrset(infopad,info_attr);
  160. const char *m= table[cursorline]->description;
  161. if (!m || !*m) m= _("No explanation available.");
  162. waddstr(infopad,"\n\n");
  163. wordwrapinfo(0,m);
  164. }
  165. void methodlist::redrawinfo() {
  166. if (!info_height) return;
  167. whatinfovb.reset();
  168. werase(infopad); wmove(infopad,0,0);
  169. if (debug) fprintf(debug,"methodlist[%p]::redrawinfo()\n", this);
  170. itd_description();
  171. whatinfovb.terminate();
  172. int y,x;
  173. getyx(infopad, y,x);
  174. if (x) y++;
  175. infolines= y;
  176. refreshinfo();
  177. }
  178. const struct helpmenuentry *methodlist::helpmenulist() {
  179. static const struct helpmenuentry list[]= {
  180. { 'i', &hlp_methintro },
  181. { 'k', &hlp_methkeys },
  182. { 0 }
  183. };
  184. return list;
  185. };