po: Update German man pages translation
[dpkg.git] / dselect / basecmds.cc
blob18f88e10a5c66580392f969791f9a67f6dbe5dc4
1 /*
2 * dselect - Debian package maintenance user interface
3 * basecmds.cc - base list keyboard commands display
5 * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2000,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>
33 #include "dselect.h"
34 #include "helpmsgs.h"
36 void baselist::kd_scrollon() {
37 topofscreen += list_height;
38 if (topofscreen > nitems - list_height) topofscreen= nitems - list_height;
39 if (topofscreen < 0) topofscreen= 0;
40 if (cursorline < topofscreen)
41 setcursor(topofscreen);
42 refreshlist();
45 void baselist::kd_scrollon1() {
46 if (topofscreen >= nitems - list_height) return;
47 topofscreen++;
48 if (cursorline < topofscreen)
49 setcursor(topofscreen);
50 refreshlist();
53 void baselist::kd_scrollback() {
54 topofscreen -= list_height;
55 if (topofscreen < 0) topofscreen= 0;
56 if (cursorline >= topofscreen + list_height)
57 setcursor(topofscreen + list_height - 1);
58 refreshlist();
61 void baselist::kd_scrollback1() {
62 if (topofscreen <= 0) return;
63 topofscreen--;
64 if (cursorline >= topofscreen + list_height)
65 setcursor(topofscreen + list_height - 1);
66 refreshlist();
69 void baselist::kd_top() {
70 topofscreen= 0; setcursor(0);
73 void baselist::kd_bottom() {
74 topofscreen= nitems - list_height;
75 if (topofscreen < 0) topofscreen= 0;
76 setcursor(min(topofscreen + list_height - 1, nitems - 1));
79 void baselist::kd_redraw() {
80 clearok(curscr,TRUE);
81 redrawall();
82 debug(dbg_general, "baselist[%p]::kd_redraw() done", this);
85 void baselist::kd_searchagain() {
86 if (!searchstring[0]) { beep(); return; }
87 dosearch();
90 bool
91 baselist::checksearch(char *str)
93 return true;
96 bool
97 baselist::matchsearch(int index)
99 int lendiff, searchlen, i;
100 const char *name;
102 name = itemname(index);
103 if (!name)
104 return false; /* Skip things without a name (separators). */
106 searchlen=strlen(searchstring);
107 lendiff = strlen(name) - searchlen;
108 for (i=0; i<=lendiff; i++)
109 if (strncasecmp(name + i, searchstring, searchlen) == 0)
110 return true;
112 return false;
115 void baselist::kd_search() {
116 char newsearchstring[128];
117 strcpy(newsearchstring,searchstring);
118 werase(querywin);
119 mvwaddstr(querywin,0,0, _("Search for ? "));
120 echo();
121 if (wgetnstr(querywin,newsearchstring,sizeof(newsearchstring)-1) == ERR)
122 searchstring[0]= 0;
123 resize_window();
124 noecho();
125 if (whatinfo_height) { touchwin(whatinfowin); refreshinfo(); }
126 else if (info_height) { touchwin(infopad); refreshinfo(); }
127 else if (thisstate_height) redrawthisstate();
128 else { touchwin(listpad); refreshlist(); }
129 if (newsearchstring[0]) {
130 if (!checksearch(newsearchstring)) {
131 beep();
132 return;
134 strcpy(searchstring,newsearchstring);
135 dosearch();
136 } else
137 kd_searchagain();
140 void
141 baselist::displayerror(const char *str)
143 const char *pr = _("Error: ");
144 int prlen=strlen(pr);
146 beep();
147 werase(querywin);
148 mvwaddstr(querywin,0,0,pr);
149 mvwaddstr(querywin,0,prlen,str);
150 wgetch(querywin);
151 if (whatinfo_height) { touchwin(whatinfowin); refreshinfo(); }
152 else if (info_height) { touchwin(infopad); refreshinfo(); }
153 else if (thisstate_height) redrawthisstate();
157 void baselist::displayhelp(const struct helpmenuentry *helpmenu, int key) {
158 int maxx, maxy, i, nextkey;
160 wbkgdset(stdscr, ' ' | part_attr[helpscreen]);
161 clearok(stdscr,TRUE);
162 for (;;) {
163 getmaxyx(stdscr, maxy, maxx);
164 werase(stdscr);
165 const struct helpmenuentry *hme = helpmenu;
166 while (hme->key && hme->key != key)
167 hme++;
168 if (hme->key) {
169 int x, y DPKG_ATTR_UNUSED;
171 attrset(part_attr[helpscreen]);
172 mvaddstr(1,0, gettext(hme->msg->text));
173 attrset(part_attr[title]);
174 mvaddstr(0,0, _("Help: "));
175 addstr(gettext(hme->msg->title));
176 getyx(stdscr,y,x);
177 while (++x<maxx) addch(' ');
178 attrset(part_attr[thisstate]);
179 mvaddstr(maxy-1,0,
180 _("Press ? for help menu, . for next topic, <space> to exit help."));
181 getyx(stdscr,y,x);
182 while (++x<maxx) addch(' ');
183 move(maxy,maxx);
184 attrset(A_NORMAL);
185 nextkey= hme[1].key;
186 } else {
187 mvaddstr(1,1, _("Help information is available under the following topics:"));
188 for (i=0, hme=helpmenu; hme->key; hme++,i++) {
189 attrset(A_BOLD);
190 mvaddch(i+3,3, hme->key);
191 attrset(A_NORMAL);
192 mvaddstr(i+3,6, gettext(hme->msg->title));
194 mvaddstr(i+4,1,
195 _("Press a key from the list above, <space> or 'q' to exit help,\n"
196 " or '.' (full stop) to read each help page in turn. "));
197 nextkey= helpmenu[0].key;
199 refresh();
200 do {
201 int curkey = key;
203 key = getch();
204 if (key == KEY_RESIZE) {
205 resize_window();
206 key = curkey;
208 } while (key == ERR && errno == EINTR);
209 if (key == EOF) ohshite(_("error reading keyboard in help"));
210 if (key == ' ' || key == 'q') {
211 break;
212 } else if (key == '?' || key == 'h') {
213 key= 0;
214 } else if (key == '.') {
215 key= nextkey;
218 werase(stdscr);
219 clearok(stdscr,TRUE);
220 wnoutrefresh(stdscr);
222 redrawtitle();
223 refreshcolheads();
224 refreshlist();
225 redrawthisstate();
226 refreshinfo();
227 wnoutrefresh(whatinfowin);
230 void baselist::kd_help() {
231 displayhelp(helpmenulist(),0);
234 void baselist::setcursor(int index) {
235 if (listpad && cursorline != -1) {
236 redrawitemsrange(cursorline,cursorline+1);
237 redraw1itemsel(cursorline,0);
239 if (cursorline != index) infotopofscreen= 0;
240 cursorline= index;
241 if (listpad) {
242 redrawitemsrange(cursorline,cursorline+1);
243 redraw1itemsel(cursorline,1);
244 refreshlist();
245 redrawthisstate();
247 redrawinfo();
250 void baselist::kd_down() {
251 int ncursor= cursorline;
252 // scroll by one line unless the bottom is already visible
253 // or we're in the top half of the screen ...
254 if (topofscreen < nitems - list_height &&
255 ncursor >= topofscreen + list_height - 3) topofscreen++;
256 // move cursor if there are any more ...
257 if (cursorline+1 < nitems) ncursor++;
258 setcursor(ncursor);
261 void baselist::kd_up() {
262 int ncursor= cursorline;
263 // scroll by one line if there are any lines not shown yet
264 // and we're not in the bottom half the screen ...
265 if (topofscreen > 0 &&
266 ncursor <= topofscreen + 2) topofscreen--;
267 // move cursor if there are any to move it to ...
268 if (cursorline > 0) ncursor--;
269 setcursor(ncursor);
272 void baselist::kd_iscrollon() {
273 infotopofscreen += info_height;
274 if (infotopofscreen > infolines - info_height)
275 infotopofscreen= infolines - info_height;
276 if (infotopofscreen < 0) infotopofscreen= 0;
277 refreshinfo();
280 void baselist::kd_iscrollback() {
281 infotopofscreen -= info_height;
282 if (infotopofscreen < 0) infotopofscreen= 0;
283 refreshinfo();
286 void baselist::kd_iscrollon1() {
287 if (infotopofscreen >= infolines - info_height) return;
288 infotopofscreen++; refreshinfo();
291 void baselist::kd_iscrollback1() {
292 if (infotopofscreen <= 0) return;
293 infotopofscreen--; refreshinfo();
296 void baselist::kd_panon() {
297 leftofscreen += xmax/3;
298 if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
299 if (leftofscreen < 0) leftofscreen= 0;
300 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
303 void baselist::kd_panback() {
304 leftofscreen -= xmax/3;
305 if (leftofscreen < 0) leftofscreen= 0;
306 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
309 void baselist::kd_panon1() {
310 leftofscreen++;
311 if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
312 if (leftofscreen < 0) leftofscreen= 0;
313 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
316 void baselist::kd_panback1() {
317 leftofscreen--;
318 if (leftofscreen < 0) leftofscreen= 0;
319 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();