pkgdisplay.cc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * pkgdisplay.cc - package list display
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2006, 2008-2015 Guillem Jover <guillem@debian.org>
  7. *
  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.
  12. *
  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.
  17. *
  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/>.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <string.h>
  24. #include <stdio.h>
  25. #include <dpkg/i18n.h>
  26. #include <dpkg/dpkg.h>
  27. #include <dpkg/dpkg-db.h>
  28. #include "dselect.h"
  29. #include "pkglist.h"
  30. /* These MUST be in the same order as the corresponding enums in dpkg-db.h */
  31. const char
  32. *const wantstrings[]= { N_("new package"),
  33. N_("install"),
  34. N_("hold"),
  35. N_("remove"),
  36. N_("purge"),
  37. nullptr },
  38. /* TRANSLATORS: The space is a trick to work around gettext which uses
  39. * the empty string to store information about the translation. DO NOT
  40. * CHANGE THAT IN A TRANSLATION! The code really relies on that being
  41. * a single space. */
  42. *const eflagstrings[]= { N_(" "),
  43. N_("REINSTALL"),
  44. nullptr },
  45. *const statusstrings[]= { N_("not installed"),
  46. N_("removed (configs remain)"),
  47. N_("half installed"),
  48. N_("unpacked (not set up)"),
  49. N_("half configured (config failed)"),
  50. N_("awaiting trigger processing"),
  51. N_("triggered"),
  52. N_("installed"),
  53. nullptr },
  54. *const prioritystrings[]= { N_("Required"),
  55. N_("Important"),
  56. N_("Standard"),
  57. N_("Optional"),
  58. N_("Extra"),
  59. N_("Unclassified"),
  60. nullptr },
  61. *const relatestrings[]= { N_("suggests"),
  62. N_("recommends"),
  63. N_("depends on"),
  64. N_("pre-depends on"),
  65. N_("breaks"),
  66. N_("conflicts with"),
  67. N_("provides"),
  68. N_("replaces"),
  69. N_("enhances"),
  70. nullptr },
  71. *const priorityabbrevs[]= { N_("Req"),
  72. N_("Imp"),
  73. N_("Std"),
  74. N_("Opt"),
  75. N_("Xtr"),
  76. N_("bUG"),
  77. N_("?") };
  78. const char statuschars[] = " -IUCWt*";
  79. const char eflagchars[] = " R";
  80. const char wantchars[]= "n*=-_";
  81. /* These MUST be in the same order as the corresponding enums in pkglist.h */
  82. const char
  83. *const ssaabbrevs[]= { N_("Broken"),
  84. N_("New"),
  85. N_("Upgradable"),
  86. N_("Obsolete/local"),
  87. N_("Installed"),
  88. N_("Available"),
  89. N_("Removed") },
  90. *const ssastrings[]= { N_("Brokenly installed packages"),
  91. N_("Newly available packages"),
  92. N_("Upgradable packages"),
  93. N_("Obsolete and locally created packages"),
  94. N_("Installed packages"),
  95. N_("Available not installed packages"),
  96. N_("Removed and no longer available packages") };
  97. const char
  98. *const sssstrings[]= { N_("Brokenly installed packages"),
  99. N_("Installed packages"),
  100. N_("Removed packages (configuration still present)"),
  101. N_("Purged packages and those never installed") },
  102. *const sssabbrevs[]= { N_("Broken"),
  103. N_("Installed"),
  104. N_("Removed"),
  105. N_("Purged") };
  106. static int maximumstring(const char *const *array) {
  107. int maxlen= 0;
  108. while (*array) {
  109. int l= strlen(gettext(*array));
  110. const char *p= strchr(*array, '(');
  111. if (p && p > *array && *--p == ' ') l= p - *array;
  112. if (l > maxlen) maxlen= l;
  113. array++;
  114. }
  115. return maxlen;
  116. }
  117. void packagelist::setwidths() {
  118. debug(dbg_general, "packagelist[%p]::setwidths()", this);
  119. col_cur_x = 0;
  120. if (verbose) {
  121. add_column(col_status_hold, _("Error"), 9);
  122. add_column(col_status_status, _("Installed?"), maximumstring(statusstrings));
  123. add_column(col_status_old_want, _("Old mark"), maximumstring(wantstrings));
  124. add_column(col_status_new_want, _("Marked for"), maximumstring(wantstrings));
  125. } else {
  126. add_column(col_status, _("EIOM"), 4);
  127. }
  128. if (sortorder == so_section)
  129. add_column(col_section, _("Section"), 8);
  130. add_column(col_priority, _("Priority"), verbose ? 8 : 3);
  131. if (sortorder != so_section)
  132. add_column(col_section, _("Section"), 8);
  133. add_column(col_package, _("Package"), verbose ? 16 : 12);
  134. switch (archdisplayopt) {
  135. case ado_none:
  136. col_archinstalled.blank();
  137. col_archavailable.blank();
  138. break;
  139. case ado_available:
  140. col_archinstalled.blank();
  141. add_column(col_archavailable, _("Avail.arch"), verbose ? 14 : 10);
  142. break;
  143. case ado_both:
  144. add_column(col_archinstalled, _("Inst.arch"), verbose ? 14 : 10);
  145. add_column(col_archavailable, _("Avail.arch"), verbose ? 14 : 10);
  146. break;
  147. default:
  148. internerr("unknown archdisplayopt %d", archdisplayopt);
  149. }
  150. switch (versiondisplayopt) {
  151. case vdo_none:
  152. col_versioninstalled.blank();
  153. col_versionavailable.blank();
  154. break;
  155. case vdo_available:
  156. col_versioninstalled.blank();
  157. add_column(col_versionavailable, _("Avail.ver"), 11);
  158. break;
  159. case vdo_both:
  160. add_column(col_versioninstalled, _("Inst.ver"), 11);
  161. add_column(col_versionavailable, _("Avail.ver"), 11);
  162. break;
  163. default:
  164. internerr("unknown versiondisplayopt %d", versiondisplayopt);
  165. }
  166. end_column(col_description, _("Description"));
  167. }
  168. void packagelist::redrawtitle() {
  169. int x, y DPKG_ATTR_UNUSED;
  170. if (title_height) {
  171. mywerase(titlewin);
  172. mvwaddnstr(titlewin,0,0,
  173. recursive ? _("dselect - recursive package listing") :
  174. modstatdb_get_status() == msdbrw_readonly ?
  175. _("dselect - inspection of package states") :
  176. _("dselect - main package listing"),
  177. xmax);
  178. getyx(titlewin,y,x);
  179. if (x < xmax) {
  180. switch (sortorder) {
  181. case so_section:
  182. switch (statsortorder) {
  183. case sso_unsorted:
  184. waddnstr(titlewin, _(" (by section)"), xmax-x);
  185. break;
  186. case sso_avail:
  187. waddnstr(titlewin, _(" (avail., section)"), xmax-x);
  188. break;
  189. case sso_state:
  190. waddnstr(titlewin, _(" (status, section)"), xmax-x);
  191. break;
  192. default:
  193. internerr("bad statsort %d on so_section", statsortorder);
  194. }
  195. break;
  196. case so_priority:
  197. switch (statsortorder) {
  198. case sso_unsorted:
  199. waddnstr(titlewin, _(" (by priority)"), xmax-x);
  200. break;
  201. case sso_avail:
  202. waddnstr(titlewin, _(" (avail., priority)"), xmax-x);
  203. break;
  204. case sso_state:
  205. waddnstr(titlewin, _(" (status, priority)"), xmax-x);
  206. break;
  207. default:
  208. internerr("bad statsort %d on so_priority", statsortorder);
  209. }
  210. break;
  211. case so_alpha:
  212. switch (statsortorder) {
  213. case sso_unsorted:
  214. waddnstr(titlewin, _(" (alphabetically)"), xmax-x);
  215. break;
  216. case sso_avail:
  217. waddnstr(titlewin, _(" (by availability)"), xmax-x);
  218. break;
  219. case sso_state:
  220. waddnstr(titlewin, _(" (by status)"), xmax-x);
  221. break;
  222. default:
  223. internerr("bad statsort %d on so_priority", statsortorder);
  224. }
  225. break;
  226. case so_unsorted:
  227. break;
  228. default:
  229. internerr("bad sort %d", sortorder);
  230. }
  231. }
  232. const char *helpstring;
  233. if (modstatdb_get_status() == msdbrw_write)
  234. helpstring = (verbose ? _(" mark:+/=/- terse:v help:?")
  235. : _(" mark:+/=/- verbose:v help:?"));
  236. else
  237. helpstring = (verbose ? _(" terse:v help:?")
  238. : _(" verbose:v help:?"));
  239. int l= strlen(helpstring);
  240. getyx(titlewin,y,x);
  241. if (xmax-l > 0) {
  242. mvwaddstr(titlewin,0,xmax-l, helpstring);
  243. }
  244. wnoutrefresh(titlewin);
  245. }
  246. }