2 * dselect - Debian package maintenance user interface
3 * pkgtop.cc - handles (re)draw of package list windows colheads, list, thisstate
5 * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2007-2014 Guillem Jover <guillem@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/>.
28 #include <dpkg/i18n.h>
29 #include <dpkg/c-ctype.h>
30 #include <dpkg/dpkg.h>
31 #include <dpkg/dpkg-db.h>
37 pkgprioritystring(const struct pkginfo
*pkg
)
39 if (pkg
->priority
== PKG_PRIO_UNSET
) {
41 } else if (pkg
->priority
== PKG_PRIO_OTHER
) {
42 return pkg
->otherpriority
;
44 if (pkg
->priority
> PKG_PRIO_UNKNOWN
)
45 internerr("package %s has out-of-range priority %d",
46 pkg_name_const(pkg
, pnaw_always
), pkg
->priority
);
47 return gettext(prioritystrings
[pkg
->priority
]);
51 int packagelist::describemany(char buf
[], const char *prioritystring
,
53 const struct perpackagestate
*pps
) {
54 const char *ssostring
, *ssoabbrev
;
60 switch (statsortorder
) {
62 if (pps
->ssavail
== -1) break;
63 ssostring
= ssastrings
[pps
->ssavail
];
64 ssoabbrev
= ssaabbrevs
[pps
->ssavail
];
68 if (pps
->ssstate
== -1) break;
69 ssostring
= sssstrings
[pps
->ssstate
];
70 ssoabbrev
= sssabbrevs
[pps
->ssstate
];
76 internerr("unknown statsortrder %d", statsortorder
);
79 if (!prioritystring
) {
81 strcpy(buf
, ssostring
? gettext(ssostring
) : _("All packages"));
85 sprintf(buf
,_("%s packages without a section"),gettext(ssoabbrev
));
87 sprintf(buf
,_("%s packages in section %s"),gettext(ssoabbrev
),section
);
93 sprintf(buf
,_("%s %s packages"),gettext(ssoabbrev
),prioritystring
);
97 sprintf(buf
,_("%s %s packages without a section"),gettext(ssoabbrev
),prioritystring
);
99 sprintf(buf
,_("%s %s packages in section %s"),gettext(ssoabbrev
),prioritystring
,section
);
106 void packagelist::redrawthisstate() {
107 if (!thisstate_height
) return;
108 mywerase(thisstatepad
);
110 const char *section
= table
[cursorline
]->pkg
->section
;
111 const char *priority
= pkgprioritystring(table
[cursorline
]->pkg
);
112 char *buf
= new char[500+
113 max((table
[cursorline
]->pkg
->set
->name
?
114 strlen(table
[cursorline
]->pkg
->set
->name
) : 0),
115 (section
? strlen(section
) : 0) +
116 (priority
? strlen(priority
) : 0))];
118 if (table
[cursorline
]->pkg
->set
->name
) {
120 _("%-*s %s%s%s; %s (was: %s). %s"),
122 table
[cursorline
]->pkg
->set
->name
,
123 gettext(statusstrings
[table
[cursorline
]->pkg
->status
]),
124 ((eflagstrings
[table
[cursorline
]->pkg
->eflag
][0]==' ') &&
125 (eflagstrings
[table
[cursorline
]->pkg
->eflag
][1]=='\0')) ? "" : " - ",
126 gettext(eflagstrings
[table
[cursorline
]->pkg
->eflag
]),
127 gettext(wantstrings
[table
[cursorline
]->selected
]),
128 gettext(wantstrings
[table
[cursorline
]->original
]),
131 describemany(buf
,priority
,section
,table
[cursorline
]->pkg
->clientdata
);
133 mvwaddnstr(thisstatepad
,0,0, buf
, total_width
);
134 pnoutrefresh(thisstatepad
, 0,leftofscreen
, thisstate_row
,0,
135 thisstate_row
, min(total_width
- 1, xmax
- 1));
140 void packagelist::redraw1itemsel(int index
, int selected
) {
143 const struct pkginfo
*pkg
= table
[index
]->pkg
;
144 int screenline
= index
- topofscreen
;
146 wattrset(listpad
, part_attr
[selected
? listsel
: list
]);
148 if (pkg
->set
->name
) {
150 draw_column_item(col_status_hold
, screenline
,
151 gettext(eflagstrings
[pkg
->eflag
]));
153 draw_column_sep(col_status_status
, screenline
);
154 draw_column_item(col_status_status
, screenline
,
155 gettext(statusstrings
[pkg
->status
]));
157 draw_column_sep(col_status_old_want
, screenline
);
158 draw_column_item(col_status_old_want
, screenline
,
159 /* FIXME: keep this? */
160 /*table[index]->original == table[index]->selected ? "(same)"
161 : */gettext(wantstrings
[table
[index
]->original
]));
163 draw_column_sep(col_status_new_want
, screenline
);
164 wattrset(listpad
, part_attr
[selected
? selstatesel
: selstate
]);
165 draw_column_item(col_status_new_want
, screenline
,
166 gettext(wantstrings
[table
[index
]->selected
]));
168 wattrset(listpad
, part_attr
[selected
? listsel
: list
]);
170 draw_column_sep(col_priority
, screenline
);
171 draw_column_item(col_priority
, screenline
,
172 pkg
->priority
== PKG_PRIO_OTHER
?
174 gettext(prioritystrings
[pkg
->priority
]));
176 mvwaddch(listpad
, screenline
, 0, eflagchars
[pkg
->eflag
]);
177 waddch(listpad
, statuschars
[pkg
->status
]);
179 /* FIXME: keep this feature? */
180 /*table[index]->original == table[index]->selected ? ' '
181 : */wantchars
[table
[index
]->original
]);
183 wattrset(listpad
, part_attr
[selected
? selstatesel
: selstate
]);
184 waddch(listpad
, wantchars
[table
[index
]->selected
]);
185 wattrset(listpad
, part_attr
[selected
? listsel
: list
]);
187 wmove(listpad
, screenline
, col_priority
.x
- 1);
188 waddch(listpad
, ' ');
189 if (pkg
->priority
== PKG_PRIO_OTHER
) {
190 for (i
= col_priority
.width
, p
= pkg
->otherpriority
;
193 waddch(listpad
, c_tolower(*p
));
194 while (i
-- > 0) waddch(listpad
,' ');
196 wprintw(listpad
, "%-*.*s", col_priority
.width
, col_priority
.width
,
197 gettext(priorityabbrevs
[pkg
->priority
]));
201 draw_column_sep(col_section
, screenline
);
202 draw_column_item(col_section
, screenline
,
203 pkg
->section
? pkg
->section
: "?");
205 draw_column_sep(col_package
, screenline
);
206 draw_column_item(col_package
, screenline
,
209 waddch(listpad
, ' ');
211 if (col_archinstalled
.width
) {
212 draw_column_sep(col_archinstalled
, screenline
);
213 draw_column_item(col_archinstalled
, screenline
, pkg
->installed
.arch
->name
);
215 waddch(listpad
, ' ');
217 if (col_archavailable
.width
) {
218 draw_column_sep(col_archavailable
, screenline
);
219 draw_column_item(col_archavailable
, screenline
, pkg
->available
.arch
->name
);
221 waddch(listpad
, ' ');
224 if (col_versioninstalled
.width
) {
225 draw_column_item(col_versioninstalled
, screenline
,
226 versiondescribe(&pkg
->installed
.version
, vdew_nonambig
));
227 waddch(listpad
, ' ');
229 if (col_versionavailable
.width
) {
230 if (dpkg_version_is_informative(&pkg
->available
.version
) &&
231 dpkg_version_compare(&pkg
->available
.version
,
232 &pkg
->installed
.version
) > 0)
233 wattrset(listpad
, part_attr
[selected
? selstatesel
: selstate
]);
234 draw_column_item(col_versionavailable
, screenline
,
235 versiondescribe(&pkg
->available
.version
, vdew_nonambig
));
236 wattrset(listpad
, part_attr
[selected
? listsel
: list
]);
240 i
= col_description
.width
;
241 p
= pkg
->available
.description
? pkg
->available
.description
:
242 pkg
->installed
.description
? pkg
->installed
.description
: "";
243 while (i
>0 && *p
&& *p
!= '\n') { waddnstr(listpad
,p
,1); i
--; p
++; }
246 const char *section
= pkg
->section
;
247 const char *priority
= pkgprioritystring(pkg
);
249 char *buf
= new char[500+
250 (section
? strlen(section
) : 0) +
251 (priority
? strlen(priority
) : 0)];
253 indent
= describemany(buf
,priority
,section
,pkg
->clientdata
);
255 mvwaddstr(listpad
, screenline
, 0, " ");
258 while (j
-- >0) { waddch(listpad
,ACS_HLINE
); i
--; }
261 wattrset(listpad
, part_attr
[selected
? selstatesel
: selstate
]);
263 while (i
>0 && *p
) { waddnstr(listpad
, p
,1); p
++; i
--; }
264 wattrset(listpad
, part_attr
[selected
? listsel
: list
]);
268 while (j
-- >0) { waddch(listpad
,ACS_HLINE
); i
--; }
273 while (i
>0) { waddch(listpad
,' '); i
--; }
276 void packagelist::redrawcolheads() {
277 if (colheads_height
) {
278 wattrset(colheadspad
, part_attr
[colheads
]);
279 mywerase(colheadspad
);
281 wmove(colheadspad
,0,0);
282 for (int i
= 0; i
< col_status_old_want
.width
; i
++)
283 waddch(colheadspad
, '.');
284 draw_column_head(col_status_hold
);
285 draw_column_head(col_status_status
);
286 draw_column_head(col_status_old_want
);
287 draw_column_head(col_status_new_want
);
289 draw_column_head(col_status
);
292 draw_column_head(col_section
);
293 draw_column_head(col_priority
);
294 draw_column_head(col_package
);
296 if (col_archinstalled
.width
)
297 draw_column_head(col_archinstalled
);
298 if (col_archavailable
.width
)
299 draw_column_head(col_archavailable
);
301 if (col_versioninstalled
.width
)
302 draw_column_head(col_versioninstalled
);
303 if (col_versionavailable
.width
)
304 draw_column_head(col_versionavailable
);
306 draw_column_head(col_description
);