awful debugging hacking
[dpkg] / dselect / methlist.cc
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
22 #include <config.h>
23 #include <compat.h>
24
25 #include <assert.h>
26 #include <errno.h>
27 #include <string.h>
28 #include <stdio.h>
29
30 #include <dpkg/i18n.h>
31 #include <dpkg/dpkg.h>
32 #include <dpkg/dpkg-db.h>
33 #include <dpkg/string.h>
34
35 #include "dselect.h"
36 #include "bindings.h"
37 #include "method.h"
38 #include "helpmsgs.h"
39
40 static keybindings methodlistbindings(methodlist_kinterps,methodlist_korgbindings);
41
42 const char *methodlist::itemname(int index) {
43 return table[index]->name;
44 }
45
46 void methodlist::kd_abort() { }
47
48 void methodlist::kd_quit() {
49 debug(dbg_general, "methodlist[%p]::kd_quit() setting coption=%p",
50 this, table[cursorline]);
51 coption= table[cursorline];
52 }
53
54 void methodlist::setheights() {
55 debug(dbg_general, "methodlist[%p]::setheights()", this);
56 baselist::setheights();
57 list_height++;
58 }
59
60 void methodlist::setwidths() {
61 debug(dbg_general, "methodlist[%p]::setwidths()", this);
62
63 col_cur_x = 0;
64
65 add_column(col_status, " ", 1);
66 add_column(col_name, _("Abbrev."), 14);
67 end_column(col_desc, _("Description"));
68 }
69
70 void methodlist::redrawtitle() {
71 if (title_height) {
72 mywerase(titlewin);
73 mvwaddnstr(titlewin,0,0,_("dselect - list of access methods"),xmax);
74 wnoutrefresh(titlewin);
75 }
76 }
77
78 void methodlist::redrawthisstate() {
79 if (!thisstate_height) return;
80 mywerase(thisstatepad);
81 wprintw(thisstatepad,
82 _("Access method '%s'."),
83 table[cursorline]->name);
84 pnoutrefresh(thisstatepad, 0,0, thisstate_row,0,
85 thisstate_row, min(total_width - 1, xmax - 1));
86 }
87
88 void methodlist::redraw1itemsel(int index, int selected) {
89 int i;
90 const char *p;
91
92 wattrset(listpad, part_attr[selected ? listsel : list]);
93 mvwaddch(listpad,index,0,
94 table[index] == coption ? '*' : ' ');
95 wattrset(listpad, part_attr[selected ? listsel : list]);
96 draw_column_sep(col_name, index);
97 draw_column_item(col_name, index, table[index]->name);
98
99 draw_column_sep(col_desc, index);
100 i = col_desc.width;
101 p= table[index]->summary ? table[index]->summary : "";
102 while (i>0 && *p && *p != '\n') {
103 waddch(listpad,*p);
104 i--; p++;
105 }
106 while (i>0) {
107 waddch(listpad,' ');
108 i--;
109 }
110 }
111
112 void methodlist::redrawcolheads() {
113 if (colheads_height) {
114 wattrset(colheadspad, part_attr[colheads]);
115 mywerase(colheadspad);
116 draw_column_head(col_status);
117 draw_column_head(col_name);
118 draw_column_head(col_desc);
119 }
120 refreshcolheads();
121 }
122
123 methodlist::methodlist() : baselist(&methodlistbindings) {
124 int newcursor= -1;
125
126 debug(dbg_general, "methodlist[%p]::methodlist()", this);
127
128 table= new struct dselect_option*[noptions];
129
130 struct dselect_option *opt, **ip;
131 for (opt=options, ip=table, nitems=0; opt; opt=opt->next, nitems++) {
132 if (opt == coption) { assert(newcursor==-1); newcursor= nitems; }
133 *ip++= opt;
134 }
135 assert(nitems==noptions);
136
137 if (newcursor==-1) newcursor= 0;
138 setcursor(newcursor);
139
140 debug(dbg_general, "methodlist[%p]::methodlist done; noptions=%d",
141 this, noptions);
142 }
143
144 methodlist::~methodlist() {
145 debug(dbg_general, "methodlist[%p]::~methodlist()", this);
146 delete[] table;
147 }
148
149 quitaction methodlist::display() {
150 int response;
151 const keybindings::interpretation *interp;
152
153 debug(dbg_general, "methodlist[%p]::display()", this);
154
155 setupsigwinch();
156 startdisplay();
157
158 debug(dbg_general, "methodlist[%p]::display() entering loop", this);
159 for (;;) {
160 if (whatinfo_height) wcursyncup(whatinfowin);
161 if (doupdate() == ERR) ohshite(_("doupdate failed"));
162 signallist= this;
163 sigwinch_mask(SIG_UNBLOCK);
164 do
165 response= getch();
166 while (response == ERR && errno == EINTR);
167 sigwinch_mask(SIG_BLOCK);
168 if (response == ERR) ohshite(_("getch failed"));
169 interp= (*bindings)(response);
170 debug(dbg_general, "methodlist[%p]::display() response=%d interp=%s",
171 this, response, interp ? interp->action : "[none]");
172 if (!interp) { beep(); continue; }
173 (this->*(interp->mfn))();
174 if (interp->qa != qa_noquit) break;
175 }
176 pop_cleanup(ehflag_normaltidy); // unset the SIGWINCH handler
177 enddisplay();
178
179 debug(dbg_general, "methodlist[%p]::display() done", this);
180
181 return interp->qa;
182 }
183
184 void methodlist::itd_description() {
185 whatinfovb(_("Explanation"));
186
187 wattrset(infopad, part_attr[info_head]);
188 waddstr(infopad, table[cursorline]->name);
189 waddstr(infopad," - ");
190 waddstr(infopad, table[cursorline]->summary);
191 wattrset(infopad, part_attr[info_body]);
192
193 const char *m= table[cursorline]->description;
194 if (str_is_unset(m))
195 m = _("No explanation available.");
196 waddstr(infopad,"\n\n");
197 wordwrapinfo(0,m);
198 }
199
200 void methodlist::redrawinfo() {
201 if (!info_height) return;
202 whatinfovb.reset();
203 werase(infopad); wmove(infopad,0,0);
204
205 debug(dbg_general, "methodlist[%p]::redrawinfo()", this);
206
207 itd_description();
208
209 int y,x;
210 getyx(infopad, y,x);
211 if (x) y++;
212 infolines= y;
213
214 refreshinfo();
215 }
216
217 const struct helpmenuentry *methodlist::helpmenulist() {
218 static const struct helpmenuentry list[]= {
219 { 'i', &hlp_methintro },
220 { 'k', &hlp_methkeys },
221 { 0 }
222 };
223 return list;
224 };