methlist.cc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * methlist.cc - list of access methods and options
  4. *
  5. * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
  6. * Copyright © 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 <https://www.gnu.org/licenses/>.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <assert.h>
  24. #include <errno.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27. #include <dpkg/i18n.h>
  28. #include <dpkg/dpkg.h>
  29. #include <dpkg/dpkg-db.h>
  30. #include <dpkg/string.h>
  31. #include "dselect.h"
  32. #include "bindings.h"
  33. #include "method.h"
  34. #include "helpmsgs.h"
  35. static keybindings methodlistbindings(methodlist_kinterps,methodlist_korgbindings);
  36. const char *methodlist::itemname(int index) {
  37. return table[index]->name;
  38. }
  39. void methodlist::kd_abort() { }
  40. void methodlist::kd_quit() {
  41. debug(dbg_general, "methodlist[%p]::kd_quit() setting coption=%p",
  42. this, table[cursorline]);
  43. coption= table[cursorline];
  44. }
  45. void methodlist::setheights() {
  46. debug(dbg_general, "methodlist[%p]::setheights()", this);
  47. baselist::setheights();
  48. list_height++;
  49. }
  50. void methodlist::setwidths() {
  51. debug(dbg_general, "methodlist[%p]::setwidths()", this);
  52. col_cur_x = 0;
  53. add_column(col_status, " ", 1);
  54. add_column(col_name, _("Abbrev."), 14);
  55. end_column(col_desc, _("Description"));
  56. }
  57. void methodlist::redrawtitle() {
  58. if (title_height) {
  59. mywerase(titlewin);
  60. mvwaddnstr(titlewin,0,0,_("dselect - list of access methods"),xmax);
  61. wnoutrefresh(titlewin);
  62. }
  63. }
  64. void methodlist::redrawthisstate() {
  65. if (!thisstate_height) return;
  66. mywerase(thisstatepad);
  67. wprintw(thisstatepad,
  68. _("Access method '%s'."),
  69. table[cursorline]->name);
  70. pnoutrefresh(thisstatepad, 0,0, thisstate_row,0,
  71. thisstate_row, min(total_width - 1, xmax - 1));
  72. }
  73. void methodlist::redraw1itemsel(int index, int selected) {
  74. int i;
  75. const char *p;
  76. wattrset(listpad, part_attr[selected ? listsel : list]);
  77. mvwaddch(listpad,index,0,
  78. table[index] == coption ? '*' : ' ');
  79. wattrset(listpad, part_attr[selected ? listsel : list]);
  80. draw_column_sep(col_name, index);
  81. draw_column_item(col_name, index, table[index]->name);
  82. draw_column_sep(col_desc, index);
  83. i = col_desc.width;
  84. p= table[index]->summary ? table[index]->summary : "";
  85. while (i>0 && *p && *p != '\n') {
  86. waddch(listpad,*p);
  87. i--; p++;
  88. }
  89. while (i>0) {
  90. waddch(listpad,' ');
  91. i--;
  92. }
  93. }
  94. void methodlist::redrawcolheads() {
  95. if (colheads_height) {
  96. wattrset(colheadspad, part_attr[colheads]);
  97. mywerase(colheadspad);
  98. draw_column_head(col_status);
  99. draw_column_head(col_name);
  100. draw_column_head(col_desc);
  101. }
  102. refreshcolheads();
  103. }
  104. methodlist::methodlist() : baselist(&methodlistbindings) {
  105. int newcursor= -1;
  106. debug(dbg_general, "methodlist[%p]::methodlist()", this);
  107. table= new struct dselect_option*[noptions];
  108. struct dselect_option *opt, **ip;
  109. for (opt=options, ip=table, nitems=0; opt; opt=opt->next, nitems++) {
  110. if (opt == coption) { assert(newcursor==-1); newcursor= nitems; }
  111. *ip++= opt;
  112. }
  113. assert(nitems==noptions);
  114. if (newcursor==-1) newcursor= 0;
  115. setcursor(newcursor);
  116. debug(dbg_general, "methodlist[%p]::methodlist done; noptions=%d",
  117. this, noptions);
  118. }
  119. methodlist::~methodlist() {
  120. debug(dbg_general, "methodlist[%p]::~methodlist()", this);
  121. delete[] table;
  122. }
  123. quitaction methodlist::display() {
  124. int response;
  125. const keybindings::interpretation *interp;
  126. debug(dbg_general, "methodlist[%p]::display()", this);
  127. setupsigwinch();
  128. startdisplay();
  129. debug(dbg_general, "methodlist[%p]::display() entering loop", this);
  130. for (;;) {
  131. if (whatinfo_height) wcursyncup(whatinfowin);
  132. if (doupdate() == ERR) ohshite(_("doupdate failed"));
  133. signallist= this;
  134. sigwinch_mask(SIG_UNBLOCK);
  135. do
  136. response= getch();
  137. while (response == ERR && errno == EINTR);
  138. sigwinch_mask(SIG_BLOCK);
  139. if (response == ERR) ohshite(_("getch failed"));
  140. interp= (*bindings)(response);
  141. debug(dbg_general, "methodlist[%p]::display() response=%d interp=%s",
  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. debug(dbg_general, "methodlist[%p]::display() done", this);
  150. return interp->qa;
  151. }
  152. void methodlist::itd_description() {
  153. whatinfovb(_("Explanation"));
  154. wattrset(infopad, part_attr[info_head]);
  155. waddstr(infopad, table[cursorline]->name);
  156. waddstr(infopad," - ");
  157. waddstr(infopad, table[cursorline]->summary);
  158. wattrset(infopad, part_attr[info_body]);
  159. const char *m= table[cursorline]->description;
  160. if (str_is_unset(m))
  161. 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. debug(dbg_general, "methodlist[%p]::redrawinfo()", this);
  170. itd_description();
  171. int y,x;
  172. getyx(infopad, y,x);
  173. if (x) y++;
  174. infolines= y;
  175. refreshinfo();
  176. }
  177. const struct helpmenuentry *methodlist::helpmenulist() {
  178. static const struct helpmenuentry list[]= {
  179. { 'i', &hlp_methintro },
  180. { 'k', &hlp_methkeys },
  181. { 0 }
  182. };
  183. return list;
  184. };