dpkg (1.2.12); priority=LOW
[dpkg.git] / dselect / pkgdisplay.cc
blob92c31a868abf89fc4279e73e546c7d0f46c93a27
1 /*
2 * dselect - Debian GNU/Linux package maintenance user interface
3 * pkgdisplay.cc - package list 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 "pkglist.h"
36 /* These MUST be in the same order as the corresponding enums in dpkg-db.h */
37 const char
38 *const wantstrings[]= { "new package", "install", "hold", "remove", "purge", 0 },
39 *const eflagstrings[]= { "", "REINSTALL", 0 },
40 *const statusstrings[]= { "not installed", "unpacked (not set up)",
41 "failed config", "installed", "half installed",
42 "removed (configs remain)", 0 },
43 *const prioritystrings[]= { "Required", "Important", "Standard", "Recommended",
44 "Optional", "Extra", "Contrib",
45 "!Bug!", "Unclassified", 0 },
46 *const relatestrings[]= { "suggests", "recommends", "depends on", "pre-depends on",
47 "conflicts with", "provides", "replaces", 0 },
48 *const priorityabbrevs[]= { "Req", "Imp", "Std", "Rec",
49 "Opt", "Xtr", "Ctb",
50 "bUG", "?" };
51 const char statuschars[]= " UC*I-";
52 const char eflagchars[]= " R?#";
53 const char wantchars[]= "n*=-_";
55 /* These MUST be in the same order as the corresponding enums in pkglist.h */
56 const char
57 *const ssaabbrevs[]= { "Broken",
58 "New",
59 "Updated",
60 "Obsolete/local",
61 "Up-to-date",
62 "Available",
63 "Removed" },
64 *const ssastrings[]= { "Brokenly installed packages",
65 "Newly available packages",
66 "Updated packages (newer version is available)",
67 "Obsolete and local packages present on system",
68 "Up to date installed packages",
69 "Available packages (not currently installed)",
70 "Removed and no longer available packages" };
72 const char
73 *const sssstrings[]= { "Brokenly installed packages",
74 "Installed packages",
75 "Removed packages (configuration still present)",
76 "Purged packages and those never installed" },
77 *const sssabbrevs[]= { "Broken",
78 "Installed",
79 "Removed",
80 "Purged" };
82 static int maximumstring(const char *const *array) {
83 int maxlen= 0;
84 while (*array) {
85 int l= strlen(*array);
86 const char *p= strchr(*array, '(');
87 if (p && p > *array && *--p == ' ') l= p - *array;
88 if (l > maxlen) maxlen= l;
89 array++;
91 return maxlen;
94 void packagelist::setwidths() {
95 if (debug) fprintf(debug,"packagelist[%p]::setwidths()\n",this);
97 if (verbose) {
98 status_hold_width= 9;
99 status_status_width= maximumstring(statusstrings);
100 status_want_width= maximumstring(wantstrings);
101 status_width= status_hold_width+status_status_width+status_want_width*2+3;
102 priority_width= 8;
103 package_width= 16;
104 } else {
105 status_width= 4;
106 priority_width= 3;
107 package_width= 12;
109 section_width= 8;
111 gap_width= 1;
113 if (sortorder == so_section) {
114 section_column= status_width + gap_width;
115 priority_column= section_column + section_width + gap_width;
116 package_column= priority_column + priority_width + gap_width;
117 } else {
118 priority_column= status_width + gap_width;
119 section_column= priority_column + priority_width + gap_width;
120 package_column= section_column + section_width + gap_width;
123 int versiondescriptioncolumn= package_column + package_width + gap_width;
125 switch (versiondisplayopt) {
126 case vdo_none:
127 versioninstalled_column= versioninstalled_width= 0;
128 versionavailable_column= versionavailable_width= 0;
129 description_column= versiondescriptioncolumn;
130 break;
131 case vdo_available:
132 versioninstalled_column= versioninstalled_width= 0;
133 versionavailable_column= versiondescriptioncolumn;
134 versionavailable_width= 11;
135 description_column= versionavailable_column + versionavailable_width + gap_width;
136 break;
137 case vdo_both:
138 versioninstalled_column= versiondescriptioncolumn;
139 versioninstalled_width= 11;
140 versionavailable_column= versioninstalled_column + versioninstalled_width +gap_width;
141 versionavailable_width= versioninstalled_width;
142 description_column= versionavailable_column + versionavailable_width + gap_width;
143 break;
144 default:
145 internerr("unknown versiondisplayopt in setwidths");
148 total_width= TOTAL_LIST_WIDTH;
149 description_width= total_width - description_column;
152 void packagelist::redrawtitle() {
153 int x,y;
155 if (title_height) {
156 mywerase(titlewin);
157 mvwaddnstr(titlewin,0,0,
158 recursive ? "dselect - recursive package listing" :
159 !readwrite ? "dselect - inspection of package states" :
160 "dselect - main package listing",
161 xmax);
162 getyx(titlewin,y,x);
163 if (x < xmax) {
164 switch (sortorder) {
165 case so_section:
166 switch (statsortorder) {
167 case sso_unsorted:
168 waddnstr(titlewin, " (by section)", xmax-x);
169 break;
170 case sso_avail:
171 waddnstr(titlewin, " (avail., section)", xmax-x);
172 break;
173 case sso_state:
174 waddnstr(titlewin, " (status, section)", xmax-x);
175 break;
176 default:
177 internerr("bad statsort in redrawtitle/so_section");
179 break;
180 case so_priority:
181 switch (statsortorder) {
182 case sso_unsorted:
183 waddnstr(titlewin, " (by priority)", xmax-x);
184 break;
185 case sso_avail:
186 waddnstr(titlewin, " (avail., priority)", xmax-x);
187 break;
188 case sso_state:
189 waddnstr(titlewin, " (status, priority)", xmax-x);
190 break;
191 default:
192 internerr("bad statsort in redrawtitle/so_priority");
194 break;
195 case so_alpha:
196 switch (statsortorder) {
197 case sso_unsorted:
198 waddnstr(titlewin, " (alphabetically)", xmax-x);
199 break;
200 case sso_avail:
201 waddnstr(titlewin, " (by availability)", xmax-x);
202 break;
203 case sso_state:
204 waddnstr(titlewin, " (by status)", xmax-x);
205 break;
206 default:
207 internerr("bad statsort in redrawtitle/so_priority");
209 break;
210 waddnstr(titlewin, " (alphabetically)", xmax-x);
211 break;
212 case so_unsorted:
213 break;
214 default:
215 internerr("bad sort in redrawtitle");
218 const char *helpstring= readwrite ? (verbose ? " mark:+/=/- terse:v help:?"
219 : " mark:+/=/- verbose:v help:?")
220 : (verbose ? " terse:v help:?"
221 : " verbose:v help:?");
222 int l= strlen(helpstring);
223 getyx(titlewin,y,x);
224 if (xmax-l > 0) {
225 mvwaddstr(titlewin,0,xmax-l, helpstring);
227 wnoutrefresh(titlewin);