pkgdisplay.cc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * dselect - Debian GNU/Linux package maintenance user interface
  3. * pkgdisplay.cc - package list display
  4. *
  5. * Copyright (C) 1994,1995 Ian Jackson <iwj10@cus.cam.ac.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
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  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.
  16. *
  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.
  20. */
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <ncurses.h>
  24. #include <assert.h>
  25. #include <signal.h>
  26. extern "C" {
  27. #include "config.h"
  28. #include "dpkg.h"
  29. #include "dpkg-db.h"
  30. }
  31. #include "dselect.h"
  32. #include "pkglist.h"
  33. /* These MUST be in the same order as the corresponding enums in dpkg-db.h */
  34. const char
  35. *const wantstrings[]= { "new package", "selected", "deselected", "purge", 0 },
  36. *const holdstrings[]= { "", "on hold", "REINSTALL",
  37. "hold,REINSTALL", 0 },
  38. *const statusstrings[]= { "not installed", "unpacked (not set up)",
  39. "failed config", "installed", "half installed",
  40. "removed (configs remain)", 0 },
  41. *const prioritystrings[]= { "Required", "Important", "Standard", "Recommended",
  42. "Optional", "Extra", "Contrib",
  43. "!Bug!", "Unclassified", 0 },
  44. *const relatestrings[]= { "suggests", "recommends", "depends on", "pre-depends on",
  45. "conflicts with", "provides", 0 },
  46. *const priorityabbrevs[]= { "Req", "Imp", "Std", "Rec",
  47. "Opt", "Xtr", "Ctb",
  48. "bUG", "?" };
  49. const char statuschars[]= " uF*H-";
  50. const char holdchars[]= " hRX";
  51. const char wantchars[]= "n*-_";
  52. static int maximumstring(const char *const *array) {
  53. int maxlen= 0;
  54. while (*array) {
  55. int l= strlen(*array);
  56. const char *p= strchr(*array, '(');
  57. if (p && p > *array && *--p == ' ') l= p - *array;
  58. if (l > maxlen) maxlen= l;
  59. array++;
  60. }
  61. return maxlen;
  62. }
  63. void packagelist::setwidths() {
  64. if (debug) fprintf(debug,"packagelist[%p]::setwidths()\n",this);
  65. if (verbose) {
  66. status_hold_width= 9;
  67. status_status_width= maximumstring(statusstrings);
  68. status_want_width= maximumstring(wantstrings);
  69. status_width= status_hold_width+status_status_width+status_want_width*2+3;
  70. priority_width= 8;
  71. package_width= 16;
  72. } else {
  73. status_width= 4;
  74. priority_width= 3;
  75. package_width= 12;
  76. }
  77. section_width= 8;
  78. gap_width= 1;
  79. if (sortorder == so_section) {
  80. section_column= status_width + gap_width;
  81. priority_column= section_column + section_width + gap_width;
  82. package_column= priority_column + priority_width + gap_width;
  83. } else {
  84. priority_column= status_width + gap_width;
  85. section_column= priority_column + priority_width + gap_width;
  86. package_column= section_column + section_width + gap_width;
  87. }
  88. description_column= package_column + package_width + gap_width;
  89. total_width= TOTAL_LIST_WIDTH;
  90. description_width= total_width - description_column;
  91. }
  92. void packagelist::redrawtitle() {
  93. int x,y;
  94. if (title_height) {
  95. mywerase(titlewin);
  96. mvwaddnstr(titlewin,0,0,
  97. recursive ? "dselect - recursive package listing" :
  98. !readwrite ? "dselect - inspection of package states" :
  99. "dselect - main package listing",
  100. xmax);
  101. getyx(titlewin,y,x);
  102. if (x < xmax) {
  103. switch (sortorder) {
  104. case so_section:
  105. waddnstr(titlewin, " (by section)", xmax-x);
  106. break;
  107. case so_priority:
  108. waddnstr(titlewin, " (by priority)", xmax-x);
  109. break;
  110. case so_alpha:
  111. waddnstr(titlewin, " (alphabetically)", xmax-x);
  112. break;
  113. case so_unsorted:
  114. break;
  115. default:
  116. internerr("bad sort in redrawtitle");
  117. }
  118. }
  119. const char *helpstring= readwrite ? (verbose ? " +/-=select v=terse ?=help"
  120. : " +/-=select v=verbose ?=help")
  121. : (verbose ? " v=terse ?=help"
  122. : " v=verbose ?=help");
  123. int l= strlen(helpstring);
  124. getyx(titlewin,y,x);
  125. if (xmax-l > 0) {
  126. mvwaddstr(titlewin,0,xmax-l, helpstring);
  127. }
  128. wnoutrefresh(titlewin);
  129. }
  130. }