Release 1.15.8
[dpkg.git] / dselect / pkgdisplay.cc
blob13ad3268ce70b71bf586991d19052c8b64f43f75
1 /*
2 * dselect - Debian package maintenance user interface
3 * pkgdisplay.cc - package list display
5 * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.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 published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This is distributed in the hope that it will be useful,
13 * but 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 License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <config.h>
22 #include <compat.h>
24 #include <string.h>
25 #include <stdio.h>
27 #include <dpkg/i18n.h>
28 #include <dpkg/dpkg.h>
29 #include <dpkg/dpkg-db.h>
31 #include "dselect.h"
32 #include "pkglist.h"
34 /* These MUST be in the same order as the corresponding enums in dpkg-db.h */
35 const char
36 *const wantstrings[]= { N_("new package"),
37 N_("install"),
38 N_("hold"),
39 N_("remove"),
40 N_("purge"),
41 0 },
42 /* WTA: the space is a trick to work around gettext which uses the empty
43 * string to store information about the translation. DO NOT CHANGE
44 * THAT IN A TRANSLATION! The code really relies on that being a single space.
46 *const eflagstrings[]= { N_(" "),
47 N_("REINSTALL"),
48 0 },
50 *const statusstrings[]= { N_("not installed"),
51 N_("removed (configs remain)"),
52 N_("half installed"),
53 N_("unpacked (not set up)"),
54 N_("half configured (config failed)"),
55 N_("awaiting trigger processing"),
56 N_("triggered"),
57 N_("installed"),
58 0 },
60 *const prioritystrings[]= { N_("Required"),
61 N_("Important"),
62 N_("Standard"),
63 N_("Optional"),
64 N_("Extra"),
65 N_("!Bug!"),
66 N_("Unclassified"),
67 0 },
69 *const relatestrings[]= { N_("suggests"),
70 N_("recommends"),
71 N_("depends on"),
72 N_("pre-depends on"),
73 N_("breaks"),
74 N_("conflicts with"),
75 N_("provides"),
76 N_("replaces"),
77 N_("enhances"),
78 0 },
80 *const priorityabbrevs[]= { N_("Req"),
81 N_("Imp"),
82 N_("Std"),
83 N_("Opt"),
84 N_("Xtr"),
85 N_("bUG"),
86 N_("?") };
88 const char statuschars[] = " -IUCWt*";
89 const char eflagchars[] = " R";
90 const char wantchars[]= "n*=-_";
92 /* These MUST be in the same order as the corresponding enums in pkglist.h */
93 const char
94 *const ssaabbrevs[]= { N_("Broken"),
95 N_("New"),
96 N_("Updated"),
97 N_("Obsolete/local"),
98 N_("Up-to-date"),
99 N_("Available"),
100 N_("Removed") },
101 *const ssastrings[]= { N_("Brokenly installed packages"),
102 N_("Newly available packages"),
103 N_("Updated packages (newer version is available)"),
104 N_("Obsolete and local packages present on system"),
105 N_("Up to date installed packages"),
106 N_("Available packages (not currently installed)"),
107 N_("Removed and no longer available packages") };
109 const char
110 *const sssstrings[]= { N_("Brokenly installed packages"),
111 N_("Installed packages"),
112 N_("Removed packages (configuration still present)"),
113 N_("Purged packages and those never installed") },
114 *const sssabbrevs[]= { N_("Broken"),
115 N_("Installed"),
116 N_("Removed"),
117 N_("Purged") };
119 static int maximumstring(const char *const *array) {
120 int maxlen= 0;
121 while (*array) {
122 int l= strlen(gettext(*array));
123 const char *p= strchr(*array, '(');
124 if (p && p > *array && *--p == ' ') l= p - *array;
125 if (l > maxlen) maxlen= l;
126 array++;
128 return maxlen;
131 void packagelist::setwidths() {
132 if (debug) fprintf(debug,"packagelist[%p]::setwidths()\n",this);
134 if (verbose) {
135 status_hold_width= 9;
136 status_status_width= maximumstring(statusstrings);
137 status_want_width= maximumstring(wantstrings);
138 status_width= status_hold_width+status_status_width+status_want_width*2+3;
139 priority_width= 8;
140 package_width= 16;
141 } else {
142 status_width= 4;
143 priority_width= 3;
144 package_width= 12;
146 section_width= 8;
148 gap_width= 1;
150 if (sortorder == so_section) {
151 section_column= status_width + gap_width;
152 priority_column= section_column + section_width + gap_width;
153 package_column= priority_column + priority_width + gap_width;
154 } else {
155 priority_column= status_width + gap_width;
156 section_column= priority_column + priority_width + gap_width;
157 package_column= section_column + section_width + gap_width;
160 int versiondescriptioncolumn= package_column + package_width + gap_width;
162 switch (versiondisplayopt) {
163 case vdo_none:
164 versioninstalled_column= versioninstalled_width= 0;
165 versionavailable_column= versionavailable_width= 0;
166 description_column= versiondescriptioncolumn;
167 break;
168 case vdo_available:
169 versioninstalled_column= versioninstalled_width= 0;
170 versionavailable_column= versiondescriptioncolumn;
171 versionavailable_width= 11;
172 description_column= versionavailable_column + versionavailable_width + gap_width;
173 break;
174 case vdo_both:
175 versioninstalled_column= versiondescriptioncolumn;
176 versioninstalled_width= 11;
177 versionavailable_column= versioninstalled_column + versioninstalled_width +gap_width;
178 versionavailable_width= versioninstalled_width;
179 description_column= versionavailable_column + versionavailable_width + gap_width;
180 break;
181 default:
182 internerr("unknown versiondisplayopt in setwidths");
185 total_width= TOTAL_LIST_WIDTH;
186 if (total_width < COLS)
187 total_width= COLS;
188 description_width= total_width - description_column;
191 void packagelist::redrawtitle() {
192 int x,y;
194 if (title_height) {
195 mywerase(titlewin);
196 mvwaddnstr(titlewin,0,0,
197 recursive ? _("dselect - recursive package listing") :
198 !readwrite ? _("dselect - inspection of package states") :
199 _("dselect - main package listing"),
200 xmax);
201 getyx(titlewin,y,x);
202 if (x < xmax) {
203 switch (sortorder) {
204 case so_section:
205 switch (statsortorder) {
206 case sso_unsorted:
207 waddnstr(titlewin, _(" (by section)"), xmax-x);
208 break;
209 case sso_avail:
210 waddnstr(titlewin, _(" (avail., section)"), xmax-x);
211 break;
212 case sso_state:
213 waddnstr(titlewin, _(" (status, section)"), xmax-x);
214 break;
215 default:
216 internerr("bad statsort in redrawtitle/so_section");
218 break;
219 case so_priority:
220 switch (statsortorder) {
221 case sso_unsorted:
222 waddnstr(titlewin, _(" (by priority)"), xmax-x);
223 break;
224 case sso_avail:
225 waddnstr(titlewin, _(" (avail., priority)"), xmax-x);
226 break;
227 case sso_state:
228 waddnstr(titlewin, _(" (status, priority)"), xmax-x);
229 break;
230 default:
231 internerr("bad statsort in redrawtitle/so_priority");
233 break;
234 case so_alpha:
235 switch (statsortorder) {
236 case sso_unsorted:
237 waddnstr(titlewin, _(" (alphabetically)"), xmax-x);
238 break;
239 case sso_avail:
240 waddnstr(titlewin, _(" (by availability)"), xmax-x);
241 break;
242 case sso_state:
243 waddnstr(titlewin, _(" (by status)"), xmax-x);
244 break;
245 default:
246 internerr("bad statsort in redrawtitle/so_priority");
248 break;
249 waddnstr(titlewin, _(" (alphabetically)"), xmax-x);
250 break;
251 case so_unsorted:
252 break;
253 default:
254 internerr("bad sort in redrawtitle");
257 const char *helpstring= readwrite ? (verbose ? _(" mark:+/=/- terse:v help:?")
258 : _(" mark:+/=/- verbose:v help:?"))
259 : (verbose ? _(" terse:v help:?")
260 : _(" verbose:v help:?"));
261 int l= strlen(helpstring);
262 getyx(titlewin,y,x);
263 if (xmax-l > 0) {
264 mvwaddstr(titlewin,0,xmax-l, helpstring);
266 wnoutrefresh(titlewin);