Dpkg::Source::Package::V2: Mark single-debian-patch as not needing forwarding
[dpkg.git] / dselect / methlist.cc
blob7a742a253c980ae4635bd177f79080756103e97f
1 /*
2 * dselect - Debian package maintenance user interface
3 * methlist.cc - list of access methods and options
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2001 Wichert Akkerman <wakkerma@debian.org>
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.
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.
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/>.
22 #include <config.h>
23 #include <compat.h>
25 #include <errno.h>
26 #include <string.h>
27 #include <stdio.h>
29 #include <dpkg/i18n.h>
30 #include <dpkg/dpkg.h>
31 #include <dpkg/dpkg-db.h>
32 #include <dpkg/string.h>
34 #include "dselect.h"
35 #include "bindings.h"
36 #include "method.h"
37 #include "helpmsgs.h"
39 static keybindings methodlistbindings(methodlist_kinterps,methodlist_korgbindings);
41 const char *methodlist::itemname(int index) {
42 return table[index]->name;
45 void methodlist::kd_abort() { }
47 void methodlist::kd_quit() {
48 debug(dbg_general, "methodlist[%p]::kd_quit() setting coption=%p",
49 this, table[cursorline]);
50 coption= table[cursorline];
53 void methodlist::setheights() {
54 debug(dbg_general, "methodlist[%p]::setheights()", this);
55 baselist::setheights();
56 list_height++;
59 void methodlist::setwidths() {
60 debug(dbg_general, "methodlist[%p]::setwidths()", this);
62 col_cur_x = 0;
64 add_column(col_status, " ", 1);
65 add_column(col_name, _("Abbrev."), 14);
66 end_column(col_desc, _("Description"));
69 void methodlist::redrawtitle() {
70 if (title_height) {
71 mywerase(titlewin);
72 mvwaddnstr(titlewin,0,0,_("dselect - list of access methods"),xmax);
73 wnoutrefresh(titlewin);
77 void methodlist::redrawthisstate() {
78 if (!thisstate_height) return;
79 mywerase(thisstatepad);
80 wprintw(thisstatepad,
81 _("Access method '%s'."),
82 table[cursorline]->name);
83 pnoutrefresh(thisstatepad, 0,0, thisstate_row,0,
84 thisstate_row, min(total_width - 1, xmax - 1));
87 void methodlist::redraw1itemsel(int index, int selected) {
88 int i;
89 const char *p;
91 wattrset(listpad, part_attr[selected ? listsel : list]);
92 mvwaddch(listpad,index,0,
93 table[index] == coption ? '*' : ' ');
94 wattrset(listpad, part_attr[selected ? listsel : list]);
95 draw_column_sep(col_name, index);
96 draw_column_item(col_name, index, table[index]->name);
98 draw_column_sep(col_desc, index);
99 i = col_desc.width;
100 p= table[index]->summary ? table[index]->summary : "";
101 while (i>0 && *p && *p != '\n') {
102 waddch(listpad,*p);
103 i--; p++;
105 while (i>0) {
106 waddch(listpad,' ');
107 i--;
111 void methodlist::redrawcolheads() {
112 if (colheads_height) {
113 wattrset(colheadspad, part_attr[colheads]);
114 mywerase(colheadspad);
115 draw_column_head(col_status);
116 draw_column_head(col_name);
117 draw_column_head(col_desc);
119 refreshcolheads();
122 methodlist::methodlist() : baselist(&methodlistbindings) {
123 int newcursor= -1;
125 debug(dbg_general, "methodlist[%p]::methodlist()", this);
127 table= new struct dselect_option*[noptions];
129 struct dselect_option *opt, **ip;
130 for (opt=options, ip=table, nitems=0; opt; opt=opt->next, nitems++) {
131 if (opt == coption) {
132 if (newcursor != -1)
133 internerr("multiple methods with same index");
134 newcursor = nitems;
136 *ip++= opt;
138 if (nitems != noptions)
139 internerr("inconsistent number of items: ntimes=%d != noptions=%d",
140 nitems, noptions);
142 if (newcursor==-1) newcursor= 0;
143 setcursor(newcursor);
145 debug(dbg_general, "methodlist[%p]::methodlist done; noptions=%d",
146 this, noptions);
149 methodlist::~methodlist() {
150 debug(dbg_general, "methodlist[%p]::~methodlist()", this);
151 delete[] table;
154 quitaction methodlist::display() {
155 int response;
156 const keybindings::interpretation *interp;
158 debug(dbg_general, "methodlist[%p]::display()", this);
160 startdisplay();
162 debug(dbg_general, "methodlist[%p]::display() entering loop", this);
163 for (;;) {
164 if (whatinfo_height) wcursyncup(whatinfowin);
165 if (doupdate() == ERR) ohshite(_("doupdate failed"));
166 do {
167 response = getch();
168 if (response == KEY_RESIZE) {
169 resize_window();
170 continue;
172 } while (response == ERR && errno == EINTR);
173 if (response == ERR) ohshite(_("getch failed"));
174 interp= (*bindings)(response);
175 debug(dbg_general, "methodlist[%p]::display() response=%d interp=%s",
176 this, response, interp ? interp->action : "[none]");
177 if (!interp)
178 continue;
179 (this->*(interp->mfn))();
180 if (interp->qa != qa_noquit) break;
182 enddisplay();
184 debug(dbg_general, "methodlist[%p]::display() done", this);
186 return interp->qa;
189 void methodlist::itd_description() {
190 whatinfovb(_("Explanation"));
192 wattrset(infopad, part_attr[info_head]);
193 waddstr(infopad, table[cursorline]->name);
194 waddstr(infopad," - ");
195 waddstr(infopad, table[cursorline]->summary);
196 wattrset(infopad, part_attr[info_body]);
198 const char *m= table[cursorline]->description;
199 if (str_is_unset(m))
200 m = _("No explanation available.");
201 waddstr(infopad,"\n\n");
202 wordwrapinfo(0,m);
205 void methodlist::redrawinfo() {
206 if (!info_height) return;
207 whatinfovb.reset();
208 werase(infopad); wmove(infopad,0,0);
210 debug(dbg_general, "methodlist[%p]::redrawinfo()", this);
212 itd_description();
214 int y,x;
215 getyx(infopad, y,x);
216 if (x) y++;
217 infolines= y;
219 refreshinfo();
222 const struct helpmenuentry *methodlist::helpmenulist() {
223 static const struct helpmenuentry list[]= {
224 { 'i', &hlp_methintro },
225 { 'k', &hlp_methkeys },
226 { 0 }
228 return list;