2 * dselect - Debian GNU/Linux package maintenance user interface
3 * pkgtop.cc - handles (re)draw of package list windows colheads, list, thisstate
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.
37 const char *pkgprioritystring(const struct pkginfo
*pkg
) {
38 if (pkg
->priority
== pkginfo::pri_unset
) {
40 } else if (pkg
->priority
== pkginfo::pri_other
) {
41 return pkg
->otherpriority
;
43 assert(pkg
->priority
<= pkginfo::pri_unknown
);
44 return prioritystrings
[pkg
->priority
];
48 int packagelist::describemany(char buf
[], const char *prioritystring
,
50 const struct perpackagestate
*pps
) {
51 const char *ssostring
, *ssoabbrev
;
57 switch (statsortorder
) {
59 if (pps
->ssavail
== -1) break;
60 ssostring
= ssastrings
[pps
->ssavail
];
61 ssoabbrev
= ssaabbrevs
[pps
->ssavail
];
65 if (pps
->ssstate
== -1) break;
66 ssostring
= sssstrings
[pps
->ssstate
];
67 ssoabbrev
= sssabbrevs
[pps
->ssstate
];
73 internerr("unknown statsortrder in describemany all");
76 if (!prioritystring
) {
78 strcpy(buf
, ssostring
? ssostring
: "All packages");
82 sprintf(buf
,"%s packages without a section",ssoabbrev
);
84 sprintf(buf
,"%s packages in section %s",ssoabbrev
,section
);
90 sprintf(buf
,"%s %s packages",ssoabbrev
,prioritystring
);
94 sprintf(buf
,"%s %s packages without a section",ssoabbrev
,prioritystring
);
96 sprintf(buf
,"%s %s packages in section %s",ssoabbrev
,prioritystring
,section
);
103 void packagelist::redrawthisstate() {
104 if (!thisstate_height
) return;
105 mywerase(thisstatepad
);
107 const char *section
= table
[cursorline
]->pkg
->section
;
108 const char *priority
= pkgprioritystring(table
[cursorline
]->pkg
);
109 char *buf
= new char[500+
110 greaterint((table
[cursorline
]->pkg
->name
111 ? strlen(table
[cursorline
]->pkg
->name
) : 0),
112 (section
? strlen(section
) : 0) +
113 (priority
? strlen(priority
) : 0))];
115 if (table
[cursorline
]->pkg
->name
) {
117 "%-*s %s%s%s; %s (was: %s). %s",
119 table
[cursorline
]->pkg
->name
,
120 statusstrings
[table
[cursorline
]->pkg
->status
],
121 eflagstrings
[table
[cursorline
]->pkg
->eflag
][0] ? " - " : "",
122 eflagstrings
[table
[cursorline
]->pkg
->eflag
],
123 wantstrings
[table
[cursorline
]->selected
],
124 wantstrings
[table
[cursorline
]->original
],
127 describemany(buf
,priority
,section
,table
[cursorline
]->pkg
->clientdata
);
129 mvwaddnstr(thisstatepad
,0,0, buf
, total_width
);
130 pnoutrefresh(thisstatepad
, 0,leftofscreen
, thisstate_row
,0,
131 thisstate_row
, lesserint(total_width
- 1, xmax
- 1));
136 void packagelist::redraw1itemsel(int index
, int selected
) {
139 const struct pkginfo
*pkg
= table
[index
]->pkg
;
140 const struct pkginfoperfile
*info
= &pkg
->available
;
142 wattrset(listpad
, selected
? listsel_attr
: list_attr
);
148 mvwprintw(listpad
,index
,0, "%-*.*s ",
149 status_hold_width
, status_hold_width
,
150 eflagstrings
[pkg
->eflag
]);
151 wprintw(listpad
, "%-*.*s ",
152 status_status_width
, status_status_width
,
153 statusstrings
[pkg
->status
]);
154 wprintw(listpad
, "%-*.*s ",
155 status_want_width
, status_want_width
,
156 /* fixme: keep this ? */
157 /*table[index]->original == table[index]->selected ? "(same)"
158 : */wantstrings
[table
[index
]->original
]);
159 wattrset(listpad
, selected
? selstatesel_attr
: selstate_attr
);
160 wprintw(listpad
, "%-*.*s",
161 status_want_width
, status_want_width
,
162 wantstrings
[table
[index
]->selected
]);
163 wattrset(listpad
, selected
? listsel_attr
: list_attr
);
164 waddch(listpad
, ' ');
166 mvwprintw(listpad
,index
,priority_column
-1, " %-*.*s",
167 priority_width
, priority_width
,
168 pkg
->priority
== pkginfo::pri_other
? pkg
->otherpriority
:
169 prioritystrings
[pkg
->priority
]);
173 mvwaddch(listpad
,index
,0, eflagchars
[pkg
->eflag
]);
174 waddch(listpad
, statuschars
[pkg
->status
]);
176 /* fixme: keep this feature? */
177 /*table[index]->original == table[index]->selected ? ' '
178 : */wantchars
[table
[index
]->original
]);
180 wattrset(listpad
, selected
? selstatesel_attr
: selstate_attr
);
181 waddch(listpad
, wantchars
[table
[index
]->selected
]);
182 wattrset(listpad
, selected
? listsel_attr
: list_attr
);
184 wmove(listpad
,index
,priority_column
-1); waddch(listpad
,' ');
185 if (pkg
->priority
== pkginfo::pri_other
) {
188 for (i
=priority_width
, p
=pkg
->otherpriority
;
191 waddch(listpad
, tolower(*p
));
192 while (i
-- > 0) waddch(listpad
,' ');
194 wprintw(listpad
, "%-*.*s", priority_width
, priority_width
,
195 priorityabbrevs
[pkg
->priority
]);
200 mvwprintw(listpad
,index
,section_column
-1, " %-*.*s",
201 section_width
, section_width
,
202 pkg
->section
? pkg
->section
: "?");
204 mvwprintw(listpad
,index
,package_column
-1, " %-*.*s ",
205 package_width
, package_width
, pkg
->name
);
207 if (versioninstalled_width
)
208 mvwprintw(listpad
,index
,versioninstalled_column
, "%-*.*s ",
209 versioninstalled_width
, versioninstalled_width
,
210 versiondescribe(&pkg
->installed
.version
,vdew_never
));
211 if (versionavailable_width
) {
212 if (informativeversion(&pkg
->available
.version
) &&
213 versioncompare(&pkg
->available
.version
,&pkg
->installed
.version
) > 0)
214 wattrset(listpad
, selected
? selstatesel_attr
: selstate_attr
);
215 mvwprintw(listpad
,index
,versionavailable_column
, "%-*.*s",
216 versionavailable_width
, versionavailable_width
,
217 versiondescribe(&pkg
->available
.version
,vdew_never
));
218 wattrset(listpad
, selected
? listsel_attr
: list_attr
);
222 i
= description_width
;
223 p
= info
->description
? info
->description
: "";
224 while (i
>0 && *p
&& *p
!= '\n') { waddch(listpad
,*p
); i
--; p
++; }
228 const char *section
= pkg
->section
;
229 const char *priority
= pkgprioritystring(pkg
);
231 char *buf
= new char[500+
232 (section
? strlen(section
) : 0) +
233 (priority
? strlen(priority
) : 0)];
235 indent
= describemany(buf
,priority
,section
,pkg
->clientdata
);
237 mvwaddstr(listpad
,index
,0, " ");
240 while (j
-- >0) { waddch(listpad
,'-'); i
--; }
243 wattrset(listpad
, selected
? selstatesel_attr
: selstate_attr
);
245 while (i
>0 && *p
) { waddch(listpad
, *p
); p
++; i
--; }
246 wattrset(listpad
, selected
? listsel_attr
: list_attr
);
250 while (j
-- >0) { waddch(listpad
,'-'); i
--; }
256 while (i
>0) { waddch(listpad
,' '); i
--; }
259 void packagelist::redrawcolheads() {
260 if (colheads_height
) {
261 wattrset(colheadspad
,colheads_attr
);
262 mywerase(colheadspad
);
264 wmove(colheadspad
,0,0);
265 for (int i
=0; i
<status_width
-status_want_width
; i
++) waddch(colheadspad
,'.');
266 mvwaddnstr(colheadspad
,0,
270 mvwaddnstr(colheadspad
,0,
273 status_status_width
);
274 mvwaddnstr(colheadspad
,0,
275 status_hold_width
+status_status_width
+2,
278 mvwaddnstr(colheadspad
,0,
279 status_hold_width
+status_status_width
+status_want_width
+3,
283 mvwaddstr(colheadspad
,0,0, "EIOM");
285 mvwaddnstr(colheadspad
,0,section_column
, "Section", section_width
);
286 mvwaddnstr(colheadspad
,0,priority_column
, "Priority", priority_width
);
287 mvwaddnstr(colheadspad
,0,package_column
, "Package", package_width
);
289 if (versioninstalled_width
)
290 mvwaddnstr(colheadspad
,0,versioninstalled_column
,
291 "Inst.ver",versioninstalled_width
);
292 if (versionavailable_width
)
293 mvwaddnstr(colheadspad
,0,versionavailable_column
,
294 "Avail.ver",versionavailable_width
);
296 mvwaddnstr(colheadspad
,0,description_column
, "Description", description_width
);