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/>.
29 #include <dpkg/i18n.h>
30 #include <dpkg/dpkg.h>
31 #include <dpkg/dpkg-db.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
);
45 void baselist::kd_scrollon1() {
46 if (topofscreen
>= nitems
- list_height
) return;
48 if (cursorline
< topofscreen
)
49 setcursor(topofscreen
);
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);
61 void baselist::kd_scrollback1() {
62 if (topofscreen
<= 0) return;
64 if (cursorline
>= topofscreen
+ list_height
)
65 setcursor(topofscreen
+ list_height
- 1);
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() {
82 debug(dbg_general
, "baselist[%p]::kd_redraw() done", this);
85 void baselist::kd_searchagain() {
86 if (!searchstring
[0]) { beep(); return; }
91 baselist::checksearch(char *str
)
97 baselist::matchsearch(int index
)
99 int lendiff
, searchlen
, i
;
102 name
= itemname(index
);
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)
115 void baselist::kd_search() {
116 char newsearchstring
[128];
117 strcpy(newsearchstring
,searchstring
);
119 mvwaddstr(querywin
,0,0, _("Search for ? "));
121 if (wgetnstr(querywin
,newsearchstring
,sizeof(newsearchstring
)-1) == ERR
)
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
)) {
134 strcpy(searchstring
,newsearchstring
);
141 baselist::displayerror(const char *str
)
143 const char *pr
= _("Error: ");
144 int prlen
=strlen(pr
);
148 mvwaddstr(querywin
,0,0,pr
);
149 mvwaddstr(querywin
,0,prlen
,str
);
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
);
163 getmaxyx(stdscr
, maxy
, maxx
);
165 const struct helpmenuentry
*hme
= helpmenu
;
166 while (hme
->key
&& hme
->key
!= 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
));
177 while (++x
<maxx
) addch(' ');
178 attrset(part_attr
[thisstate
]);
180 _("Press ? for help menu, . for next topic, <space> to exit help."));
182 while (++x
<maxx
) addch(' ');
187 mvaddstr(1,1, _("Help information is available under the following topics:"));
188 for (i
=0, hme
=helpmenu
; hme
->key
; hme
++,i
++) {
190 mvaddch(i
+3,3, hme
->key
);
192 mvaddstr(i
+3,6, gettext(hme
->msg
->title
));
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
;
204 if (key
== KEY_RESIZE
) {
208 } while (key
== ERR
&& errno
== EINTR
);
209 if (key
== EOF
) ohshite(_("error reading keyboard in help"));
210 if (key
== ' ' || key
== 'q') {
212 } else if (key
== '?' || key
== 'h') {
214 } else if (key
== '.') {
219 clearok(stdscr
,TRUE
);
220 wnoutrefresh(stdscr
);
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;
242 redrawitemsrange(cursorline
,cursorline
+1);
243 redraw1itemsel(cursorline
,1);
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
++;
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
--;
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;
280 void baselist::kd_iscrollback() {
281 infotopofscreen
-= info_height
;
282 if (infotopofscreen
< 0) infotopofscreen
= 0;
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() {
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() {
318 if (leftofscreen
< 0) leftofscreen
= 0;
319 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();