dpkg (1.2.12); priority=LOW
[dpkg.git] / dselect / basecmds.cc
blob85d2d7f96c54f3797b6507a325ec574540e6868f
1 /*
2 * dselect - Debian GNU/Linux package maintenance user interface
3 * bcommands.cc - base list keyboard commands display
5 * Copyright (C) 1994,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 "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(lesserint(topofscreen + list_height - 1, nitems-1));
79 void baselist::kd_redraw() {
80 //#define RFSH(x) werase(x); redrawwin(x)
81 // RFSH(listpad);
82 // RFSH(infopad);
83 // RFSH(colheadspad);
84 // RFSH(thisstatepad);
85 // RFSH(titlewin);
86 // RFSH(whatinfowin); /* fixme-ncurses: why does ncurses need this ? */
87 clearok(curscr,TRUE);
88 redrawall();
89 if (debug) fprintf(debug,"baselist[%p]::kd_redraw() done\n",this);
92 void baselist::kd_searchagain() {
93 if (!searchstring[0]) { beep(); return; }
94 dosearch();
97 void baselist::kd_search() {
98 werase(querywin);
99 mvwaddstr(querywin,0,0, "Search for ? ");
100 echo();
101 /* fixme: make / RET do `search again' and / DEL to abort */
102 if (wgetnstr(querywin,searchstring,sizeof(searchstring)-1) == ERR)
103 searchstring[0]= 0;
104 noecho();
105 if (whatinfo_height) { touchwin(whatinfowin); refreshinfo(); }
106 else if (info_height) { touchwin(infopad); refreshinfo(); }
107 else if (thisstate_height) redrawthisstate();
108 else { touchwin(listpad); refreshlist(); }
109 if (searchstring[0]) dosearch();
112 void baselist::displayhelp(const struct helpmenuentry *helpmenu, int key) {
113 const struct helpmenuentry *hme;
114 int maxx, maxy, i, y, x, nextkey;
116 getmaxyx(stdscr,maxy,maxx);
117 clearok(stdscr,TRUE);
118 for (;;) {
119 werase(stdscr);
120 for (hme= helpmenu; hme->key && hme->key != key; hme++);
121 if (hme->key) {
122 attrset(list_attr);
123 mvaddstr(1,0, hme->msg->text);
124 attrset(title_attr);
125 mvaddstr(0,0, "Help: ");
126 addstr(hme->msg->title);
127 getyx(stdscr,y,x);
128 while (++x<maxx) addch(' ');
129 attrset(thisstate_attr);
130 mvaddstr(maxy-1,0,
131 "? = help menu Space = exit help . = next help or a help page key "
133 getyx(stdscr,y,x);
134 while (++x<maxx) addch(' ');
135 move(maxy,maxx);
136 attrset(A_NORMAL);
137 nextkey= hme[1].key;
138 } else {
139 mvaddstr(1,1, "Help information is available under the following topics:");
140 for (i=0, hme=helpmenu; hme->key; hme++,i++) {
141 attrset(A_BOLD);
142 mvaddch(i+3,3, hme->key);
143 attrset(A_NORMAL);
144 mvaddstr(i+3,6, hme->msg->title);
146 mvaddstr(i+4,1,
147 "Press a key from the list above, Space to exit help,\n"
148 " or `.' (full stop) to read each help page in turn. ");
149 nextkey= helpmenu[0].key;
151 refresh();
152 key= getch();
153 if (key == EOF) ohshite("error reading keyboard in help");
154 if (key == ' ') {
155 break;
156 } else if (key == '?') {
157 key= 0;
158 } else if (key == '.') {
159 key= nextkey;
162 werase(stdscr);
163 clearok(stdscr,TRUE);
164 wnoutrefresh(stdscr);
166 redrawtitle();
167 refreshcolheads();
168 refreshlist();
169 redrawthisstate();
170 refreshinfo();
171 wnoutrefresh(whatinfowin);
174 void baselist::kd_help() {
175 displayhelp(helpmenulist(),0);
178 void baselist::setcursor(int index) {
179 if (listpad && cursorline != -1) {
180 redrawitemsrange(cursorline,cursorline+1);
181 redraw1itemsel(cursorline,0);
183 if (cursorline != index) infotopofscreen= 0;
184 cursorline= index;
185 if (listpad) {
186 redrawitemsrange(cursorline,cursorline+1);
187 redraw1itemsel(cursorline, showinfo != 2);
188 refreshlist();
189 redrawthisstate();
191 redrawinfo();
194 void baselist::kd_down() {
195 int ncursor= cursorline;
196 // scroll by one line unless the bottom is already visible
197 // or we're in the top half of the screen ...
198 if (topofscreen < nitems - list_height &&
199 ncursor >= topofscreen + list_height - 3) topofscreen++;
200 // move cursor if there are any more ...
201 if (cursorline+1 < nitems) ncursor++;
202 setcursor(ncursor);
205 void baselist::kd_up() {
206 int ncursor= cursorline;
207 // scroll by one line if there are any lines not shown yet
208 // and we're not in the bottom half the screen ...
209 if (topofscreen > 0 &&
210 ncursor <= topofscreen + 2) topofscreen--;
211 // move cursor if there are any to move it to ...
212 if (cursorline > 0) ncursor--;
213 setcursor(ncursor);
216 void baselist::kd_iscrollon() {
217 infotopofscreen += info_height;
218 if (infotopofscreen > infolines - info_height)
219 infotopofscreen= infolines - info_height;
220 if (infotopofscreen < 0) infotopofscreen= 0;
221 refreshinfo();
224 void baselist::kd_iscrollback() {
225 infotopofscreen -= info_height;
226 if (infotopofscreen < 0) infotopofscreen= 0;
227 refreshinfo();
230 void baselist::kd_iscrollon1() {
231 if (infotopofscreen >= infolines - info_height) return;
232 infotopofscreen++; refreshinfo();
235 void baselist::kd_iscrollback1() {
236 if (infotopofscreen <= 0) return;
237 infotopofscreen--; refreshinfo();
240 void baselist::kd_panon() {
241 leftofscreen += xmax/3;
242 if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
243 if (leftofscreen < 0) leftofscreen= 0;
244 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
247 void baselist::kd_panback() {
248 leftofscreen -= xmax/3;
249 if (leftofscreen < 0) leftofscreen= 0;
250 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
253 void baselist::kd_panon1() {
254 leftofscreen++;
255 if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
256 if (leftofscreen < 0) leftofscreen= 0;
257 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
260 void baselist::kd_panback1() {
261 leftofscreen--;
262 if (leftofscreen < 0) leftofscreen= 0;
263 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();