dpkg (1.2.12); priority=LOW
[dpkg.git] / dselect / methlist.cc
blobc81ce8e1c1834f49ce1c083c53390a4b14fe5887
1 /*
2 * dselect - Debian GNU/Linux package maintenance user interface
3 * methlist.cc - list of access methods and options
5 * Copyright (C) 1995 Ian Jackson <iwj10@cus.cam.ac.uk>
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.
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.
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.
22 #include <stdio.h>
23 #include <string.h>
24 #include <ncurses.h>
25 #include <assert.h>
26 #include <signal.h>
28 extern "C" {
29 #include "config.h"
30 #include "dpkg.h"
31 #include "dpkg-db.h"
33 #include "dselect.h"
34 #include "bindings.h"
35 #include "method.h"
36 #include "helpmsgs.h"
38 static keybindings methodlistbindings(methodlist_kinterps,methodlist_korgbindings);
40 const char *methodlist::itemname(int index) {
41 return table[index]->name;
44 void methodlist::kd_abort() { }
46 void methodlist::kd_quit() {
47 if (debug) fprintf(debug,"methodlist[%p]::kd_quit() setting coption=%p\n",
48 this, table[cursorline]);
49 coption= table[cursorline];
52 void methodlist::setwidths() {
53 if (debug) fprintf(debug,"methodlist[%p]::setwidths()\n",this);
55 status_width= 1;
56 gap_width= 1;
57 name_width= 14;
58 name_column= status_width + gap_width;
59 description_column= name_column + name_width + gap_width;
61 total_width= TOTAL_LIST_WIDTH;
62 description_width= total_width - description_column;
65 void methodlist::redrawtitle() {
66 if (title_height) {
67 mywerase(titlewin);
68 mvwaddnstr(titlewin,0,0,"dselect - list of access methods",xmax);
69 wnoutrefresh(titlewin);
73 void methodlist::redrawthisstate() {
74 if (!thisstate_height) return;
75 mywerase(thisstatepad);
76 wprintw(thisstatepad,
77 "Access method `%s'.",
78 table[cursorline]->name);
79 pnoutrefresh(thisstatepad, 0,0, thisstate_row,0,
80 thisstate_row, lesserint(total_width - 1, xmax - 1));
83 void methodlist::redraw1itemsel(int index, int selected) {
84 int i;
85 const char *p;
87 wattrset(listpad, selected ? listsel_attr : list_attr);
88 mvwaddch(listpad,index,0,
89 table[index] == coption ? '*' : ' ');
90 wattrset(listpad, selected ? listsel_attr : list_attr);
91 mvwprintw(listpad,index,name_column-1, " %-*.*s ",
92 name_width, name_width, table[index]->name);
94 i= description_width;
95 p= table[index]->summary ? table[index]->summary : "";
96 while (i>0 && *p && *p != '\n') {
97 waddch(listpad,*p);
98 i--; p++;
100 while (i>0) {
101 waddch(listpad,' ');
102 i--;
106 void methodlist::redrawcolheads() {
107 if (colheads_height) {
108 wattrset(colheadspad,colheads_attr);
109 mywerase(colheadspad);
110 mvwaddstr(colheadspad,0,0, " ");
111 mvwaddnstr(colheadspad,0,name_column, "Abbrev.", name_width);
112 mvwaddnstr(colheadspad,0,description_column, "Description", description_width);
114 refreshcolheads();
117 methodlist::methodlist() : baselist(&methodlistbindings) {
118 int newcursor= -1;
120 if (debug)
121 fprintf(debug,"methodlist[%p]::methodlist()\n",this);
123 table= new struct option*[noptions];
125 struct option *opt, **ip;
126 for (opt=options, ip=table, nitems=0; opt; opt=opt->next, nitems++) {
127 if (opt == coption) { assert(newcursor==-1); newcursor= nitems; }
128 *ip++= opt;
130 assert(nitems==noptions);
132 if (newcursor==-1) newcursor= 0;
133 setcursor(newcursor);
135 if (debug)
136 fprintf(debug,"methodlist[%p]::methodlist done; noptions=%d\n", this, noptions);
139 methodlist::~methodlist() {
140 if (debug) fprintf(debug,"methodlist[%p]::~methodlist()\n",this);
141 delete[] table;
144 quitaction methodlist::display() {
145 int response;
146 const keybindings::interpretation *interp;
148 if (debug) fprintf(debug,"methodlist[%p]::display()\n",this);
150 setupsigwinch();
151 startdisplay();
153 if (debug) fprintf(debug,"methodlist[%p]::display() entering loop\n",this);
154 for (;;) {
155 if (whatinfo_height) wcursyncup(whatinfowin);
156 if (doupdate() == ERR) ohshite("doupdate failed");
157 signallist= this;
158 if (sigprocmask(SIG_UNBLOCK,&sigwinchset,0)) ohshite("failed to unblock SIGWINCH");
159 response= getch();
160 if (sigprocmask(SIG_BLOCK,&sigwinchset,0)) ohshite("failed to re-block SIGWINCH");
161 if (response == ERR) ohshite("getch failed");
162 interp= (*bindings)(response);
163 if (debug)
164 fprintf(debug,"methodlist[%p]::display() response=%d interp=%s\n",
165 this,response, interp ? interp->action : "[none]");
166 if (!interp) { beep(); continue; }
167 (this->*(interp->mfn))();
168 if (interp->qa != qa_noquit) break;
170 pop_cleanup(ehflag_normaltidy); // unset the SIGWINCH handler
171 enddisplay();
173 if (debug) fprintf(debug,"methodlist[%p]::display() done\n",this);
175 return interp->qa;
178 void methodlist::itd_description() {
179 whatinfovb("explanation of ");
180 whatinfovb(table[cursorline]->name);
182 wattrset(infopad,info_headattr);
183 waddstr(infopad, table[cursorline]->name);
184 waddstr(infopad," - ");
185 waddstr(infopad, table[cursorline]->summary);
186 wattrset(infopad,info_attr);
188 const char *m= table[cursorline]->description;
189 if (!m || !*m) m= "No explanation available.";
190 waddstr(infopad,"\n\n");
191 wordwrapinfo(0,m);
194 void methodlist::redrawinfo() {
195 if (!info_height) return;
196 whatinfovb.reset();
197 werase(infopad); wmove(infopad,0,0);
199 if (debug) fprintf(debug,"methodlist[%p]::redrawinfo()\n", this);
201 itd_description();
203 whatinfovb.terminate();
204 int y,x;
205 getyx(infopad, y,x);
206 if (x) y++;
207 infolines= y;
209 refreshinfo();
212 const struct helpmenuentry *methodlist::helpmenulist() {
213 static const struct helpmenuentry list[]= {
214 { 'i', &hlp_methintro },
215 { 'k', &hlp_methkeys },
216 { 0 }
218 return list;