pkgdisplay.cc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. *
  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.
  11. *
  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.
  16. *
  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/>.
  19. */
  20. #include <config.h>
  21. #include <compat.h>
  22. #include <string.h>
  23. #include <stdio.h>
  24. #include <dpkg/i18n.h>
  25. #include <dpkg/dpkg.h>
  26. #include <dpkg/dpkg-db.h>
  27. #include "dselect.h"
  28. #include "pkglist.h"
  29. /* These MUST be in the same order as the corresponding enums in dpkg-db.h */
  30. const char
  31. *const wantstrings[]= { N_("new package"),
  32. N_("install"),
  33. N_("hold"),
  34. N_("remove"),
  35. N_("purge"),
  36. nullptr },
  37. /* TRANSLATORS: The space is a trick to work around gettext which uses
  38. * the empty string to store information about the translation. DO NOT
  39. * CHANGE THAT IN A TRANSLATION! The code really relies on that being
  40. * a single space. */
  41. *const eflagstrings[]= { N_(" "),
  42. N_("REINSTALL"),
  43. nullptr },
  44. *const statusstrings[]= { N_("not installed"),
  45. N_("removed (configs remain)"),
  46. N_("half installed"),
  47. N_("unpacked (not set up)"),
  48. N_("half configured (config failed)"),
  49. N_("awaiting trigger processing"),
  50. N_("triggered"),
  51. N_("installed"),
  52. nullptr },
  53. *const prioritystrings[]= { N_("Required"),
  54. N_("Important"),
  55. N_("Standard"),
  56. N_("Optional"),
  57. N_("Extra"),
  58. N_("!Bug!"),
  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_("Updated"),
  86. N_("Obsolete/local"),
  87. N_("Up-to-date"),
  88. N_("Available"),
  89. N_("Removed") },
  90. *const ssastrings[]= { N_("Brokenly installed packages"),
  91. N_("Newly available packages"),
  92. N_("Updated packages (newer version is available)"),
  93. N_("Obsolete and local packages present on system"),
  94. N_("Up to date installed packages"),
  95. N_("Available packages (not currently installed)"),
  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. if (verbose) {
  120. status_hold_width= 9;
  121. status_status_width= maximumstring(statusstrings);
  122. status_want_width= maximumstring(wantstrings);
  123. status_width= status_hold_width+status_status_width+status_want_width*2+3;
  124. priority_width= 8;
  125. package_width= 16;
  126. } else {
  127. status_width= 4;
  128. priority_width= 3;
  129. package_width= 12;
  130. }
  131. section_width= 8;
  132. if (sortorder == so_section) {
  133. section_column= status_width + gap_width;
  134. priority_column= section_column + section_width + gap_width;
  135. package_column= priority_column + priority_width + gap_width;
  136. } else {
  137. priority_column= status_width + gap_width;
  138. section_column= priority_column + priority_width + gap_width;
  139. package_column= section_column + section_width + gap_width;
  140. }
  141. int versiondescriptioncolumn= package_column + package_width + gap_width;
  142. switch (versiondisplayopt) {
  143. case vdo_none:
  144. versioninstalled_column= versioninstalled_width= 0;
  145. versionavailable_column= versionavailable_width= 0;
  146. description_column= versiondescriptioncolumn;
  147. break;
  148. case vdo_available:
  149. versioninstalled_column= versioninstalled_width= 0;
  150. versionavailable_column= versiondescriptioncolumn;
  151. versionavailable_width= 11;
  152. description_column= versionavailable_column + versionavailable_width + gap_width;
  153. break;
  154. case vdo_both:
  155. versioninstalled_column= versiondescriptioncolumn;
  156. versioninstalled_width= 11;
  157. versionavailable_column= versioninstalled_column + versioninstalled_width +gap_width;
  158. versionavailable_width= versioninstalled_width;
  159. description_column= versionavailable_column + versionavailable_width + gap_width;
  160. break;
  161. default:
  162. internerr("unknown versiondisplayopt %d", versiondisplayopt);
  163. }
  164. description_width= total_width - description_column;
  165. }
  166. void packagelist::redrawtitle() {
  167. int x, y DPKG_ATTR_UNUSED;
  168. if (title_height) {
  169. mywerase(titlewin);
  170. mvwaddnstr(titlewin,0,0,
  171. recursive ? _("dselect - recursive package listing") :
  172. modstatdb_get_status() == msdbrw_readonly ?
  173. _("dselect - inspection of package states") :
  174. _("dselect - main package listing"),
  175. xmax);
  176. getyx(titlewin,y,x);
  177. if (x < xmax) {
  178. switch (sortorder) {
  179. case so_section:
  180. switch (statsortorder) {
  181. case sso_unsorted:
  182. waddnstr(titlewin, _(" (by section)"), xmax-x);
  183. break;
  184. case sso_avail:
  185. waddnstr(titlewin, _(" (avail., section)"), xmax-x);
  186. break;
  187. case sso_state:
  188. waddnstr(titlewin, _(" (status, section)"), xmax-x);
  189. break;
  190. default:
  191. internerr("bad statsort %d on so_section", statsortorder);
  192. }
  193. break;
  194. case so_priority:
  195. switch (statsortorder) {
  196. case sso_unsorted:
  197. waddnstr(titlewin, _(" (by priority)"), xmax-x);
  198. break;
  199. case sso_avail:
  200. waddnstr(titlewin, _(" (avail., priority)"), xmax-x);
  201. break;
  202. case sso_state:
  203. waddnstr(titlewin, _(" (status, priority)"), xmax-x);
  204. break;
  205. default:
  206. internerr("bad statsort %d on so_priority", statsortorder);
  207. }
  208. break;
  209. case so_alpha:
  210. switch (statsortorder) {
  211. case sso_unsorted:
  212. waddnstr(titlewin, _(" (alphabetically)"), xmax-x);
  213. break;
  214. case sso_avail:
  215. waddnstr(titlewin, _(" (by availability)"), xmax-x);
  216. break;
  217. case sso_state:
  218. waddnstr(titlewin, _(" (by status)"), xmax-x);
  219. break;
  220. default:
  221. internerr("bad statsort %d on so_priority", statsortorder);
  222. }
  223. break;
  224. case so_unsorted:
  225. break;
  226. default:
  227. internerr("bad sort %d", sortorder);
  228. }
  229. }
  230. const char *helpstring;
  231. if (modstatdb_get_status() == msdbrw_write)
  232. helpstring = (verbose ? _(" mark:+/=/- terse:v help:?")
  233. : _(" mark:+/=/- verbose:v help:?"));
  234. else
  235. helpstring = (verbose ? _(" terse:v help:?")
  236. : _(" verbose:v help:?"));
  237. int l= strlen(helpstring);
  238. getyx(titlewin,y,x);
  239. if (xmax-l > 0) {
  240. mvwaddstr(titlewin,0,xmax-l, helpstring);
  241. }
  242. wnoutrefresh(titlewin);
  243. }
  244. }